Reputation: 2837
When I copy a text from a browser and paste it into a file I opened using vi
in Terminal, I get the following unformatted text. Why does vi or the Terminal ignoring the newlines?
Instead of getting the following:
" Restore cursor position to where it was before
augroup JumpCursorOnEdit
au!
autocmd BufReadPost *
\ if expand("<afile>:p:h") !=? $TEMP |
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ let JumpCursorOnEdit_foo = line("'\"") |
\ let b:doopenfold = 1 |
\ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
\ let JumpCursorOnEdit_foo = JumpCursorO
I get this:
" Restore cursor position to where it was before
augroup JumpCursorOnEdit
au!
autocmd BufReadPost *
\ if expand("<afile>:p:h") !=? $TEMP |
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ let JumpCursorOnEdit_foo = line("'\"") |
\ let b:doopenfold = 1 |
\ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
Upvotes: 3
Views: 1260
Reputation: 11694
Even better than :set paste
is to just us the mac clipboard.
If you're using vim 7.3, you can add this to your ~/.vimrc
file to get yank (y
) and paste (p
) to use the Mac`s cut and paste buffer:
if has("macunix")
if v:version >= 703
" Default yank and paste go to Mac's clipboard
set clipboard=unnamed
endif
endif
You can safely put it in your .vimrc
even if you don't have Vim 7.3 -- it just won't work.
You can get the latest vim using homebrew and the homebrew-alt repositories. I recommend it!
Upvotes: 4
Reputation: 57460
This is the fault of vi, not Mac OS X or Terminal. Vi isn't ignoring the newlines; it's just accumulating indentation. You can fix this by turning autoindent off (:set noai
) before pasting and turning it back on afterwards, or, if you're using Vim (which I believe vi is just a symlink to in Mac OS X) you can temporarily turn the paste
option on, which disables autoindent along with several other features that can cause problems when pasting text.
Upvotes: 4