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.

1
  • :h CTRL-W_F could be also of use.
    – Matt
    Jan 3, 2020 at 6:54

3 Answers 3

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
1
  • perfect! I figured there was something, and I was just missing it. Jan 3, 2020 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.

0
0

vim [file] +50 +split to split horizontally

vim [file] +50 +vsto split vertically

2
  • 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, 2020 at 17:11
  • The question only specified one filename so I thought it wasn't about multiple files. Jan 7, 2020 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.