【问题标题】:Copy and paste issue with Mac OS XMac OS X 的复制和粘贴问题
【发布时间】:2011-10-31 10:01:35
【问题描述】:

当我从浏览器复制文本并将其粘贴到我在终端中使用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)) |

【问题讨论】:

标签: macos vim vi


【解决方案1】:

:set paste 更好的是只有我们的mac剪贴板。

如果您使用的是 vim 7.3,您可以将其添加到您的 ~/.vimrc 文件中以获取 yank (y) 和粘贴 (p) 以使用 Mac 的剪切和粘贴缓冲区:

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。我推荐它!

【讨论】:

  • 我认为这样更好,虽然我更喜欢使用系统键盘 ("*p) 而不是覆盖默认键盘。如果你不想安装更新版本的 vim,fakeclip plugin 也可以。
【解决方案2】:

这是 vi 的错,而不是 Mac OS X 或终端。 Vi 并没有忽略换行符;它只是在累积缩进。您可以通过在粘贴之前关闭自动缩进 (:set noai) 来解决此问题,然后再将其重新打开,或者,如果您使用的是 Vim(我相信 vi 只是 Mac OS X 中的符号链接),您可以暂时关闭paste 选项打开,它会禁用自动缩进以及其他几个在粘贴文本时可能导致问题的功能。

【讨论】:

  • 支持使用paste 选项。另见pastetoggle
猜你喜欢
  • 2011-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-26
  • 1970-01-01
相关资源
最近更新 更多