Split to a Line

4.4
(145)

You may know that Vim has two kinds of splits: horizontal and vertical. You can split your current file by simply calling either :split or :vsplit. Now you have the same file open twice and you can more easily access or compare different parts of that file.

But you may find yourself wanting to see a specific line in the file. Perhaps you’re doing some code reviews on GitHub and need to take a closer look at a specific portion of the file. Or you just want to compare sections within a file. There’s a few ways you can open that split to a specific portion:

  • :vsplit +10 – Open vertical split of the current file to line 10
  • :split +319 – Open horizontal split of the current file to line 319
  • :split + – Open horizontal split to the last line of the file
  • :vsplit +/pattern – Open a vertical split to a specific pattern

Check out the gif below. Here I have a large JSON file open. Let’s say I want to compare this section at the top to the bottom. First I do a horizontal split with :split + and it opens to the bottom of the file. I close that buffer with :q.

Next, I wanted to compare the section I was viewing with another section of this JSON about DigitalOcean. So I split it vertically with :vsplit +/digital and I was jumped directly to the first reference to digital in the file.

Try this trick to speed up your navigation through files and Tweet at us if you find it useful! Here are some other tips related to splits:

How useful was this tip?

Average rating 4.4 / 5. Vote count: 145

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

81 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts

Leave a reply

Your email address will not be published. Required fields are marked *