Tags

, ,

Being developed for terminals where only the keyboard is used, there are numerous keybindings and commands, and fluency with these enables the experienced user to perform actions faster than a GUI would allow. Maybe this is why the feature exists in Visual Studio Code also.

Basic Actions
Press the ‘I‘ or ‘A‘ key to start inserting text. There’ll be ‘— INSERT —‘ at the foot of the editor.

In order to save the file or quit, press the ‘Esc‘ key and ‘:’, then enter one of the following commands:
:w – Write buffer to file
:wq – Write buffer to file and quit
:q! – Quit without writing buffer

These are the commands that are quickest to pick up, and that’s pretty much all that’s needed for basic usage. Also, there is an online help feature, accessible by pressing the tab key after entering the first character of a command.

Another nice feature of vim is the buffer is actually saved somewhere, so if the system crashes or the connection drops before the file’s saved, the buffer can be reloaded when vim is next run.

Navigating Through File Contents
In addition to the ‘I‘ or ‘A‘ key for entering INSERT mode, there are several other key bindings for navigating through text: ‘H‘, ‘J‘, ‘K‘ and ‘L‘ are used for moving the cursor up, down, left and right one place.

Cutting and Pasting Text, and Reversing Changes
We can also copy and paste sections of text. Press ‘V‘ and whichever direction keys to select a section of text. Pressing ‘C‘ will cut the text and ‘P‘ to paste that section elsewhere. If the user wants to reverse that (or any other) change, this can be done with the ‘U‘ key.

Lastly vim enables the user to delete a character or section/paragraph with the ‘X‘ and ‘D‘ keys.

Searching Text
Often you’d want to find a string within the current file. Press the ‘Esc’ key, and use the following command:
:/[keyword]

And press ‘N‘ to scroll through the matches.

Configuration
The editor’s configuration is stored in /etc/vim/vimrc. If the GUI version is installed there’ll also be a gvimrc in the same directory, although I found an easier way to configure that is to save and load a session file.

The first thing you might want is a ‘soft wrap’ which wraps text within the editor without inserting line breaks in the file itself:
set columns=90

But we also don’t want to wrap in the middle of words, so set a line break:
set linebreak

Also, I’m used to seeing line numbers when modifying code:
set number

In another directory, /usr/share/vim/vim73/colors, there’ll also be a number of colour scheme files. Any of these can be set, e.g.
colorscheme evening

Advertisements