Type vimtutor
in your terminal.
VIM has three modes:
- To enter insert mode, hit
i
- To exit insert mode, hit
<ESC>
- To enter visual mode, hit
v
- To exit visual mode, hit
<ESC>
- insert mode- stuff you type is added to the buffer
- normal mode- keys you hit are interpreted as commands
- visual mode- allows you to select blocks of text
I use a vim gem below, you can clone it on Github.
https://github.com/carlhuda/janus
Some useful commands for me:
vim -o[number] . - open ‘.’ with [number] windows
operator [number] motion
d - delete word/line, and store it in a vim register
dw - delete word
d2w - delete two words
dd - delete the line
d2d - delete two lines
v - visual mode: highlight the text
[ctrl + v] - block visual mode, move the cursor with hjkl
I# [ESC] - insert ‘#’ to every line selected
y - yank (copy) the highlighted text
y2w - yank two words
p - paste
f - find
[number]f[character] - find the next [number]th [character]
3fc - find the next third ‘c’ character
$ - end of the line
d$ - delete to the end of the line
w - move to the start of the next word
2w - jump to the start of the next two words
e - move to the end of the current word
2e - jump to the end of the next two words
0 - move to the start of the line
r - replace
R - enter replace mode: replace more than one character
c - correct
ce - correct from current letter to the end of the word, and place you in Insert mode
c$ - correct to the end of the line, and place you in Insert mode
c2w - correct the next two words, and place you in Insert mode
[number] G - move to the line [number]
124 G - move to line 124
% - find a matching ), ] or }
^ - move to the first non-blank character of this line
g_ - move to the last non-blank character of this line
:s/old/new/g - substitute ’new’ for ‘old’ (s means substitute, g means globally in the line)
:![shell-command] - execute an external shell command
o - open command: open up a line BELOW the cursor and place you in Insert mode
O - open command: open up a line ABOVE the cursor and place you in Insert mode
a - append command: insert text AFTER the cursor
A - append command: insert text after the end of the line
[ctrl + n(or p)] - auto complement
:set option
:set nu - set number of current file
:set ic - set ignore case when searching
:set noic - disable ignore case
:set hls - highlight all matching phrases
ctrl + p - search a file in directory left
ctrl + w + v - open a new tab in vim
without ending…