Vim Masterclass Part #2: Tab Navigation

Following on from Paul’s excellent Vim Masterclass: Tabs post, I thought I would touch on a few nice keymaps that you can add to your .vimrc file to make the tab functionality within vim a little more friendly.

.vimrc file

The .vimrc file is used to setup the configuration of vim, from within this file you can do many things such as setting shift widths, colours, indents and syntax highlighting etc.

Tab Navigation

Recently when using tabs I found that the navigation between tabs was quite cumbersome, so I created a few keymaps to handle this. Keys can be mapped depending on what mode you are using, but we want this to be generic, so by using the following command we can map a key :

:map <C-k>

this would map to CTRL-k, and based on this type of rule it is really easy to create a set of rules to help us.

All I wanted was the ability to move left and right between tabs easily, and also create new tabs. In a browser such as firefox this can be done simply by pressing CMD-t, and with this in mind I decided to create the following shortcuts :

CTRL+j moves to the previous tab (left)

CTRL+k moves to the next tab (right)

CTRL+t creates a new empty tab

So to create these I simply needed to create a rule for each command within my .vimrc file, as follows :

:map <C-j> <Esc>:tabprevious<CR>

:map <C-k> <Esc>:tabnext<CR>

:map <C-t> <Esc>:tabnew<CR>

This will prevent us from having to type <ESC>:tabprevious when we want to move one tab to the left, and combining these commands with the default VIM commands to open an existing file and “save as” new filename makes vim much better to use in a tabbed environment.

This entry was posted in Managed Hosting. Bookmark the permalink.

Leave a Reply

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


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>