I've seen so many examples/usages about how to display/hide line numbers in vi edit mode.

To turn on line numbers: Type :set number in edit mode

To turn off line numbers: Type :set nonumber in edit mode

I wonder whether there is any convenient way/option available (that I may not be knowing) to specify/mention this option at the time of opening the file from the command line?

NOTE: For example, to go to a specific line inside a file after opening it, we can conveniently say vi +/<linenumber> <filename> from the command line.

  • 1
    Didn't you answer your own question? – HTTP500 Apr 30 '12 at 12:50
  • @HTTP500: Hope, by now you might have understood (after reading the answers below) that my question is subtle different. – Gnanam May 2 '12 at 4:59

You can use:

vi +"set number" your_file

How about if you create a separate vim settings file for both cases? For example, ~/.vimrc-number and ~/.vimrc-nonumber. Then you can launch those like this:

vim -u ~/.vimrc-number /some/text/file
vim -u ~/.vimrc-nonumber /some/text/file

Or create aliases to your .bashrc:

alias vimnumbers="vim -u ~/.vimrc-number"
alias vimnonumbers="vim -u ~/.vimrc-nonumber"

You can use:

vi +set\ number <filename>

or put "set number" to your ~/.vimrc


If wrongly answered your question first. My answer was:

The exact syntax, to jump to a line is :

vi +linenumber filename 


vi filename +linenumber

Where linenumber is a number.

And the correct answer to your question is:

vi +set\ number <filename>

Which will provides lines number while editing filename.


Looks to me like you answered your own question; Maybe you need to rephrase the question?? :D

vi +LINENUMBER nameoffile

  • No, the question is little different. Your command jumps to the specified line number after opening the file. But my question was, how do I specify that option at the time of opening file itself. Hope you might be clear by now. – Gnanam Apr 30 '12 at 13:34
  • If you mean once you open the file, you want to go to the line then you just type in :linenumber – RomeNYRR Apr 30 '12 at 14:55
  • Actually, my question was how to specify the option "at the time" of opening file from command-line (but not "after" opening the file). Hope I made it clear. – Gnanam May 2 '12 at 5:39

If you want to have the line numbers and to jump to the line number you can use the +"set number" and +linenumber :

vi +set\ number your_file +171


One can use alias, add alias vim='vim +"set number"' to ~/.bashrc,then source ~/.bashrc done.

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.