DISQUS

Tech-Recipes: Show line numbers in vi or vim | UNIX | Tech-Recipes

  • penno · 5 years ago
    Does anyone know how to make line numbers the default?? :?
  • qmchenry · 5 years ago
    If you are in a UNIX operating system, you can create a file in your home directory called .exrc that vi will read when it starts. Just put set number on its own line as well as any other set. To see what other options are available and their current values, use :set all from within vi.
  • penno · 5 years ago
    That works wonderfully! Thank you very much!! :D
  • Anonymous · 4 years ago
    Alternativley you can see the current cursor postiton with :set ruler
  • trilobites · 1 year ago
    wow, thanks. very helpful!
  • thanks · 1 year ago
    thanks
  • pandiano · 1 year ago
    MANY THX!!!!!!!!!!!!!
  • robertmarkbram · 1 year ago
    Helped me!
  • tom · 11 months ago
    helped me too!
  • Rob · 10 months ago
    Is it possible to get vim to show line numbers by default? I need them more often than not.
  • Quinn McHenry · 10 months ago
    Sure thing -- just add

    :set number

    to the file .vimrc in your home directory.

    Sometime when you get bored, type :set all while in vim.. it'll show you all the available options. Chances are if there's some behavior you don't like in vim, you can tweak it.
  • Sandy · 10 months ago
    Thanks. It was helpful for me
  • Joe · 10 months ago
    Nice... had forgotten my vi
  • Vasanth · 9 months ago
    thanks it helped!
  • Dave · 9 months ago
    too easy.. :-)
  • James · 7 months ago
    Good tip. I get horizontal lines underneath the numbers, is that supposed to happen?
  • Nick · 6 months ago
    You can also add:
    set number
    ~/.vimrc
  • Dushi · 4 months ago
    that was so helpful. thanx...
  • Tim Broder · 3 months ago
    sweet, thanks
  • Rick Graham · 3 months ago
    This is what I was looking for.

    Here's what I did:

    Edit ~/.vimrc

    add these lines:

    nnoremap <silent> <F6> :set number<CR>
    nnoremap <silent> <S-F6> :set nonumber<CR>

    Now, F6 turns line numbers on, Shift F6 turns them off.
  • Cédric Bosdonnat · 3 months ago
    @Rick: you can use only one shortcut to toggle the line numbers also with the following line (note the ! after the number which mean "toggle" for vi):

    nnoremap <silent> <F6> :set number!<CR>
  • sud · 1 week ago
    first time - comments are important more then the post