Sunday 9 March 2014

Vim Cheatsheet

This is awesome editor. Enough Said. So, here is the cheatsheet

Command            What it does
--------------------------------------------------------------------------------
:q                        Quit (no saving)
:wq                     Save and quit
j                          Move one line down
k                         Move one line up
l                          Move to the next alphabet
h                         Move to the previous alphabet
x                         Delete unwanted character
i                          Insert text
dw                      Delete word
d$                       Delete from current cursor position to end of line
de                       Delete word till end of word
w                        Move onto next word
e                         Move onto next word's end alphabet
0                         Move to beginning of line
$                         Move to end of line
dd                       Delete a line
u                         Undo recent change
U(capital u)        Undo everything on that line
CTRL-r               Redo recent change
p                         Put deleted text after cursor (the entire thing)
r<new char>     Replace character at current cursor position with specified character
ce                       Change characters until the end of the word
Ctrl-g                 Show line number and file status
G                        Go to end of file
gg                      Go to beginning of file
<line number>  Ctrl-g    Go to specified line number
/<word>            Search for specified word in forward direction
?<word>           Search for specified word in backward direction
n                        Search previous word for next hit in forward direction
N                       Search previous word for next hit in backward direction
Ctrl-o(Oh)          To go back where you came from
Ctrl-i                  To go forward
%                       To search for matching parenthesis (place cursor on parenthesis first)
:s/old/new           Substitute 'old' word with 'new' word (only first occurence of 'old' word)
:!<command>    Execute specified command
:w <Filename>   Save opened file with specified filename
v motion :w <filename>    By pressing 'v' we enter visual mode which selects all text with motion such as move down
:r <filename>     Place the text from specified filename below the current cursor position
o                         Place text below cursor position
O(capital o)        Place text above cursor position
a                         Append Text
A                        Insert text after the end of the line
R(capital r)        Replace all characters until <ESC> is pressed
y                         Yank (copy) selected text. Use after entering visual mode
:set ic                  Ignore case for all searches (Use after search command)
:set hls is            Highlight matching text for all searches (Use after search command)
:set noic             Disable ignore case for all searches (Use after search command)
:nohlsearch        Disable highlighting text for all searches (Use after search command)
<HELP>, <F1>, :help    To get help
Ctrl-w Ctrl-w       To jump from one window to another
:e <filename>     Open filename for editing
:set nocp             Disable compatible mode
Ctrl-d                   Show a list of available commands starting with the specified character (Enter a character first), press repeatedly for autocompletion of command (Do :set nocp first)

<TAB>            Autocomplete command or filename (Do :set nocp first)

Note:
You can use the following formats for these commands:
    <times> command
like
    3w        -    Move three words forwards
    2e        -    Move two words forward on the end character
    d3w        -    Delete three words
    2dd        -    Delete two lines
    c$        -    Change till end of line
    c3w        -    Change from beginning of line till beginning of fourth word
    4G        -    Move to fourth line from top
    :s/old/new/g    -    Substitute 'old' word with 'new' word (for every occurence of the 'old' word in the file)

    :#,#s/old/new/g -    #,# are line numbers within which to change 'old' word with 'new' word

    :%s/old/new/g    -    Change 'old' word with 'new' word in entire file
    :%s/old/new/gc  -    Change 'old' word with 'new' word in entire file but prompt first

    :!ls        -    See contents of present working directory
    :!rm <filename>    -    Delete specified filename
    :r !ls        -    Write contents of directory below current cursor position
    j$        -    Move to end of line
    /<text>\c    -    Search for specified text while ignoring case just for this search
    :help <argument> -    Get help on the specified argument


If you want to download it, here you go.

This covers the terminal based vim and not GVim, and also does not cover buffer management  and other commands. These commands should also work on GVim.

As Always thanks for reading and please comment.

No comments:

Post a Comment

Stuff that most try to do