5

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
13

You can use:

vi +"set number" your_file
| improve this answer | |
3

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"
| improve this answer | |
2

You can use:

vi +set\ number <filename>

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

| improve this answer | |
2

If wrongly answered your question first. My answer was:

The exact syntax, to jump to a line is :

vi +linenumber filename 

or

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.

| improve this answer | |
1

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

vi +LINENUMBER nameoffile

| improve this answer | |
  • 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
0

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

| improve this answer | |

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.