I have been a long time user of Vim but started to get into some of the more advanced commands and one of my favourite with vim is the use of buffers and splitting the screen. Please note buffers and screen splitting functionality are only available in later versions of vim – version 5 onwards.

Buffers

You can edit multiple files simulatenously.

:e <filename> – To edit a secondary file

:ls – To list all files you are currently editting

:b<1> – To jump to a specific edited file.

:bn – To jump to the next file in the buffer

:bp – To jump to the previous file in the buffer

These last two commands are nice to place into you vim resource file to map a ctrl sequence onto the commands to quickly move between them.

Screen Splitting

Screen splitting is a step beyond and complimentary to buffers. Screen splitting allows to see the window split across the center of the current file (either horizontally or vertically) and allows you to see the currently editted file. This is extremely useful if you want to see your declarations or definition of a piece of code (especially in the same file). This is much prefered to opening a secondary file as you do not get warnings about swap files nor do you need to keep in mind where you can edit as all edits are to the same file.

<ctrl-w>  s – Split screen (horizontally)

<ctrl-w>  v – Split screen (vertically)

<ctrl-w>  c – Close current screen split

<ctrl-w>  k – Move up a screen split

<ctrl-w> j – Move down a screen split

<ctrl-w> l – Move right a screen split

<ctrl-w> h – Move left a screen split

<ctrl-w> r – Reverse screen splits

 

Screen virtual terminal emulation.

Finally as a tip – If you are working with Linux up can use the screen virtual terminal emulator. This will allow you to swap sessions on a virtual terminal

Use the command screen from a terminal session to start the virtual terminal emulator

Once running you can

<ctrl-a> c – To create a new session (no need to log in another session

<ctrl-a> k – To kill the session

<ctrl-a> ” – To list all your running screen sessions

<ctrl-a> A – Will allow you to name (title) each session

<ctrl-a> 1..9 – Will swap you to a given session

<ctrl-a> d – To detach from the session

If you detach, the screen session will continue to run, you can see what is still running with

screen -ls

then re-attach again if you are running just a single one with no session name, or just enough to make unique if more than on is running.

screen -r [session name]

 

Another use of screen permits you to run a session and let multiple users attach and work in it simulateously. This is done by running against a special resource file

screen -c .my_resource

Create .my_resource containing (for example)

sessionname <The session name>
shelltitle <The session name>

multiuser on