jeffkreeftmeijer / vim-numbertoggle

Toggles between hybrid and absolute line numbers automatically
https://jeffkreeftmeijer.com/vim-number/#automatic-toggling-between-line-number-modes
MIT License
682 stars 49 forks source link

Option to toggle to absolute numbers in command mode #48

Closed tversteeg closed 3 years ago

tversteeg commented 4 years ago

I would like to be able to set the numbers to absolute when I press :. Is this something that could be added to this plugin? I can understand it if other people don't want this option, so maybe it should be configurable?

seymar commented 4 years ago

There is no autocmd event for that:

http://vimdoc.sourceforge.net/htmldoc/autocmd.html#autocmd-events

jeffkreeftmeijer commented 3 years ago

Since number toggle only toggles relative numbers, you could toggle using the F2 key by remapping it:

:nnoremap <F2> :set nornur!<CR>
mmirus commented 2 years ago

FYI, I think the CmdlineEnter and CmdlineLeave events can be used for this now.

simonmandlik commented 2 years ago

I achieved this with the following:

augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave,CmdlineLeave,WinEnter * if &number && mode() != "i" | set relativenumber | redraw | endif
autocmd BufLeave,FocusLost,InsertEnter,CmdlineEnter,WinLeave   * if &number | set norelativenumber | redraw | endif
augroup END