vim is the upgraded version of vi, a "modal" text editor that leaves the user between two major modes, insertion mode and command mode.
The user writes text in insertion mode and can enter commands in command mode, like searching or replacing text etc.
In giving you a list of commands, anything surrounding by {} braces is to be considered a variable which is to be replaced by what is appropriate for you, except for the case in defining the effects of the braces themselves, which should be evident from context
Ex commands are commands that start with ":", like the command to replace text for example (:s),
to get a complete list of Ex commands type
:help holy-grail
The user is by default in command mode upon opening a file with vim. There are a number of keys to get the user into insert mode, where the user can write to the file what he/she wants.
Here is a list of keys to get the user into insertion mode from command mode:
in moving through vim, vim defines a "word" as a string of characters up to separated by white space, as well as punctuation marks, which are considered words themselves.
command | result |
---|---|
<Enter> |
move to first character of next line |
- | first character of prev line |
h | move one position to the left |
j | move one position to the bottom |
k | move one position to the top |
l | move one position to the right |
w | move to the next beginning position of a "word" |
b | move to the next beginning position of previous "word" |
e | move to the next end position of a "word" |
W/E/B | same as their lowercase counterparts except that this ignores punctation marks in defining a "word" |
command | result |
---|---|
# or * | jump to previous/next occurrence of current word (the word your cursor is currently on) |
{ or } | jump to next/previous paragraph |
( or ) | jump to next/previous sentence |
% | jump to enclosing character (any of these characters are enclosing characters "<>{}()[]" ) |
G | jump to last line |
{i}G or :{i} | jump to line number i |
gg | jump to first line |
'' | jump back to the start of the line you were in before jumping to your current position |
`` | jump back to the exact position of the line you were in before jumping to your current position |
command | result |
---|---|
f{n} | move cursor to next occurrence of character n in current line |
F{n} | move cursor to previous occurrence of character n in current line |
t{n} | move cursor to one position before next occurrence of character n in current line |
T{n} | move cursor to one position after previous occurrence of character n in current line |
; | repeat forward |
, | repeat backward |
{i}| | go to ith char of line |
0 | move to beginning of current line |
^ | move to beginning of text in current line |
$ | move to end of line |
command | result |
---|---|
H | "home", moves cursor to top of screen |
L | moves cursor to bottom of screen |
M | "middle", moves cursor to middle of screen |
Sometimes you want to scroll the page to get a better view of the text and context.
Moving the page screen does not move the cursor! (unless the cursor is not within view of the movement, in which case the cursor is moved)
<ENTER>
Copying/cutting text is referred to as yanking text. When yanking text in vim, the text gets put into a special buffer (whether copying or cutting text). Deleting text is considered the same as cutting text, so when you delete text you by default are cutting the text and placing it into the special buffer.
The buffer is interesting in that it can store up to 9 items, as you will soon see, and you can access those yanked items by cycling through it's index.
Something annoying I've found with mac os is that it is difficult to paste text from os clipboard to the vim terminal, but, as a friend tells me, it is not the case with linux. I don't know a fix other than to open the file with another text editor to paste outside text, then resume session within vim.
you can combine movement keys with these commands for more precise typing. Examples:
for k = command (whether it be y, d, or c)
This buffer can store up to 9 yanked items. It keeps the text in a last in first out order.
another method to pasting what you want is
This buffer can store up to 26 yanked text, ranging from buffer a to z
when you want to replace a single occurrence of text with something else you can use these commands
<SPACE>
")typing v in command mode takes you to visual mode where you can highlight the text you want to manipulate.
:help :<help-topic>
vim settings (like plugins to install, highlight colors, number of spaces in place of tabs etc) are to be placed in home directory (~/ in unix systems) in a file called .vimrc.
if you want to use custom setup for a file, make a custom configuration file and type in your working file :so {config_filename}
When trying to master vim, avoid using arrow keys and train yourself to use vim's movement keys, especially the search tools.
Learn to copy text from one file to another well and to switch between files quickly (however way you choose).
Plug in error checking syntax for the programming language you plan to write in, vim supports syntax checking for multiple languages.