Learning the vi Editor/Vim/Basic navigation

Learning the vi Editor: Getting acquaintedBasic tasksMaking your work easierAdvanced tasksDetailsVi clones (VimBasic navigationModesTips and TricksUseful things for programmers to knowEnhancing VimVim on WindowsVimL Script language, Vile, BB vi)vi Reference

Basic navigation

edit

Basic navigation in vim is covered below.

Moving around

edit

We can move around in the editor by first entering command mode, and then using the <h>, <j>, <k>, and <l> keys.

Note
your arrow keys may be set up to work, and you can use them if you like, but for proficiency and for advanced work later, you should learn to use the letter keys.
  • The <h> key, in command mode, moves the cursor one character left.
  • The <j> key, in command mode, moves the cursor one character down.
  • The <k> key, in command mode, moves the cursor one character up.
  • The <l> key, in command mode, moves the cursor one character right.

If you have trouble remembering this, keep in mind that <h> is leftmost, the letter <j>goes down below the line, the letter <k>pokes up above the line, and the <l> key is rightmost. (J also resembles an arrow pointing downward, if you squint a bit.)

After you have moved the cursor using those keys, you can enter insert mode again by pressing <i>. When you do this, you insert text at the cursor, inserting text between the character to the left of the cursor and the current position of the cursor. Let's practice this in an exercise.


VIM Help system

edit

vim is a very feature rich application. Unlike the 'vi' editor it includes a help system. Because the help system will allow you to teach yourself much more than any book on vim possibly could, you will benefit from the power of the vim editor much more if you learn to use it. On a normal vim installation you should be able to start the online help by pressing the <HELP> key . If your keyboard does not feature a <HELP> key then you can try <F1> instead. (Some system administrators may have changed how vim behaves. If you cannot get into vim's help system with these commands, perhaps your administrator can help.)

:help

Start vim and enter command mode by pressing escape. To get help on any command simply type :help command.

For example, if you would like to learn all the different ways the :x command can be used you could type :h x. To move around in the help files the same keys work, <h>, <j>, <k>, <l>. To leave the help files type :quit. If you know you want to do something, but you aren't sure what the command might be you can type partial commands like this :help cut. To learn to switch text from upper case to lower case you could type :help lowercase

When you search for help on any subject, vim will (normally by default) create a window (buffer) which you can navigate just like any window in vim. You can close the help window by typing :quit or :q and pressing enter.

The default help file (shown when you type "help") explains basic navigation for vim and for vim's help files.


Learning the vi Editor: Getting acquaintedBasic tasksMaking your work easierAdvanced tasksDetailsVi clones (VimBasic navigationModesTips and TricksUseful things for programmers to knowEnhancing VimVim on WindowsVimL Script language, Vile, BB vi)vi Reference