Skip to content

Instantly share code, notes, and snippets.

@eprev
Last active November 10, 2021 13:11
Show Gist options
  • Save eprev/d73ff6dd83e2d243ed60e03cee7585e4 to your computer and use it in GitHub Desktop.
Save eprev/d73ff6dd83e2d243ed60e03cee7585e4 to your computer and use it in GitHub Desktop.

Basics

Read-Write
:e[dit] [file] Edit File
:w[rite] [file] Write File
:w[rite] !sudo tee % Write File with Root Permission
:sav[eas] {file} Save File As and Open It
:q Exit Vim
:q! Quit Without Saving
:x Write File Changes and Exit
Miscellaneous
. Repeat the Last Command
Unix Shell
:!{command} Execute Command and Return
!!{command} Execute Command and Insert Output
:sh Temporary Returns to Unix

Moving in the Buffer

Up-Down
k Line Up
j Line Down
gg Begining of the File
G End of the File
H Top of the Screen
M Middle of the Screen
L Bottom of the Screen
{ Previous Paragraph
} Next Paragraph
:[range] At Line Number
Left-Right
h Character Left
l Character Right
b Begining of the Word
e End of the Word
0 Begining of the Line
^ First Non-Blank Character of the Line
$ End of the Line
( Previous Sentence
) Next Sentence
|[count] At Columnt Number
Scrolling
CTRL-Y Line Up
CTRL-E Line Down
CTRL-U Half-Page Up
CTRL-D Half-Page Down
CTRL-B Page Up
CTRL-F Page Down
Searching
/{pattern} Search Forward
?{pattern} Search Backword
n Next Occurrence
N Previous Occurrence
* Search Forward for Word Under Cursor
# Serach Backward for Word Under Cursor
% Matching Parenthesis
gd Local Definition
gD Global Definition
Marks
m {a-zA-Z} Set Mark
'{a-zA-Z} Jump to Mark
'' Previous Position
:marks List the Marks

Changing Text

Delete, Insert
["x]dd Delete Line
{Visual}["x]d Delete the Highlighted Text
["x]cc Delete Line and Start Insert
["x]C Delete to the End on the Line and Start Insert
{Visual}["x]c Delete the Highlighted Text and Start Insert
:g[lobal]/{patern}/d Delete Lines Containing Pattern
Copy, Move
:reg[isters] Contents of Registers (0 - default register, 1-9 - shifting delete register, " - unnamed register)
["x]yy Yank Lines
{Visual}["x]y Yank the Highlighted Text
["x]p Put Text After
["x]P Put Text Before
["x]gp Put Text After and Move Cursor
CTRL+R {register} Put Text Before (Command Mode)
Changes
R Replace Mode
r{char} Replace Character
~ Change Case of Character
g~~ Change Case of Line
{Visual}~ Change Case of Highlighted Text
gUU Make Line Uppercase
{Visual}U Make Highlighted Text Uppercase
guu Make Line Lowercase
{Visual}u Make Highlighted Text Lowercase
gJ Join Lines
{Visual}J Join Lines With Spaces
CTRL-A Increment Number Under Cursor
CTRL-X Decrement Number Under Cursor
Shifting
<< Shift Lines Leftwards
{Visual}< Shift Highlighted Lines Leftwards
>> Shift Lines Rightwards
{Visual}> Shift Highlighted Lines Rightwards
== Auto Indent Lines
{Visual}= Auto Indent Highlighted Lines
=% Auto Indent Lines Between Parenthesis
Substitute
:[range]s[ubstitute]/{pattern}/{string}/[flags] Replace a Match. Flags: c (With Confirmation), g (Replace All), i (Ignore Case). Use % in range for entire file.
:[range]s[ubstitute] Repeat Last Substitute
:re[tab] [tabstop] Reformat and Change Tabstop
Formating
:ce[nter] [width] Center Lines
:ri[ght] [width] Right-Align Lines
:le[ft] [indent] Left-Align Lines

Tabs & Windows

Tabs
:tabe[dit] {file} Creates Tab
gt Next Tab
gT Previous Tab
:tabr[ewind] First Tab
:tabl[ast] Last Tab
:tabm[ove] [N] Move Tab
:tab ball Put All Open Files In Tabs
Windows
:sp[lit] [file] Split Window Horizontally
:vs[plit] {file} Split Window Vertically
CTRL-W j Window Below Current
CTRL-W k Window Above Current
CTRL-W CTRL-W Next Window
CTRL-W _ Maximize Window Vertically
CTRL-W | Maximize Window Horizontally
CTRL-W = Resize All Windows
[N] CTRL-W + Add Lines to Window
:hid[e] Close Window
:on[ly] Close All But This
:ls Show All Buffers
:b[uffer] N Open Window

Insert Mode

Auto-Completion
CTRL-N Next Keyword
CTRL-P Previous Keyword
Indent
CTRL-T Indent Line
CTRL-D Unindent Line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment