how to edit text in multiple columns in vim

家住魔仙堡 提交于 2021-02-05 12:52:41

问题


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).


回答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.




回答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 + =




回答3:


This is what I use: http://vim.wikia.com/wiki/View_text_file_in_two_columns.

It's a little clunky... Sometimes the scroll synchronization gets offset or disconnected, forcing you to re-columnate the view (in cmd mode, CTRL+W,q to close a a col. window, & \vs to add one.).

But it works great 90% of the time. I use it a lot.



来源:https://stackoverflow.com/questions/5131205/how-to-edit-text-in-multiple-columns-in-vim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!