Mac OS X 的复制粘贴问题

3
当我从浏览器中复制文本并将其粘贴到终端中使用vi打开的文件中时,我得到以下未经格式化的文本。为什么vi或终端会忽略换行符? 而不是得到以下内容:
" 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:不行。http://meta.stackexchange.com/q/25925/160504 - sidyll
1
@sidyll,我错了。谢谢:) - Matt Ball
2个回答

4
比:set paste更好的方法是使用Mac剪贴板。如果您正在使用vim 7.3,则可以将以下内容添加到您的~/.vimrc文件中,以使yank(y)和paste(p)使用Mac的剪贴板。
if has("macunix")
  if v:version >= 703
    " Default yank and paste go to Mac's clipboard
    set clipboard=unnamed
  endif
endif

你可以安全地将其放入你的.vimrc中,即使你没有Vim 7.3 -- 它只是不起作用而已。
你可以使用homebrewhomebrew-alt存储库获取最新的vim。我推荐这样做!

我认为这样做更好,尽管我更喜欢使用系统键盘("*p)而不是覆盖默认键盘。如果您不想安装更新版本的vim,则fakeclip插件也可以使用。 - kejadlen

4
这是 vi 的问题,而不是 Mac OS X 或终端的问题。Vi 并没有忽略换行符,只是积累了缩进。在粘贴之前关闭自动缩进 (:set noai),然后在粘贴后再打开它,就可以解决这个问题。或者,如果您正在使用 Vim(我认为 vi 在 Mac OS X 中只是一个符号链接),您可以临时打开 paste 选项,这将禁用自动缩进以及其他几个可能导致粘贴文本时出现问题的功能。

1
请使用“paste”选项。另请参见“pastetoggle”。 - ib.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接