4

I can open a file with vim on the command line like so:

vim fnord.txt +50

And it will take me to the 50th line

Is it possible to do the same thing with :split? So far I haven't been able to figure out how to do it.

  • :split fnord.txt +50
  • :split fnord.txt ++50
  • :split fnord.txt:50

None of these work, and I didn't see anything searching for line within :help split.

Wayne Werner
  • 425
  • 2
  • 7

3 Answers3

8

You are so close:

:split +50 fnord.txt

All commands in vim that create new buffer has prototype:

cmd [++opt] [+cmd] [file]

All commands in vim that write buffer to your disk has prototype:

cmd [++opt] [file]

:h ++opt is only used for special options that should be set before read or write a buffer.

:e ++fileformat=dos file
:e ++encoding=latin1 file
:e ++binary file
:e ++nobinary file
:e ++bad=?
:w ++enc=latin1 newfile
read ++edit file

Note the last read ++edit file change 'fileformat' and 'fileencoding' to values the same as :e file.

:h +cmd can be used to do any ex command:

:e +50 file
:e +/main file
:e +echo\ "blah\ blah" file
:e +setlocal\ textwidth=120 file
dedowsdi
  • 6,248
  • 1
  • 18
  • 31
1

:split file | :50 should work, from command line. The separator separate commands. A number typed as command jumps to that line number.

Rich
  • 31,891
  • 3
  • 72
  • 139
eyal karni
  • 1,106
  • 9
  • 33
0

vim [file] +50 +split to split horizontally

vim [file] +50 +vsto split vertically

Gustav Blomqvist
  • 791
  • 1
  • 6
  • 18
  • This doesn't really answer the question; it creates the appropriate split, but not the way the OP wants. I imagined OP started on file a, and then wanted to :split b, but have b be on the 50th line. – D. Ben Knoble Jan 04 '20 at 17:11
  • The question only specified one filename so I thought it wasn't about multiple files. – Gustav Blomqvist Jan 07 '20 at 07:14