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.

  • :h CTRL-W_F could be also of use. – Matt Jan 3 at 6:54
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
|improve this answer|||||
  • perfect! I figured there was something, and I was just missing it. – Wayne Werner Jan 3 at 16:54
1

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

|improve this answer|||||
0

vim [file] +50 +split to split horizontally

vim [file] +50 +vsto split vertically

|improve this answer|||||
  • 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 4 at 17:11
  • The question only specified one filename so I thought it wasn't about multiple files. – Gustav Blomqvist Jan 7 at 7:14

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.