Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show line numbers only on command mode

Tags:

vim

I only ever use the line numbers when I want to switch to a line on the screen, which I use the command mode for (e.g. :82)

Is there a way to show the line numbers when I switch to command mode?

like image 919
pyceanx Avatar asked Sep 05 '25 19:09

pyceanx


1 Answers

Yes. You can use map for that.

: nnoremap : :set nu<CR>:

This will set line numbers when you enter command line mode.

The following command will not show line numbers when you leave command-line mode.

  :nnoremap <CR> :set nonu<CR>

But this needs two enters to be pressed.

** As Andrew suggests, the following command des the same and avoids typing enter twice.**

:cnoremap <silent> <CR> <CR>:set nonu<CR> 

Put these two lines in your ~/.vimrc file.

like image 175
SibiCoder Avatar answered Sep 09 '25 01:09

SibiCoder