how to edit text in multiple columns in vim

13,275

Solution 1

Just press CTRL-W v and the file you are working on will be split into two separate independent columns. Repeat CTRL-W v as many times as you want.

Set scrollbind: set scrollbind to columns that you want to scroll in sync.

For example:

vim afile         # Open a file
^w v              # split it
gg                # go to top
:set scrollbind   # bind this one
^w l              # go to the new split
L                 # go to bottom of this split
zt                # make it the top line
:set scrollbind   # bind with this one

Now, while you move on one column, the other one scrolls so as if the first column overflows the text to the second column.

Solution 2

I think what you want to do is split windows...

Type :Vexplore to split a window vertically.

Then use Ctrl + W + arrowkey to navigate to another window. :Sexplore will enable you to split the window horizontally.

To evenly space after resizing, you can type Ctrl + W + =

Share:
13,275

Related videos on Youtube

Scott Cumming
Author by

Scott Cumming

Updated on May 06, 2020

Comments

  • Scott Cumming
    Scott Cumming almost 4 years

    How can I edit my code in Vim by displaying it in any number of columns?

    My laptop and desktop monitors are widescreen (I suspect that is true of most monitors made in the last 5 or 10 years!). When I open any editor in full screen, more than half the screen is completely empty. I'd like to be able to effectively use the rest of the screen by splitting it into two or three columns so I can see all much more of my code in a single screen.

    Frankly, I'm surprised that other than Microsoft Word, I have never seen this functionality in any editor.

    I found the following page (http://vim.wikia.com/wiki/View_text_file_in_two_columns) which seems to do what I want, but I don't really understand what they are suggesting. I did set columns and scroll bind, but that didn't seem to do anything.

    I don't normally use Vim, but if I can get access to this functionality, I'll switch happily. I am currently on Ubuntu 10.10 (gnome). The default version of Vim seems to be 7.2 (/usr/bin/vim.gnome).

    • jamesmortensen
      jamesmortensen about 13 years
      Does this belong on Superuser?
    • Karl Bielefeldt
      Karl Bielefeldt about 13 years
      Clearly falls under "software tools commonly used by programmers."
    • Kent
      Kent almost 4 years
      @brillout what do you mean by "looking for an up-to-date" answer? Do you have a particular question/problem? It is probably better to open a new one if the answers below don't help you.
    • brillout
      brillout almost 4 years
      The solution of the accepted answer is not reliable and the scrolling of the two panes get out of sync all the time. I'm surprised there isn't a better solution to this. Would love something reliable! It would effectively double my read estate...
    • Kent
      Kent almost 4 years
      @brillout IMO, perhaps it is better to open a new question, there you can reference this one, and describe why the answer here doesn't help you and make an example to show the problem. This question has already an accepted answer, perhaps it was not working for you, but the OP has accepted it, that means, it is done.
    • brillout
      brillout almost 4 years
      You're right, thank you.
  • Scott Cumming
    Scott Cumming about 13 years
    :*explore and :split seems to allow me to open two different files at the same time. I actually want to split the same file across multiple columns. Just like long lines automatically flow to the next lines, I expect long text to overflow over to the next column.
  • Scott Cumming
    Scott Cumming about 13 years
    wow, this is tantalizingly close! I can see the same file in two columns and they scroll together. However, I don't want mirror images in the two columns, I want text from the first column flow into the next columns. Say my file just has numbers from 1 to 10k. I expect to see, say, 1-60 in the first column, 61-120 in the second columns, etc.
  • Eelvex
    Eelvex about 13 years
    @Shahbaz: I had a typo. It does what you want. I think I'll update with a more complete function later.
  • pyramation
    pyramation about 13 years
    @Shahbaz: Yes, it will open a browser so to speak. But you can open the same file twice or as many times as you like.
  • David
    David almost 10 years
    This seems to do what you describe: vim.wikia.com/wiki/View_text_file_in_two_columns
  • brillout
    brillout almost 4 years
    This solution is not reliable and the scrolling of the two panes get out of sync all the time. I'm surprised there isn't a better solution to this. Would love something reliable! It would effectively double my read estate..
  • Eelvex
    Eelvex almost 4 years
    You can make a more sophisticated function to handle your edge cases but the main point will still be using scrollbind.
  • Sridhar Sarnobat
    Sridhar Sarnobat almost 3 years
    Note: set scrollbind only works when you are in the new pane. I’m guessing there's a reason for that but I don't see what exactly.