【问题标题】:How to show vertical line to wrap the line in Vim?如何显示垂直线以在 Vim 中换行?
【发布时间】:2009-12-17 01:57:35
【问题描述】:

我有兴趣找到一种在 Vim(不是 GVim)中在第 80 列显示垂直线的方法。

我用过set wrap,但我只想显示一条垂直线,以便我自己将长线包裹起来。

【问题讨论】:

标签: vim word-wrap


【解决方案1】:

Vim 7.3 中的新功能:

'colorcolumn' 是一个逗号分隔的屏幕列列表,它们是 用 ColorColumn 突出显示。用于对齐文本。将要 使屏幕重绘变慢。屏幕列可以是绝对数,或者 一个以 '+' 或 '-' 开头的数字,添加或减去 '文本宽度'。

文档中的示例:

:set colorcolumn=+1        " highlight column after 'textwidth'
:set colorcolumn=+1,+2,+3  " highlight three columns after 'textwidth'
:highlight ColorColumn ctermbg=lightgrey guibg=lightgrey

你也可以使用绝对数:

:set colorcolumn=80

【讨论】:

  • 我认为这里最好注意颜色是由您的突出显示颜色自动确定的,除非您像示例中那样手动设置它。
  • 请注意,highlight 设置必须在任何colorscheme 命令之后设置,因为这会覆盖您的突出显示颜色。
  • 我选择了明亮的、燃烧你的大脑的红色......因为你知道......行长
  • 提一下textwidth 也会在你打字时导致vim换行。
  • @chutsu Vim 颜色图表位于:codeyarns.com/2011/07/29/vim-chart-of-color-names
【解决方案2】:

编辑:对于 Vim >=7.3,请参阅答案 below

不幸的是,vim 没有在你想要的列之后显示垂直线的机制(不像 TextMate)。但是,您可以使用其他视觉指示器来显示行太长。

这是我使用的(你可以把它放在你的.vimrc):

nnoremap <Leader>H :call<SID>LongLineHLToggle()<cr>
hi OverLength ctermbg=none cterm=none
match OverLength /\%>80v/
fun! s:LongLineHLToggle()
 if !exists('w:longlinehl')
  let w:longlinehl = matchadd('ErrorMsg', '.\%>80v', 0)
  echo "Long lines highlighted"
 else
  call matchdelete(w:longlinehl)
  unl w:longlinehl
  echo "Long lines unhighlighted"
 endif
endfunction

因此,您可以使用&lt;Leader&gt;H 切换超过 80 列被突出显示。

【讨论】:

【解决方案3】:

还有另一种方法可以通知长线。

highlight OverLength ctermbg=red ctermfg=white guibg=#592929 <br>
match OverLength /\%81v.*/

Vim 80 column layout concerns

【讨论】:

    【解决方案4】:

    我使用match ErrorMsg '\%&gt;80v.\+',它将用红色突出显示超过 80 个字符。

    我把那个命令放在我的 python.vim 和 ruby​​.vim 下 ~/.vim/after/ftplugin/.

    【讨论】:

      【解决方案5】:

      这里有几个答案http://vim.wikia.com/wiki/Highlight_long_lines简单的自动命令

      :au BufWinEnter * let w:m1=matchadd('Search', '\%<81v.\%>77v', -1)
      :au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
      

      【讨论】:

        猜你喜欢
        • 2020-07-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-19
        • 2011-11-20
        • 1970-01-01
        • 1970-01-01
        • 2013-04-13
        相关资源
        最近更新 更多