- the following notes are derived from this awesome presentation
- a modal text editor
- modes:
- normal (default on start)
- insert
- visual
- command mode
- don't use the arrow keys
i,I
insert (begin of line)a,A
append (line end)
- cursor motions:
- use h,j,k,l for right,down,up,left
0
,$
jump begin/end of line
- word motions
w
,b
next/prev word beginninge
,eg
next/prev word ending
- character jump:
f<char>
,F<char>
find next/prev (on character)t<char>
,T<char>
find next/prev (one character before)
- other movement:
)
,(
next/prev sentences}
,{
next/prev paragraphs
- all those previous commands can be prefixed by a number (counts), e.g.
3j
jumps three lines down :set relativenumber
enables relative numbering based on the current line, this makes relative jump counts fairly easy
- change/replace
c
character,c$
=C
till end of line,cc
line- replace a word
cw
- replace a word
- delete
d
,d$
=D
till end of line,dd
line xC
,XC
deleteC
ount characters after/before- copy
y
character,Y
=yy
linemap Y y$
to get consistent behaviour
aw
a word,iw
inner wordas
a sentence,iw
inner sentenceap
a paragraph,ip
inner paragraphat
a tag,it
inner tag<h1>change in tag</h1>
to replace the heading:cit
(change in tag)
- modify inside
iX
, outsideaX
, where X is ", `, ', <, ...
.
repeat the last editJ
join lines
C-f
,C-b
page up/downC-d
,C-u
half page up/downC-y
,C-e
line up/down- relative to cursor:
zt
(top),zz
(center),zb
(bottom)
- move cursor inside window:
H
(top),M
(mid),L
(bottom) - jump to
<number>gg
top,<number>G
bottom of the file
v
char. wiseV
line wiseC-v
block wise
:
enter command modewq
wqa
write quite (all)x
,xa
only write if changes were madew!
discard and quitr <filepath>
read-in file%!command
filter through externalcommand
- e.g.
%!tr '[:lower:]' '[:upper:]'
- e.g.
:.!command
insertcommand
output in place- the
.
can be replaced with any position
- the
%s/foo/bar/g
replace every occurence offoo
withbar
,g
will match multiple occurences in one line%s/foo/bar/gc
like above with confirm
%
=1,$
entire file.,$
from current to last lineX,/some text/
from line x tosome text
- e.g.
v.,/autocomplete/
selects from current cursor to first occurence ofautocomplete
- e.g.
/text/+1
line belowtext
/
forward search?
backward search
- a buffer is basically a file
:ls
list buffers:sp
split window- a window is a view of a file
- switch between windows
C-{h,j,k,l}
- a
tab
is an arrangement of windows (not like a usual tab in GUI text editors)
- copy/paste buffers are `registers
- overview
:reg
"0
last yanked"1-"9
last deletes- named register
"a-z
- copy into named register
"aY
wherea
is the registers name andY
is yank line - GUI clipboards:
"*
and"+
- yank the entire file/buffer into the system clipboard:
%y+
:tab help
start help in tab:help <bs <tab>>
autocomplete help