:split <file>
:<lines_height>sp <file>
:vs <file>
Ctrl+w+<direction>
to move between splits
Remember you can use Ctrl+^(6)
to switch between buffers.
- Normal - Command
:
Line (from normal)i
/a
InsertR
Replace
Leave mode with ESC
[count]operation{motion}
operation operation
: does operation on all the line (for exampleg~~
for caps), this happens as repeating operation gets interpreted as a line motion ($
).
/u
/redo
repeat/undo/redo- `:help
-
j
/k
Up and down -
h
/l
Left and right -
Ctrl f
page down -
Ctrl b
page up -
w/b
move right/left one word -
W/B
move right/left one word ignoring puntuaction -
0
beginning of line -
$
end of line -
gg
first line of the file -
G
last line of the file -
<LINE_NUM>gg
or:<LINE_NUM><Enter>
specific line -
CTRL G
Get information about lines
x/X
deletes from cursor / del previousdw
delete worddd
deletes current lined + motion (j/k)
deletes line + line you would have navigated tod + motion (0/$)
deletes till the beginning/end of the line
d
andx
don't delete, they cuty
yank (copy),yy
to fast copy linep/P
put below/above actual line<REG>p
put from desired register
Registers :reg <ENTER>
You can use a specific register for example, black hole register "_dd
.
You can also use specific registers, for example "ayy
to copy line to "a
register,
and then put from it with "ap
.
You can append to a register instead of insert, using its name in caps. For example:
"Ayy
will append instead of replace all content.
- Unnammed:
- "" holds text from d,c,s,x and y operations
- "0 holds last text yanked (y)
- "1 holds last text deleted (d) or changed (c)
- Numbered shift with each d or c
I
shift from beginning of line and go into Insert modea
insert after current positionA
insert after end of the lineo/O
insert on new line below/above current onecw
change word, this can be used with a specific registerc$
replace till the end of the linecc
repalce line~[motion]
invert caps,g~~
/g~$
gU[motion]
/gu[motion]
mayus or minusshift [direction]
join lines
f/F {char}
Search forward/backward in line (case sensitive)t/T {char}
same asf
but places cursor before/after result;/,
next/previous ocurrence
For example, you can delete everything up until next ocurrence of a character with d t {char}
Search across file
-
/{word} <ENTER>
forward search (in command line mode) -
?{word} <ENTER>
reverse search -
n / N
next/previous ocurrence -
c w
to replace word, you can basicaly used
c
y
-
/\<is\>
regexp allowed, with this example you can find only exact word -
* / #
search for newxt/previous occurence of current word -
:[range]s/<word1>/<word2>/[flags]
replaces occurences of word1 with word2 in current line. -
g
flag to replace every ocurrence -
range
1 or more line lumbers separeted by comma -
range
can also be: -
.
current line -
.,$
current line till last line -
%
all lines -
/PATTERN-1/,/PATTERN-2/
you could only run operations between two search results for example:/<word1>/,/<word2>/s/<replace_this_word>/<replacement_word>/g
, another example would be:/word1/,$s/
{operator}{a/i}{object}
d
c
y
d a w
delete a wordd/c i w
delete/change inner wordd i p
delete a inner paragraphc i [/(/<
deletes everythin inside object, you can usea
instead ofi
to delete object too[
=b
(
=p
<
=t
A usefull example is, for manipulating everything inside brackets:
d|v|y i <bracket>
, where bracket can be (, [, {, etc...d|v|y a <bracket>
if you also want to delete the bracket
Normalize data, cleanup, change format, basically any repetable operation. Nothing more than a recorded sequence of keystrokes.
q <nammed register
: record a macro, for exampleq a
, to stop pressq
.@ <nammed register>
: apply macro<lineNum>,<lineNum>normal @ <nammedregister>
to apply to multiple lines
Best practices:
- Noralize the cursor position with
0
- Perform edits and operations
- Position your cursor in next line enable easy replays, for example with
j
-
v
characterwise visual mode -
V
linewise visual mode -
Ctrl v
blockwise visual mode -
g v
rapidly select previous selection -
>
>>
indent -
{motions}
to highlight -
{operations}
affect highlighted text -
If you want to highlight to both sides of the cursor, first move to the beginning of your selection with
o
. You can do the opposite withO
. -
You can use text objects to operate with highlights, for example
v a p
to highlight a paragraph -
You can use
i
nserty
ankc
hanger
eplacex
deletej
oinu
/U
upper/lower case,<
/>
shift left/right. -
You can perform commands over selected area, for example, if you highlight an area in visual mode and press
:
, you can perform a substitution withs/word1/word2/g
-
Center text with
:ce
, you can also do:right
and:left
~/.vimrc
, you can make comments with"
.:h option-list
check all options
Helpful options:
set history=1000
: keep 1000 items in historyset ruler
: show cursor positionset showcmd
: show incomplete commandsset wildmenu
: shows menu when using tab completionset scrolloff=5
: how many lines to keep above the cursorset hlsearch
: highligh search resultsset incsearch
: highlight incremental searchsset ignorecase
andset smartcase
: ignore case if uppercase not in search termset number
: set column numberset ai
: set auto indentset si
: smart indentset bg=light/dark
color <schema>
, you can install custom ones in~/.vim/colors
map <F2> i<your_name>
: create a macro for f2, you can do it with multiple keyslet mapleader="<key>"
: by default\
map <leader>w :w!
: now you can use\ w
- Editing multiple files:
vim file1 file2
orvim file-*
:buffers
/:ls
to see opened files:buffer/b <num>
to change between files