How To Speak To Vim
Why Vim?
- Modal editor
- Lightweight
- Usable through SSH
- Universal shortcuts (less, git diff...)
Vim Basics
Movements
h j k lw b efor ←↑↓→
move around words
^ $move to begin/end of line
Movements
tA fA;jump to character A
repeat the last "t" or "f" jump
%move to matching parenthesis
Movements
gg G123Gjump to beginning/end of file
jump to line 123
CTRL-U
CTRL-Dscroll up/down half a page
Movements
CTRL-I
CTRL-Oprevious/next in the jump list
The jump list!
Actions
o Onew line and insert
i aIinsertion mode
insert at beginning of line
Ainsert at end of line
Essentials
dypdelete (cut)
copy
paste
Actions
Essentials
uundo
CTRL-Rrecover
vVCTRL-Vselect
select whole lines
select by block
Actions
Essentials
combine it with I and A :)
cS ccrchange (delete + insert)
change line
replace one character
Actions
Useful
> <=add/remove one indent
auto indent
Actions
Useful
Vim as Language
Sentences
Verb + Modifier + Noun
action + modifier + object
or
action + movement
=
Sentences
Examples
`daw``ci(``dtP`delete a word
change inside parenthesis
delete until letter P
Sentences
Verbs (= actions)
d...delete
ppaste
cchange
ycopy
"yank"
=indent
Sentences
Modifiers
iinside
aaround
Sentences
Objects
wword
pparagraph
ssentence
t<tag>...</tag>
''...'
{{...}
((...)
Sentences
Repeat your sentences!
Use
.Search & Replace
Search & Replace
Searching
/hellon NSearches 'hello' in the file
Jumps to next/previous occurence
(can be combined with an action!
e.g. "delete until first occurence of 'hello'")
*Searches the word under the cursor
Search & Replace
Highlight spaces or tabs
/ highlights space characters
/\thighlights tab characters
:set hlsearch↓
"slash space"
Search & Replace
Replacing
:%s/hello/hi/gReplace 'hello' by 'hi' in the whole file
Search & Replace
Replacing
%s/hello/hi/gRange '%'
= whole file
Option 'g'
= replace all occurrences of each line
Search & Replace
Replace currently highlighted word
*then
%s//new word/gOther commands/tips
jump to next number of the line and increment/decrement it
CTRL-A CTRL-X<C-X><C-F>ctrl-x then ctrl-f successively
autocomplete filenames
References
- https://yanpritzker.com/learn-to-speak-vim-verbs-nouns-and-modifiers-d7bfed1f6b2d
Registers
Registers
Copy/paste from different places
"Prefix with and a character (= register name)
"ay"bpCopy in register 'a'
Paste from register 'b
Registers
Special registers
"+"%System clipboard :)
Current filename
(doesn't work through SSH!)
deck
By Pierre Poupin
deck
- 187