Right margin in Vim
Is there any way to make Vim/gVim highlight the right-margin at the current document? I have just begun to work with Vim for a while and I found it annoyed without the right-margin at column 80.
Vim 7.3 introduced colorcolumn.
:set colorcolumn=80
It may be easier for you to remember the short form.
:set cc=80
There is no simple way to visualize vertical edge of the textwidth
-margin (in Vim 7.2 and earlier). However, one can highlight all characters beyond the 80 columns limit using the :match
command.
:match ErrorMsg /%>80v.+/
So, the general solution is to use the following auto-command.
:autocmd BufWinEnter * call matchadd('ErrorMsg', '%>'.&l:textwidth.'v.+', -1)
我在.vimrc中编写了一个vimscript函数,当按下按钮时,切换颜色列,8(逗号后跟8,其中逗号是用户定义命令的定义领导者,而8是我的助记键,第80列):
" toggle colored right border after 80 chars
set colorcolumn=81
let s:color_column_old = 0
function! s:ToggleColorColumn()
if s:color_column_old == 0
let s:color_column_old = &colorcolumn
windo let &colorcolumn = 0
else
windo let &colorcolumn=s:color_column_old
let s:color_column_old = 0
endif
endfunction
nnoremap <Leader>8 :call <SID>ToggleColorColumn()<cr>
链接地址: http://www.djcxy.com/p/49480.html
上一篇: 重新映射Vim键以避免左手的RSI
下一篇: Vim中的右边距