Answers:
对于(g)vim,请使用以下命令:
set colorcolumn=80
或您想要的任何宽度。适用于vim和gvim。我在IF中有我的文件,所以这取决于我编辑的文件类型。
您也可以使用+ x / -x来设置&textwidth中+/-列的基本位置。
set textwidth=80
set colorcolumn=-2
将有效地在char位置78绘制彩色条。当然,您可以自行设置文本宽度,也可以不设置,因此它可以为0(默认值)。我使用绝对头寸表格。
您还可以根据需要更改使用的颜色:
highlight ColorColumn ctermbg=green guibg=orange
(尽管我不推荐这些颜色)
在(g)vim 7.3中添加了此选项。
Google代码中有一个代码段,您可以尝试:
augroup vimrc_autocmds
au!
autocmd BufRead * highlight OverLength ctermbg=red ctermfg=white guibg=#592929
autocmd BufRead * match OverLength /\%81v.*/
augroup END
我喜欢lornix”回答了很多,但我并不想突出列所有的时间,只有当至少一个行超过长度限制:
这是我为Haskell文件执行的操作:
augroup HaskellCommands
autocmd!
" When a Haskell file is read or the text changes in normal or insert mode,
" draw a column marking the maximum line length if a line exceeds this length
autocmd BufRead,TextChanged,TextChangedI *.hs call ShowColumnIfLineTooLong(80)
augroup END
" Color the column marking the lengthLimit when the longest line in the file
" exceeds the lengthLimit
function! ShowColumnIfLineTooLong(lengthLimit)
" See /programming/2075276/longest-line-in-vim#2982789
let maxLineLength = max(map(getline(1,'$'), 'len(v:val)'))
if maxLineLength > a:lengthLimit
highlight ColorColumn ctermbg=red guibg=red
" Draw the vertical line at the first letter that exceeds the limit
execute "set colorcolumn=" . (a:lengthLimit + 1)
else
set colorcolumn=""
endif
endfunction