Created
August 26, 2016 14:14
-
-
Save zachbrowne/d88cfb1c2eb6ffc21a9126a7f0566e2a to your computer and use it in GitHub Desktop.
The Ultimate Bad Ass VIM Cheat Sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
<title>The Ultimate Bad Ass VIM Cheat Sheet by Zach Browne</title> | |
<meta name="viewport" content="width=device-width"> | |
<meta name="description" content="The Ultimate Bad Ass VIM Cheat Sheet"> | |
<link rel="canonical" href="http://zachbrowne.me/"> | |
<!-- Custom CSS --> | |
<link rel="stylesheet" href="main.css"> | |
</head> | |
<body class="en_us"> | |
<div class="container"> | |
<div class="grid-block"> | |
<div class="grid-1"> | |
<h1><a class="site-title" href="/">The Ultimate Bad Ass VIM Cheat Sheet</a></h1> | |
</div> | |
</div> <!-- end row --> | |
<div class="commands-container"> | |
<div class="grid-block"> | |
<div class="grid-lg-1-3"> | |
<h2>Global</h2> | |
<ul> | |
<li><kbd>:help keyword</kbd> - open help for keyword</li> | |
<li><kbd>:o file</kbd> - open file</li> | |
<li><kbd>:saveas file</kbd> - save file as</li> | |
<li><kbd>:close</kbd> - close current pane</li> | |
</ul> | |
<h2>Cursor movement</h2> | |
<ul> | |
<li><kbd>h</kbd> - move cursor left</li> | |
<li><kbd>j</kbd> - move cursor down</li> | |
<li><kbd>k</kbd> - move cursor up</li> | |
<li><kbd>l</kbd> - move cursor right</li> | |
<li><kbd>w</kbd> - jump forwards to the start of a word</li> | |
<li><kbd>W</kbd> - jump forwards to the start of a word (words can contain punctuation)</li> | |
<li><kbd>e</kbd> - jump forwards to the end of a word</li> | |
<li><kbd>E</kbd> - jump forwards to the end of a word (words can contain punctuation)</li> | |
<li><kbd>b</kbd> - jump backwards to the start of a word</li> | |
<li><kbd>B</kbd> - jump backwards to the start of a word (words can contain punctuation)</li> | |
<li><kbd>0</kbd> - jump to the start of the line</li> | |
<li><kbd>^</kbd> - jump to the first non-blank character of the line</li> | |
<li><kbd>$</kbd> - jump to the end of the line</li> | |
<li><kbd>g_</kbd> - jump to the last non-blank character of the line</li> | |
<li><kbd>gg</kbd> - go to the first line of the document</li> | |
<li><kbd>G</kbd> - go to the last line of the document</li> | |
<li><kbd>5G</kbd> - go to line 5</li> | |
<li><kbd>fx</kbd> - jump to next occurrence of character x</li> | |
<li><kbd>tx</kbd> - jump to before next occurrence of character x</li> | |
<li><kbd>}</kbd> - jump to next paragraph (or function/block, when editing code)</li> | |
<li><kbd>{</kbd> - jump to previous paragraph (or function/block, when editing code)</li> | |
<li><kbd>Ctrl</kbd> + <kbd>b</kbd> - move back one full screen</li> | |
<li><kbd>Ctrl</kbd> + <kbd>f</kbd> - move forward one full screen</li> | |
<li><kbd>Ctrl</kbd> + <kbd>d</kbd> - move forward 1/2 a screen</li> | |
<li><kbd>Ctrl</kbd> + <kbd>u</kbd> - move back 1/2 a screen</li> | |
</ul> | |
<div class="well"> | |
<strong>Tip</strong> Prefix a cursor movement command with a number to repeat it. For example, <kbd>4j</kbd> moves down 4 lines. | |
</div> | |
<h2>Insert mode - inserting/appending text</h2> | |
<ul> | |
<li><kbd>i</kbd> - insert before the cursor</li> | |
<li><kbd>I</kbd> - insert at the beginning of the line</li> | |
<li><kbd>a</kbd> - insert (append) after the cursor</li> | |
<li><kbd>A</kbd> - insert (append) at the end of the line</li> | |
<li><kbd>o</kbd> - append (open) a new line below the current line</li> | |
<li><kbd>O</kbd> - append (open) a new line above the current line</li> | |
<li><kbd>ea</kbd> - insert (append) at the end of the word</li> | |
<li><kbd>Esc</kbd> - exit insert mode</li> | |
</ul> | |
</div> | |
<div class="grid-lg-1-3"> | |
<h2>Editing</h2> | |
<ul> | |
<li><kbd>r</kbd> - replace a single character</li> | |
<li><kbd>J</kbd> - join line below to the current one</li> | |
<li><kbd>cc</kbd> - change (replace) entire line</li> | |
<li><kbd>cw</kbd> - change (replace) to the end of the word</li> | |
<li><kbd>c$</kbd> - change (replace) to the end of the line</li> | |
<li><kbd>s</kbd> - delete character and substitute text</li> | |
<li><kbd>S</kbd> - delete line and substitute text (same as cc)</li> | |
<li><kbd>xp</kbd> - transpose two letters (delete and paste)</li> | |
<li><kbd>u</kbd> - undo</li> | |
<li><kbd>Ctrl</kbd> + <kbd>r</kbd> - redo</li> | |
<li><kbd>.</kbd> - repeat last command</li> | |
</ul> | |
<h2>Marking text (visual mode)</h2> | |
<ul> | |
<li><kbd>v</kbd> - start visual mode, mark lines, then do a command (like y-yank)</li> | |
<li><kbd>V</kbd> - start linewise visual mode</li> | |
<li><kbd>o</kbd> - move to other end of marked area</li> | |
<li><kbd>Ctrl</kbd> + <kbd>v</kbd> - start visual block mode</li> | |
<li><kbd>O</kbd> - move to other corner of block</li> | |
<li><kbd>aw</kbd> - mark a word</li> | |
<li><kbd>ab</kbd> - a block with ()</li> | |
<li><kbd>aB</kbd> - a block with {}</li> | |
<li><kbd>ib</kbd> - inner block with ()</li> | |
<li><kbd>iB</kbd> - inner block with {}</li> | |
<li><kbd>Esc</kbd> - exit visual mode</li> | |
</ul> | |
<h2>Visual commands</h2> | |
<ul> | |
<li><kbd>></kbd> - shift text right</li> | |
<li><kbd><</kbd> - shift text left</li> | |
<li><kbd>y</kbd> - yank (copy) marked text</li> | |
<li><kbd>d</kbd> - delete marked text</li> | |
<li><kbd>~</kbd> - switch case</li> | |
</ul> | |
<h2>Registers</h2> | |
<ul> | |
<li><kbd>:reg</kbd> - show registers content</li> | |
<li><kbd>"xy</kbd> - yank into register x</li> | |
<li><kbd>"0p</kbd> - paste contents of register x</li> | |
</ul> | |
<div class="well"> | |
<strong>Tip</strong> Registers are being stored in ~/.viminfo, and will be loaded again on next restart of vim. | |
</div> | |
<div class="well"> | |
<strong>Tip</strong> Register 0 contains always the value of the last yank command. | |
</div> | |
<h2>Marks</h2> | |
<ul> | |
<li><kbd>:marks</kbd> - list of marks</li> | |
<li><kbd>ma</kbd> - set current position for mark A</li> | |
<li><kbd>`a</kbd> - jump to position of mark A</li> | |
<li><kbd>y`a</kbd> - yank text to position of mark A</li> | |
</ul> | |
<h2>Macros</h2> | |
<ul> | |
<li><kbd>qa</kbd> - record macro a</li> | |
<li><kbd>qq</kbd> - stop recording macro</li> | |
<li><kbd>@@</kbd> - rerun last run macro</li> | |
</ul> | |
</div> | |
<div class="grid-lg-1-3"> | |
<h2>Cut and paste</h2> | |
<ul> | |
<li><kbd>yy</kbd> - yank (copy) a line</li> | |
<li><kbd>2yy</kbd> - yank (copy) 2 lines</li> | |
<li><kbd>yw</kbd> - yank (copy) the characters of the word from the cursor position to the start of the next word</li> | |
<li><kbd>y$</kbd> - yank (copy) to end of line</li> | |
<li><kbd>p</kbd> - put (paste) the clipboard after cursor</li> | |
<li><kbd>P</kbd> - put (paste) before cursor</li> | |
<li><kbd>dd</kbd> - delete (cut) a line</li> | |
<li><kbd>2dd</kbd> - delete (cut) 2 lines</li> | |
<li><kbd>dw</kbd> - delete (cut) the characters of the word from the cursor position to the start of the next word</li> | |
<li><kbd>D</kbd> - delete (cut) to the end of the line</li> | |
<li><kbd>d$</kbd> - delete (cut) to the end of the line</li> | |
<li><kbd>x</kbd> - delete (cut) character</li> | |
</ul> | |
<h2>Exiting</h2> | |
<ul> | |
<li><kbd>:w</kbd> - write (save) the file, but don't exit</li> | |
<li><kbd>:w !sudo tee %</kbd> - write out the current file using sudo</li> | |
<li><kbd>:wq</kbd> or <kbd>:x</kbd> or <kbd>ZZ</kbd> - write (save) and quit</li> | |
<li><kbd>:q</kbd> - quit (fails if there are unsaved changes)</li> | |
<li><kbd>:q!</kbd> or <kbd>ZQ</kbd> - quit and throw away unsaved changes</li> | |
</ul> | |
<h2>Search and replace</h2> | |
<ul> | |
<li><kbd>/pattern</kbd> - search for pattern</li> | |
<li><kbd>?pattern</kbd> - search backward for pattern</li> | |
<li><kbd>\vpattern</kbd> - 'very magic' pattern: non-alphanumeric characters are interpreted as special regex symbols (no escaping needed)</li> | |
<li><kbd>n</kbd> - repeat search in same direction</li> | |
<li><kbd>N</kbd> - repeat search in opposite direction</li> | |
<li><kbd>:%s/old/new/g</kbd> - replace all old with new throughout file</li> | |
<li><kbd>:%s/old/new/gc</kbd> - replace all old with new throughout file with confirmations</li> | |
<li><kbd>:noh</kbd> - remove highlighting of search matches</li> | |
</ul> | |
<h2>Search in multiple files</h2> | |
<ul> | |
<li><kbd>:vimgrep /pattern/ {file}</kbd> - search for pattern in multiple files</li> | |
</ul> | |
<div class="well"> | |
e.g. | |
<kbd>:vimgrep /foo/ **/*</kbd> | |
</div> | |
<ul> | |
<li><kbd>:cn</kbd> - jump to the next match</li> | |
<li><kbd>:cp</kbd> - jump to the previous match</li> | |
<li><kbd>:copen</kbd> - open a window containing the list of matches</li> | |
</ul> | |
</div> | |
</div> <!-- end grid-block --> | |
<div class="grid-block"> | |
<div class="grid-lg-1-3"> | |
<h2>Working with multiple files</h2> | |
<ul> | |
<li><kbd>:e</kbd> filename - edit a file in a new buffer</li> | |
<li><kbd>:bnext</kbd> or <kbd>:bn</kbd> - go to the next buffer</li> | |
<li><kbd>:bprev</kbd> or <kbd>:bp</kbd> - go to the previous buffer</li> | |
<li><kbd>:bd</kbd> - delete a buffer (close a file)</li> | |
<li><kbd>:ls</kbd> - list all open buffers</li> | |
<li><kbd>:sp</kbd> filename - open a file in a new buffer and split window</li> | |
<li><kbd>:vsp</kbd> filename - open a file in a new buffer and vertically split window</li> | |
<li><kbd>Ctrl</kbd> + <kbd>ws</kbd> - split window</li> | |
<li><kbd>Ctrl</kbd> + <kbd>ww</kbd> - switch windows</li> | |
<li><kbd>Ctrl</kbd> + <kbd>wq</kbd> - quit a window</li> | |
<li><kbd>Ctrl</kbd> + <kbd>wv</kbd> - split window vertically</li> | |
<li><kbd>Ctrl</kbd> + <kbd>wh</kbd> - move cursor to the left window (vertical split)</li> | |
<li><kbd>Ctrl</kbd> + <kbd>wl</kbd> - move cursor to the right window (vertical split)</li> | |
<li><kbd>Ctrl</kbd> + <kbd>wj</kbd> - move cursor to the window below (horizontal split)</li> | |
<li><kbd>Ctrl</kbd> + <kbd>wk</kbd> - move cursor to the window above (horizontal split)</li> | |
</ul> | |
</div> | |
<div class="grid-lg-1-3"> | |
<h2>Tabs</h2> | |
<ul> | |
<li><kbd>:tabnew</kbd> filename or <kbd>:tabn</kbd> filename - open a file in a new tab</li> | |
<li><kbd>Ctrl</kbd> + <kbd>wT</kbd> - move the current split window into its own tab</li> | |
<li><kbd>gt</kbd> or <kbd>:tabnext</kbd> or <kbd>:tabn</kbd> - move to the next tab</li> | |
<li><kbd>gT</kbd> or <kbd>:tabprev</kbd> or <kbd>:tabp</kbd> - move to the previous tab</li> | |
<li><kbd>#gt</kbd> - move to tab number #</li> | |
<li><kbd>:tabmove #</kbd> - move current tab to the #th position (indexed from 0)</li> | |
<li><kbd>:tabclose</kbd> or <kbd>:tabc</kbd> - close the current tab and all its windows</li> | |
<li><kbd>:tabonly</kbd> or <kbd>:tabo</kbd> - close all tabs except for the current one</li> | |
<li><kbd>:tabdo</kbd> command - run the <code>command</code> on all tabs (e.g. <code>:tabdo q</code> - closes all opened tabs)</li> | |
</ul> | |
</div> | |
</div> <!-- end grid-block --> | |
</div> | |
<div > | |
<!-- Web2PDF Converter Button BEGIN --> | |
<script type="text/javascript"> | |
var | |
pdfbuttonlabel="Save page as PDF" | |
</script> | |
<script src="http://www.web2pdfconvert.com/pdfbutton2.js" id="Web2PDF" type="text/javascript"></script> | |
<!-- Web2PDF Converter Button END --> | |
</div> <!-- end container --> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! normalize.css v3.0.1 | MIT License | git.io/normalize */ | |
html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,main,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}h1{font-size:2em;margin:.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input{line-height:normal}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:.35em .625em .75em}legend{border:0;padding:0}textarea{overflow:auto}optgroup{font-weight:bold}table{border-collapse:collapse;border-spacing:0}td,th{padding:0} | |
/*Layout*/ | |
* { | |
-webkit-box-sizing: border-box; | |
-moz-box-sizing: border-box; | |
box-sizing: border-box; | |
} | |
.grid-block { | |
clear: both; | |
letter-spacing: -.31em; | |
display: -webkit-flex; | |
-webkit-flex-flow: row wrap; | |
display: -ms-flexbox; | |
-ms-flex-flow: row wrap; | |
overflow: hidden; | |
text-rendering: optimizespeed; | |
width: 100%; | |
} | |
.grid-block, .grid-1, .grid-lg-1-2, .grid-lg-1-3 { | |
display: inline-block; | |
float: left; | |
letter-spacing: normal; | |
padding: 0px 10px; | |
vertical-align: top; | |
word-spacing: normal; | |
text-rendering: auto; | |
width: 100%; | |
zoom: 1; | |
} | |
/*Large*/ | |
@media screen and (min-width: 64em){ | |
.grid-lg-1-2 { | |
width: 50%; | |
} | |
.grid-lg-1-3 { | |
width: 33.3333%; | |
} | |
} | |
/*-----------------*/ | |
body { | |
background-color: #fff; | |
color: #000; | |
font-family: Georgia, serif; | |
font-size: 16px; | |
} | |
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 { | |
color: inherit; | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
font-weight: 500; | |
letter-spacing: normal; | |
line-height: 1.1; | |
margin-top: 20px; | |
margin-bottom: 10px; | |
} | |
h1 { | |
font-size: 45px; | |
margin-bottom: 0px; | |
margin-top: 30px; | |
} | |
h1 a { | |
color: #FA4949; | |
} | |
h2 { | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
font-size: 24px; | |
} | |
a { | |
color: #1a0dab; | |
text-decoration: none; | |
} | |
a:hover { | |
text-decoration: underline; | |
} | |
p { | |
margin: 12px 0; | |
line-height: 20px; | |
letter-spacing: normal; | |
} | |
ul { | |
padding: 0; | |
} | |
li { | |
border-bottom: 1px dashed #e0e0e0; | |
line-height: 1.55; | |
list-style-type: none; | |
padding: 7px 0; | |
} | |
kbd { | |
background-color: #eee; | |
color: #000; | |
border-radius: 0; | |
box-shadow: none; | |
font-family: monospace,serif; | |
font-size: 1em; | |
font-weight: bold; | |
padding: 0 4px; | |
} | |
.container { | |
background: #fff; | |
margin: 0 auto; | |
width: 100%; | |
max-width: 1170px; | |
} | |
.well { | |
background: #f8f8f8; | |
border: none; | |
border-radius: 0; | |
-webkit-box-shadow: none; | |
box-shadow: none; | |
min-height: 20px; | |
margin-bottom: 20px; | |
padding: 19px; | |
} | |
.link-to-repo { | |
margin: 20px 0; | |
text-align: center; | |
} | |
.link-to-repo p { | |
margin-bottom: inherit; | |
} | |
.ja { | |
font-size: 13px; | |
} | |
.ja h2 { | |
font-size: 20px; | |
} | |
.ja kbd { | |
font-size: 16px; | |
} | |
.box { | |
background: #f8f8f8; | |
border: 1px solid #E7E7E7; | |
margin: 10px 0; | |
width: 100%; | |
} | |
.box .grid-block { | |
padding: 0 | |
} | |
.box-header { | |
background: #EBEBEB; | |
min-height: 30px; | |
padding: 10px; | |
} | |
.box-header h2{ | |
font-size: 16px; | |
margin: 5px 0; | |
} | |
.box-body { | |
font-size: 14px; | |
display: block; | |
clear: both; | |
overflow: hidden; | |
padding: 0 10px; | |
padding-bottom: 20px; | |
} | |
.box-body li { | |
border-bottom: none; | |
line-height: inherit; | |
list-style-type: none; | |
padding: 7px 7px; | |
} | |
@media print { | |
html, body { | |
height: 90%; | |
} | |
body { | |
line-height: 1.3; | |
font-size: 10px; | |
} | |
h1 { | |
font-size: 20px; | |
margin-left: 0; | |
margin-bottom: 8px; | |
margin-top: 0; | |
} | |
h2 { | |
font-size: 10px; | |
margin-bottom: -10px; | |
margin-top: 0; | |
line-height: 10px; | |
} | |
#footer, .link-to-repo { | |
height: 0px; | |
display: none; | |
} | |
.commands-container { | |
clear: both; | |
overflow: hidden; | |
} | |
.commands-container > .grid-block:first-child { | |
width: 60%; | |
} | |
.commands-container > .grid-block:last-child .grid-lg-1-3 { | |
width: 50%; | |
} | |
.grid-block { | |
clear: none; | |
float: left; | |
display: inline-block; | |
overflow: hidden; | |
width: 40%; | |
} | |
.grid-1 { | |
padding: 0; | |
margin: 0; | |
} | |
.grid-lg-1-3 { | |
display: inline-block; | |
float: left; | |
letter-spacing: normal; | |
padding: 0; | |
word-spacing: normal; | |
text-rendering: auto; | |
width: 33.3333%; | |
zoom: 1; | |
} | |
li { | |
line-height: initial; | |
padding: 4px 5px; | |
} | |
kbd { | |
color: #000; | |
font-size: 12px; | |
padding: 0; | |
} | |
.well { | |
height: 0px; | |
display: none; | |
} | |
} | |
@page { | |
margin: 0.5cm; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment