Skip to content

Latest commit

 

History

History
254 lines (218 loc) · 10.4 KB

vim_cheat_sheet.md

File metadata and controls

254 lines (218 loc) · 10.4 KB

iota2

Making Imaginations, Real

i2.iotasquare@gmail.com

 ██╗ ██████╗ ████████╗ █████╗ ██████╗
 ██║██╔═══██╗╚══██╔══╝██╔══██╗╚════██╗
 ██║██║   ██║   ██║   ███████║ █████╔╝
 ██║██║   ██║   ██║   ██╔══██║██╔═══╝
 ██║╚██████╔╝   ██║   ██║  ██║███████╗
 ╚═╝ ╚═════╝    ╚═╝   ╚═╝  ╚═╝╚══════╝

BSD licensed

VIM Cheat Sheet

INSERT Mode

Commands Description
i Insert at the cursor
a Insert after the cursor
A [APPEND] Insert at the end of line
o Insert a new line after the current one
O Insert a new line before the current one

CONTROL Commands

Commands Description
:w Save the file
:q Quit and exit the file
:wq Save and exit the file
q! Exit without saving
:saveas <path> Save the file to <path>

MOVE Across Columns

Commands Description
<n> h Equivalent to arrow move left [for n number of moves]
<n> j Equivalent to arrow move down [for n number of moves]
<n> k Equivalent to arrow move up [for n number of moves]
<n> l Equivalent to arrow move right [for n number of moves]
O Goto first column / beginning of line
^ Goto first non-blank character of line
$ Goto the end of line
g_ Goto last non-blank character of line

MOVE Across Line

Commands Description
f a Goto next occurrence of character a in current line
t a Go before next occurrence of character a in current line
, Goto NEXT occurrence of result of f / t
; Goto PREVIOUS result from f / t

MOVE Across word/WORD

words are composed of letters and underscore character. lets call a WORD, a group of letters separated by blank characters

Commands Description
w Goto start of next word
W Goto start of next WORD
e Goto end of current word
E Goto end of current WORD
* Goto NEXT occurrence of word under cursor
# Goto PREVIOUS occurrence of word under cursor

MOVE Across File

Commands Description
<n> G Goto line number n
G Goto last line for the file
gg Goto start of the file [Equivalent to 1G]
% Match Bracket at cursor
[ctrl + o] Jump back
[ctrl + i] Jump forward

MOVE Across Panes

Commands Description
[ctrl + h] Navigate to horizontally left pane
[ctrl + j] Navigate to vertically lower pane
[ctrl + k] Navigate to vertically upper pane
[ctrl + l] Navigate to horizontally right pane
[ctrl + w] Move across panes
[ctrl + w=] Make the pane sizes equal

SPLIT Layout

Commands Description
:sp <filename> Vertical Split : Open file below current file
:vs <filename> Horizontal Split : Open file to right of current file

CUT-COPY-PASTE

Commands Description
<n> d delete n characters
<n> y Yank / Copy n characters
p Paste
<n> dd Delete & copy n line including current
<n> yy Copy n lines including current
<n> u UNDO n number of times
<n> [ctrl+r] REDO n number of times

AUTO-COMPLETE

These commands will work in insert mode.

Commands Description
[ctrl + p] Displays auto-complete suggestions
[ctrl + n] Displays auto-complete suggestions

SEARCH

Commands Description
/pattern Search for occurrence of pattern in file
n Goto NEXT occurrence o searched pattern
[shift + n] Goto PREVIOUS occurrence of searched pattern

FIND-AND-REPLACE

Commands Description
:s/xxx/yyy/ Replace xxx with yyy at the first occurrence
:s/xxx/yyy/g Replace xxx with yyy global (whole sentence)
:s/xxx/yyy/gc Replace xxx with yyy global with confirm
:%s/xxx/yyy/g Replace xxx with yyy global in the whole file

COMBINATIONS

<start_position> <command> <end_position>

Examples:

  1. Oy$
    • O : Goto beginning of current line
    • y : Yank from here
    • $ : Up-to end of current line
  2. ye : Yank from here to end of the word
  3. y2/foo : Yank up-to 2nd occurrence of foo
  4. dt" : Remove everything until "

What was true for yank y, is also true for othe commands like delete d, visual select v, uppercase gU, lowercase gu etc.

ZONE Selection

<action> a <object>
<action> i <object>

Action can be delete d, yank y, or visual v. And an object can be word, extended WORD, sentence S, paragraph p or natural characters like " ' ) } ].

Example: Suppose the cursor is at first o of the following line:

(map (+) ("foo"))
Commands Selected outcome
vi" foo
va" "foo"
vi) "foo"
va) ("foo")
v2i) map (+) ("foo")
v2a) (map (+) ("foo"))

BLOCK Selection

Enter Visual-Mode: [ctrl + v]

Examples:

  1. Write at beginning of selected block (lines): ^ [ctrl + v] 9 [ctrl + d] I > ESC

    • ^ : Goto first non-blank character of line.
    • [ctrl + v] : Start block selection.
    • 9 [ctrl + d] : Move down 9 lines.
    • I : Enter insert mode.
    • > : Write character > at cursor (beginning of line).
    • ESC : Exit insert mode, writing > to all selected lines.
  2. Write at end of selected lines: [ctrl + v] 9 [ctrl + d] $ A , ESC

    • [ctrl + v] : Start block selection.
    • 9 [ctrl + d] : Move down 9 lines.
    • $ : Goto end of the line.
    • A : Enter append mode.
    • , : Write text , at cursor (End of line).
    • ESC : Exit append mode, writing , to all selected lines.

PLUG-IN Shortcuts

CtrlP Commands Description
[ctrl + p] Open files pane
:vs Open highlighted file in horizontal split
:sp Open highlighted file in vertical split
[ctrl + x] Open highlighted file in horizontal split
[ctrl + v] Open highlighted file in vertical split
[ctrl + b] CtrlP MRU buffer list
[ctrl + f] CtrlP function matching
Tagbar Commands Description
F8 Toggle Tagbar
:TagbarToggle Toggle Tagbar
NerdTree Commands Description
" Open Nerd-Tree pane
s Open highlighted file in vertical split
i Open highlighted file in horizontal split
ctags Commands Description
:ctags -R ! Generate tags file for project
\c Call ctags on project
:ta Navigate list of tags
[ctrl + ]] Navigate via tags to item under cursor
[ctrl + t] Navigate back after jumping with ctags
YCM Commands Description
\g :YcmCompleter GoTo
\d :YcmCompleter GoToDefinition

Misc

Commands Description
u Convert selection (visual mode) to lowercase
U Convert selection (visual mode) to uppercase
~ Swap case
[ctrl + a] Increment the number at cursor
ga Show ASCII of char under cursor
<n> > Indent Right n number of times
<n> < Indent left n number of times

License

GNU GPU v3
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Free Software, Hell Yeah!