Last Updated: February 25, 2016
·
1.007K
· weslleyaraujo

Dealing with multiple windows and files on VIM

As we know, vim is such a powerful text-editor available in most of all UNIX systems.

And one thing that is kind of hard to deal is the windows manipulation (resizing, opening file, go to file, etc)

Today Im gonna show you one of the commands that really made me more productive solving that problems.

NOTE: THE COMMANDS ABOVE MUST BE EXECUTED IN THE NORMAL MODE WHICH YOU CAN SIMPLE ENTER PRESSING ESC

Opening files from anywhere

One of the most useful command in vim is the :edit

you can simple use it like :edit <path-to-my-file>

or to make it more easier you can use it shortcut :e <path-to-my-file>

Splitting screen

Another useful tool is the screen split which lets you create multiple files instances in the same screen.
You have two kinds:

  • :vsp vertical split
  • :sp split (horizontal)

the usage of those commands are very similar with the :edit,
you just have to indicate which is the path of the file to split like:

:vsp <path-to-my-file>

or the horizontal split like:

:sp <path-to-my-file>

Using that you will be able to open, visualize and edit how many files do you want at the same time. But doing that you got to know how to move between split viewports.

Moving beetwen a split viewport

Splitting screen is a useful tool, but how do you move between those viewports?

For that you can use the ctrl + w following by the chosen direction.

For example, if you have two vertical viewports :vsp, you can use ctrl + w -> to focus on the right side, and then ctrl + w <- to go back to the left side.
This is called :wincdm and can find more about it here.

funny fact is that w is to remind you window

Maximizing and restoring viewports

Another great feature is that you can maximise those viewport while you working to get a better view of the file.
For that you can simple use:

  • ctrl + w _ for horizontals
  • ctrl + w | for verticals.

To return all viewports to a equal size you can use ctrl + w =

Conclusion

Vim can be a great friend with time, and while you get used with it. Its a hard path to leave you favorite text editor to become a vim user, but once you do and start to discover all the power of this awesome editor it gets very easy and for sure it will improve your production.

1 Response
Add your response

Also it's by far the best way of handling large files where flow jumps around. I didn't know how useful having multiple viewports open, placed at key points on the same buffer was until I started tracing the flow of some of Linux's subsystems.

over 1 year ago ·