Using vim for Development

Page 1 - Inserting text

vim - The Editor

Skip to navigation

Jun
22

One of my preferred editors when in Debian, or other *nix distribution is vim (sometimes aliased as vi). It is a powerful editor and has many shortcuts and commands that are not easy to figure out without browsing around the net. So here is my own attempt at collecting together and describing what it can do.

Opening vim with a filename will open the file for editing, or if the file doesn't exist it will create it when you save. Once you're editing a file you will see the contents of the file, but will not immediately be able to edit it. To do this you can press "i" and start entering text before the current cursor position. There are other keys that will enter text in a different modes. The following keys will also allow text input:

i
Start inserting text before the current cursor position
I
Insert text before the first non-whitespace character
a
Text will be appended after the current cursor position
A
Text will be appended at the end of the current line
o
New line below the current cursor position
O
New line above the current cursor position
gI
Start inserting text in column 1
r
Replace the next character with the following keypress
R
Replace characters instead of inserting

This will then work pretty much as you'd expect with what you typing appearing on the screen. When you have done typing you can press ESC to stop inserting text - this gives you the ability to type vim commands once more.

Esc
Exits text entry mode

If you make a mistake and need to remove it then you can do this by using:

x
Deletes the character after the cursor
X
Deletes the character before the cursor

Or to use the "history", you can undo and redo using:

u
Undo the last change
Ctrl + r
Redo the last change (after an undo)
U
Undo all previous changes to the current line