vim

m

insert

r

This uses special keys to move around, while remaining in Insert mode. Thisresembles what you would do in a modeless editor. It's easier to remember,but takes more time (you have to move your hand from the letters to the cursorkeys, and the <End> key is hard to press without looking at the keyboard). These special keys are most useful when writing a mapping that doesn'tleave Insert mode. The extra typing doesn't matter then. An overview of the keys you can use in Insert mode: <C-Home> to start of the file <PageUp> a whole screenful up <Home> to start of line <S-Left> one word left <C-Left> one word left <S-Right> one word right <C-Right> one word right <End> to end of the line <PageDown> a whole screenful down <C-End> to end of the fileThere are a few more, see |ins-special-special|.

:help

repeat

.

repeat last command

n

repeat / or ? forward (search)

N

repeat / or ? backward(search)

&

:s

repeat last substitute

motion.text

nav

delete

d

select

Vi{

select in bracket

m(char)

mark to char

'(char)

go to char

'.

go to last edit

'"

go to last cursor pos

z(folding)

r

*28.5* Folding by indentDefining folds with |zf| is a lot of work. If your text is structured bygiving lower level items a larger indent, you can use the indent foldingmethod. This will create folds for every sequence of lines with the sameindent. Lines with a larger indent will become nested folds. This works wellwith many programming languages.Try this by setting the 'foldmethod' option: :set foldmethod=indentThen you can use the |zm| and |zr| commands to fold more and reduce folding.It's easy to see on this example text:

textobject

ciw

change in word

caw

change in word greedy

ci{ [ci}]

change in bracket

ctM

change 'till 'M'

==

fix indentation

search

cursor

screens

windows

ctrl+w

w

tumble through windows

v

split vertically

s

split horizontally

tabs

gt

next

gT

prev

#gt

tab number

completion

ctrl + p (or ctrl + n)

pathing

%

install

Mac

terminal

brew install macvim --override-system-vim

:

ls

list all files in buffer

ctrl + ^

switch active buffer

:buffer n

switch to buffer by number

:bn

buffer next

:bp

buffer prev

regexp

:%s/oldstuff/newstuff/gci

simple global find and replace(confirm/caseinsensitive[i]casesensitive[I])

!

r

*21.2* Executing shell commandsTo execute a single shell command from Vim use ":!{command}". For example, tosee a directory listing: :!ls :!dirThe first one is for Unix, the second one for MS-Windows. Vim will execute the program. When it ends you will get a prompt to hit<Enter>. This allows you to have a look at the output from the command beforereturning to the text you were editing. The "!" is also used in other places where a program is run. Let's takea look at an overview: :!{program} execute {program} :r !{program} execute {program} and read its output :w !{program} execute {program} and send text to its input :[range]!{program} filter text through {program}

r

Replace:%s/old/new/g Replace all occurences of old by new in file:%s/old/new/gw Replace all occurences with confirmation:2,35s/old/new/g Replace all occurences between lines 2 and 35:5,$s/old/new/g Replace all occurences from line 5 to EOF:%s/^/hello/g Replace the begining of each line by hello:%s/$/Harry/g Replace the end of each line by Harry:%s/onward/forward/gi Replace onward by forward, case unsensitive:%s/ *$//g Delete all white spaces:g/string/d Delete all lines containing string:v/string/d Delete all lines containing which didn’t contain string:s/Bill/Steve/ Replace the first occurence of Bill by Steve in current line:s/Bill/Steve/g Replace Bill by Steve in current line:%s/Bill/Steve/g Replace Bill by Steve in all the file:%s/\r//g Delete DOS carriage returns (^M):%s/\r/\r/g Transform DOS carriage returns in returns:%s#<[^>]\+>##g Delete HTML tags but keeps text:%s/^\(.*\)\n\1$/\1/ Delete lines which appears twiceCtrl+a Increment number under the cursorCtrl+x Decrement number under cursorggVGg? Change text to Rot13

gr[ep] -rin -A 2 "pattern" .

search for text pattern(plus 2 lines) in all files at current pwd

ack "pattern" *

search for text in current directory

binary

:set binary

:set display=uhex

:%!xxd

-r

(revert?)

Tab/

=(char)

(Tabularize)align to char

(char)\zs

align to char(after char)

:Git

:Gstatus

-

stage file

:Gcommit

push origin master

macro

qq

begin rec

....

stop

q

@q

access macro