I added:
set number
nnoremap <F2> :set nonumber!
to my vimrc file. Basically what it's supposed to do is let me press F2 to toggle line numbering but it's not working. What have I done wrong?
I added:
set number
nnoremap <F2> :set nonumber!
to my vimrc file. Basically what it's supposed to do is let me press F2 to toggle line numbering but it's not working. What have I done wrong?
In your .vimrc
, add this:
set number
nnoremap <F2> :set nonumber!<CR>
Then pressing F2 will toggle line numbering.
:set nonumber! norelativenumber!
if you use both number and relative number. –
Terni This is what I use (with a different key binding):
nmap <f2> :set number! number?<cr>
The "number!" toggles the setting and "number?" reports the state.
lua
version for Neovim vim.api.nvim_set_keymap("n", "<C-s>", ":set scrollbind! scrollbind?<CR>", { noremap = true, silent = true })
–
Notification nmap <silent> <F11> :exec &nu==&rnu? "se nu!" : "se rnu!"<CR>
In new vim you can set both relative number and number at once, this way:
set nu rnu
nmap <silent> <F11> :exec &nu==&rnu? "se nu!" : "se rnu!"<CR>
–
Percolator This is one method:
map <silent> <F2> :if &number <Bar>
\set nonumber <Bar>
\else <Bar>
\set number <Bar>
\endif<cr>
(this one is nice 'cause I usually put foldcolumn in there as well)
This is another:
map <silent> <F2> :set invnumber<cr>
(direct method)
I use this to toggle between relativenumber ( with current absolute line number) and no line numbering
nnoremap <silent> <leader>l :set relativenumber! <bar> set nu!<CR>
© 2022 - 2025 — McMap. All rights reserved.
nonumber!
implement the toggle function? – Rode