How do I enable line numbers to be displayed in Vim?

  • Work on your search skills. This functionality exists since the early versions of vi, i.e. for decades. There surely is some mentioning on teh Internets. – Ingo Karkat Oct 8 '13 at 8:20

To enable line numbering:

:set number

To disable it:

:set nonumber
  • 4
    short form for the same: :set nu and :set nonu – Hemant Sep 17 '10 at 18:20
  • 7
    Heck, :se nu and :se nonu if you really want to shave characters. But :set number and :set nonumber are pretty clear, aren't they? – ephemient Sep 17 '10 at 18:29

And if you want it to apply to every instance of Vim you open... put set number in your .vimrc file!

  • Or even your .exrc file, which will work for vim, nvi, vi, etc. – kurtm Oct 7 '13 at 21:30

I find it extremely useful to have a binding to toggle line numbering (among other things). It can be configured as follows

nnoremap <Leader>gn :setl number!<CR>:setl number?<CR>

The first command will toggle the line numbering for the current buffer (local) and the second one will display the current value of the option on the status line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.