开发者

Vim, how to map two tasks under one shortcut key?

i like to have line numbers ON in Vim but sometimes line numbers are annoying. I have shortcuts set in .vimrc:

map <c-F12> :set nonumber<ENTER>
map <c-F11> :set number<ENTER>

for turning them off/on.

Is it possible to connect both tasks (turning off/on) under 开发者_如何学编程one key? I mean, when line numbers are ON shortcut should turn OFF them and turn ON when line numbers are OFF.


From Vim help, you can use the following syntax :

:se[t] {option}! or
:se[t] inv{option} Toggle option: Invert value. {not in Vi}

See :help set-option

In your case, you could use: map <c-F11> :set number!<ENTER>


In case you want also change between the relative line number, the line number, and no number you can use something like the following:

let g:relativenumber = 0
function! ToogleRelativeNumber()
  if g:relativenumber == 0
    let g:relativenumber = 1
    set norelativenumber
    set number
  elseif g:relativenumber == 1
    let g:relativenumber = 2
    set nonumber
    set relativenumber
  else
    let g:relativenumber = 0
    set nonumber
    set norelativenumber
  endif
endfunction

map <c-f11> :call ToogleRelativeNumber()<cr>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜