7

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.

jberryman
  • 904
  • 2
  • 10
  • 25
Gnanam
  • 1,439
  • 13
  • 26
  • 32

7 Answers7

16

You can use:

vi +"set number" your_file
Khaled
  • 35,688
  • 8
  • 69
  • 98
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"
Janne Pikkarainen
  • 31,454
  • 4
  • 56
  • 78
2

You can use:

vi +set\ number <filename>

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

mulaz
  • 10,472
  • 1
  • 30
  • 37
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.

CloudWeavers
  • 2,511
  • 1
  • 14
  • 17
1

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

vi +LINENUMBER nameoffile

RomeNYRR
  • 1,439
  • 9
  • 16
  • 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 02 '12 at 05:39
0

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

kajibu
  • 1
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

Sosin
  • 1