2011-08-20 80 views
3

當我從瀏覽器複製文本並將其粘貼到在終端中使用vi打開的文件中時,我得到以下未格式化的文本。爲什麼vi或終端忽略換行符?使用Mac OS X複製和粘貼問題

非但沒有如下:

" 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 

我得到這個:

" 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)) | 
+2

@Matt:No. http://meta.stackexchange.com/q/25925/160504 – sidyll

+1

@sidyll我糾正了。謝謝':)' –

回答

4

這是六,而不是Mac OS X或終端的故障。 Vi不會忽視新行;它只是積累縮進。您可以在粘貼之前關閉自動跳線(:set noai)並在之後將其重新打開,或者如果您使用Vim(我相信vi僅僅是Mac OS X中的符號鏈接),您可以暫時關閉paste選項on,它會禁用autoindent以及粘貼文本時可能導致問題的其他幾個功能。

+1

使用'paste'選項的espouse。另見'pastetoggle'。 –

4

甚至比:set paste更好的是我們的mac剪貼板。

如果你使用vim 7.3,你可以添加到您的~/.vimrc文件,以獲得抽出(y)並粘貼(p)使用Mac`s剪切和粘貼緩衝區:

if has("macunix") 
    if v:version >= 703 
    " Default yank and paste go to Mac's clipboard 
    set clipboard=unnamed 
    endif 
endif 

你即使您沒有Vim 7.3,也可以安全地將它放入您的.vimrc - 這不會起作用。

您可以使用homebrewhomebrew-alt存儲庫獲取最新的vim。我推薦它!

+0

我認爲這樣比較好,雖然我更喜歡使用系統鍵盤('「* p')而不是覆蓋默認的鍵盤。如果你不想安裝更新版本的vim,[fakeclip插件](http: //www.vim.org/scripts/script.php?script_id=2098)也將起作用。 – kejadlen