Skip to content

Instantly share code, notes, and snippets.

@joequery
Created August 21, 2012 19:54
Show Gist options
  • Select an option

  • Save joequery/3418841 to your computer and use it in GitHub Desktop.

Select an option

Save joequery/3418841 to your computer and use it in GitHub Desktop.
Vim Toggle Relative Line Numbers
" use Ctrl+L to toggle the line number counting method
function! g:ToggleNuMode()
if &nu == 1
set rnu
else
set nu
endif
endfunction
nnoremap <silent><C-L> :call g:ToggleNuMode()<cr>
@choppy812

choppy812 commented Aug 26, 2019

Copy link
Copy Markdown

This wouldn't work for me--it would only toggle once, then C-L wouldn't work again. Here's how I made it work for me:

" use Ctrl+L to toggle the line number counting method
function! g:ToggleNuMode()
  if &nu == 1
     set nonu   " turn off nu
     set rnu
  else
     set nornu   " turn off rnu
     set nu
  endif
endfunction
nnoremap <silent><C-L> :call g:ToggleNuMode()<cr>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment