Home | Projects | Notes > Unix/Linux > Vim Cheat Sheet
xxxxxxxxxx
111* :help keyword - open help for keyword
2* :saveas file - save file as
3* :close - close current pane
4* K - open man page for word under the cursor
5* Ctrl+g - show file name and relevant information
6* :w newfile.txt.backup - create a backup file (still working in newfile.txt)
7* :w newname.txt - write to a different file with newname
8* :r file.txt - read in contents in file.txt and put it to cursor position
9* :version - show the current vim version (:ver)
10* :colorscheme - show the current vim colorscheme
11 - :colorscheme+Tab - loop through selectable colorschemes
xxxxxxxxxx
141[number] verb [number] <noun>
2
3* d2w : [1 time] delete [2] <words>
4* 2dw : [2 times] delete [1] <word>
5* 2d3l : [2 times] delete [3] <characters to the right>
6* 3d2l : [3 times] delete [2] <characters to the right>
7* d6j : [1 time] delete [6] <lines>
8* >l : [1 time] indent [current line]
9* >h : [1 time] indent [current line]
10* >j : indent current line and line below
11* >> : indent current line
12* 2>> : indent 2 lines
13
14[!] Note: above mentioned '> (indent)' logic applies to '< (outdent)' as well
xxxxxxxxxx
581* h - move cursor left (2h - move left two characters)
2* j - move cursor down (2j - move down 2 lines)
3* k - move cursor up
4* l - move cursor right
5* H - move to top of screen (High)
6* M - move to middle of screen (Middle)
7* L - move to bottom of screen (Low)
8* w - jump forwards to the start of a word
9* W - jump forwards to the start of a word (words can contain punctuation)
10* e - jump forwards to the end of a word
11* E - jump forwards to the end of a word (words can contain punctuation)
12* b - jump backwards to the start of a word
13* B - jump backwards to the start of a word (words can contain punctuation)
14* ge - jump backwards to the end of a word
15* % - move to matching character (default supported pairs: '()', '{}', '[]' -
16 use ':h matchpairs' in vim for more info)
17* 0 - jump to the start of the line
18* ^ - jump to the first non-blank character of the line
19* Home - jump to the start of the line
20* $ - jump to the end of the line
21* g_ - jump to the last non-blank character of the line
22* End - jumb to the end of the line
23* gg - go to the first line of the document
24* G - go to the last line of the document
25* Ctrl+Home - go to the first line of the document
26* Ctrl+End - go to the last line of the document
27* 5G - go to line 5
28* :5 - go to line 5
29* fx - FIND the next ocuerrence of character x
30* Fx - FIND the previous occurence of character x
31* tx - jump TO before next occurrence of character x
32* Tx - jump TO after previous occuerence of character x
33* ; - repeat previous f, t, F or T movement
34* , - repeat previous f, t, F or T movement, backwards
35* } - jump to next paragraph (or function/block, when editing code)
36* { - jump to previous paragraph (or function/block, when editing code)
37* Ctrl+e - move screen down on line (without moving cursor)
38* Ctrl+y - move screen up one line (without moving cursor)
39* Ctrl+b - move back one page (full screen)
40* Ctrl+f - move forward one page (full screen)
41* 3+PgUp - go up 3 pages
42* 3+PgDn - go down 3 pages
43* Ctrl+d - move forward 1/2 a screen
44* Ctrl+u - move back 1/2 a screen
45* :set scrolloff=5 - set scroll offset to 5 (lines) - default is 'scrolloff=0'
46* :set scrolloff=999 - set scroll offset to the middle of the screen
47* 50% - move from the top down to the 50% into the file
48* zt - take the current line to the top of the screen
49* zz - take the current line to the center of the screen
50* zb - take the current line to the bottom of the screen
51* g; - go to the last (previous) change
52* g, - go to the next (more recent) change
53* :changes - show all changes made
54* Ctrl+o - go to the previous jump
55* Ctrl+i - go to the next more recent jump
56* :jumps - show all jumps (searches, substitutes, finding marks...)
57 - [!] Note: scrolling through the file, paging or moving cursor
58 up/down are NOT jumps
xxxxxxxxxx
81* i - insert before the cursor
2* I - insert at the beginning of the line
3* a - insert (append) after the cursor
4* A - insert (append) at the end of the line
5* o - append (open) a new line below the current line
6* O - append (open) a new line above the current line
7* ea - insert (append) at the end of the word
8* Esc - exit insert mode
xxxxxxxxxx
241* r - replace a single character
2* J - join line below to the current one without space in between
3* gJ - join line below to the current one with a space in between
4* gwip - reflow paragraph
5* cc - change (replace) entire line
6* C - change (replace) to the end of the line (D+i)
7* C$ - change (replace) to the end of the line
8* ciw - change (replace) entire word
9 - the cut word replaces whatever there was in the default register
10* cw - change (replace) to the end of the word
11* s - delete character and substitue text
12* S - delete line and substitute text (same as cc)
13* xp - transpose two letters (delete and paste)
14* u - undo
15* Ctrl+r - redo
16* . - repeat last command
17* R - enter replace(overwrite text) mode ('backspace' to undo)
18* J - join the line below to the current line (J = 1J = 2J)
19* 3J - join next 2 lines to the current line (4J - ... next 3 lines...)
20* :10,19sort - sort lines from line 10 to 19
21* :10,19sort! - sort lines from line 10 to 19 in reverse order
22* %sort - sort all lines in the current file
23* %sort! - sort all lines in the current file in reverse order
24* :set list - show 'end of line ($)' characters
xxxxxxxxxx
381* Ctrl+a - increment the number by 1
2 - this works as long as the cursor is on the left to the number
3* 5+Ctrl+a - repeat 'Ctrl+a' 5 times (increment the number by 5)
4* Ctrl+x - decrement the number by 1
5 - this works as long as the cursor is on the left to the number
6* g+Ctrl+a - set array indecies in increasing order
7
8 myArray[0] = 0; myArray[0] = 0;
9 myArray[0] = 0; <--- select from here myArray[1] = 0;
10 myArray[0] = 0; myArray[2] = 0;
11 myArray[0] = 0; myArray[3] = 0;
12 myArray[0] = 0; myArray[4] = 0;
13 myArray[0] = 0; ----------> myArray[5] = 0;
14 myArray[0] = 0; myArray[6] = 0;
15 myArray[0] = 0; myArray[7] = 0;
16 myArray[0] = 0; myArray[8] = 0;
17 myArray[0] = 0; myArray[9] = 0;
18 myArray[0] = 0; <--- to here myArray[10] = 0;
19
20* :put =range(10,15) - put range of numbers vertically from the next line of
21 current cursor position
22* :12put =range(10,15) - put range of numbers vertically from the next line of
23 user specified line 12 (which is line 13)
24* :0put =range(10,15) - put rnage of numbers vertically from the beginning of
25 the file
26* :$put =range(10,15) - put rnage of numbers vertically at the bottom of the
27 file
28* :for i in range(115,120) | put = '192.168.0.'.i | endfor
29 - putting sequential IP addresses using for loop
30 - .i means put in the range user specified
31* :%s/^/\=print('%-4d', line('.')) - insert line numbers in the entire file
32 (numbers are left justified)
33 - 's' means substitute
34 - '^' means beginning of the file
35* :%s/^/\=print('%4d', line('.')) - insert numbers right justified
36 - '%4-d' -> '%4d'
37* :%s/^/\=print('%04d', line('.')) - insert numbers right justified and zero
38 filled (leading zeros)
xxxxxxxxxx
251* yy - yank (copy) a line (and save it in memory)
2* Y - yank (copy) a line
3* 2yy - yank (copy) 2 lines
4* y2w - yank (copy) 2 words
5* yw - yank (copy) the characters of the word from the cursor position to the
6 start of the next word
7* yi{ - yank (copy) in curly braces
8* y$ - yank (copy) to end of line
9* p - put (paste) the clipboard after cursor
10* 2p - put (paste) the clipboard after cursor twice
11* P - put (paste) before cursor
12* Ctrl+r " - paste from default register (in insert mode)
13* dd - delete (cut) a line
14* 2dd - delete (cut) 2 lines
15* dw - delete (cut) the characters of the word from the cursor position to
16 the start of the next word
17* D - delete (cut) from the cursor to the end of the line
18* 2D - delete to end of line and the next line
19* dip - delete in paragraph
20* d$ - delete (cut) to the end of the line
21* dt. - delete TO the '.'
22* d/pattern - delete from the cursor to pattern
23* d?pattern - delete from the cursor to pattern backwards (including pattern)
24* x - delete (cut) character
25* :set Paste - pastes text in alignment(not needed on updated versions of vim)
xxxxxxxxxx
391* * - search forwarad for current pattern
2* # - search backward for current pattern
3* /pattern - search for pattern
4* /\cpattern - search for pattern case insensitive
5* /\Cpattern - search for pattern case sensitive
6* /\<pattern\> - search for independent pattern (surrounded by spaces)
7* /\/\* - search for '/*' (escaping special characters)
8* ?pattern - search backward for pattern
9* ?\cpattern - search backward for pattern case insensitive
10* ?\Cpattern - search backward for pattern case sensitive
11* \vpattern - 'very magic' pattern: non-alphanumeric characters are interpreted
12 as special regex symbols (no escaping needed)
13* n - repeat search in same direction
14* N - repeat search in opposite direction
15* :4,7s/old/new - replace all old with new from line 4 to 7
16* :%s/old/new - replace all old with new throughout(%s) file
17* :%s/\<old\>/new - replace all independent old with new throughout(%s) file
18* :%s/old/new/g - ... globally
19* :%s/old/new/gc - ...globally with confirmations (see confirmation msg below)
20 - replace with new (y/n/a/q/l/^E/^Y)?
21 y - yes
22 n - no
23 a - all after current cursor position
24 q - quit
25 l - make this the last change and quit (yq)
26 ^E - scroll down until current cursor position hits top of screen
27 ^Y - scroll up until current cursor position hits bottom of screen
28* :%s/old/new/gic - ...globally with confirmations case insensitive
29* :%s/old/new/gIc - ...globally with confirmations case sensitive
30* :set hlsearch - turn on search highlighting (:set hl)
31* :set nohlsearch - turn off search highlighing (:set nohl, :set noh)
32* :set incsearch - turn on incrememtal search highlighting
33* :set noincsearch - turn off incrememtal search highlighting
34* /[arrow up] - search through forward search history
35* ?[arrow up] - search through backward search history
36* :[arrow up] - search through command history
37* q/ - show forward search history (records are editable)
38* q? - show backward search history (records are editable)
39* q: - show command history (records are editable)
xxxxxxxxxx
3811. ENTER VISUAL MODE
2====================
3
4* Ctrl+v start visual mode, mark lines, then do a command (like y-yank)
5* V start linewise visual mode
6
72. SELECT AREA
8==============
9
10* $ - select to the end of the line
11* aw - mark a word
12* ab - a block with ()
13* aB - a block with {}
14* iw - select current word under cursor
15* i+parenthesis - select everything inside parenthesis (e.g. vi(, vi{, vi[)
16* iB - select everything inside block (curly braces), same as vi{
17* ib - inner block with ()
18* iB - inner block with {}
19
203. TAKE ACTION
21==============
22
23* o - move to other end of marked area
24* I - insert text to the left of visual block
25* A - append to the right of the visual block
26* c - change visual block (delete the block and insert new text to the block)
27* d - delete visual block
28* 0 - move to other corner of block
29* > - shift text right
30* < - shift text left
31* y - yank (copy) marked text
32* d - delete marked text
33* ~ - switch case
34* w - mark to before the start of next word
35* e - mark to the end of a word
36* fed - find and mark to the letter 'e' and delete the marked text
37* fey - find and mark to the letter 'e' and yank the marked text
38* Esc - exit visual mode
xxxxxxxxxx
131* :set list - show invisible characters (^I: Tab, $: end of line)
2* :set expandtab - set to insert spaces instead of tab character
3 - ':set noexpandtab' to unset
4* :set shiftwidth - show current shiftwidth value
5* :set shiftwidth=4 - set shift width to 4 (:set sw=4)
6* :set tabstop - show current tabstop value
7* :set tabstop=4 - set tabstop to 4 (:set ts=4)
8 - if tabstop=8 and shiftwidth=4, tab character will appear
9 when shift happens twice
10* :set softtabstop - show current shofttabstop value
11 - ':set softtabstop=0' use tabstop value as a default
12* :filetype - check to see if vim is detecting file types
13 - [!] Note: for filetype indent setting, see '.vimrc' section
xxxxxxxxxx
81* >> - indent a single line
2* << - outdent a single line
3* 4>> - indent the current line and the 3lines below it
4* 4<< - outdent the current line and the 3lines below it
5* 14== - auto-format 14 lines from the current line
6[!] Note: ':e $VIMRUNTIME/indent' to see the file vim refers to for filetype
7 auto-formatting information (depending on the version, this path may
8 point to a different location
xxxxxxxxxx
51* Tab - indent
2* Ctrl+v u0009 - insert a tab character
3* Ctrl+v Ctrl+i - insert a tab character
4* Backspace - outdent
5[!] Note: to change tab character to a single character, see '.vimrc' section
xxxxxxxxxx
21* (visually selected block) > - indent selected block
2* (visually selected block) = - auto-foramt (auto indent)
xxxxxxxxxx
341little storage places where you can yank text and keep it for later
2(registers we can yank in to are: a - z)
3
4* :register - show registers content (:reg)
5 - ": - special register for the last command user typed
6 - "/ - special register for the path directory
7 - "% - special register for the document name
8 - ". - register for last command
9 - "0 - last yanked register
10 - when an entire line is yanked, '^j' character is appended at
11 the end of the yanked line in the register
12 - "" - default register
13 - "- - register for the last deleted text (dash/hyphen register)
14 - when an entire line is deleted, it is saved in both '""' and
15 '"1' registers. numbered registers will keep bumped down and
16 down until it gets to '"9' (there's no '"10' register so
17 after '"9' register, it will be lost)
18 - "a - user specified register 'a'
19 [!] Note: when we yank text, it is saved in both '"0' and '""'
20* "/p a Ctrl+r % Ctrl+r : - print 'dir', 'doc name', 'last command'
21* "ay - yank into register a (each letter on the keyboard corresponds to
22 different registers)
23* "ayiw - yank in word to register 'a' (as well as to the default register)
24* "ap - paste contents of register 'a'
25* Ctrl+r " - paste from default register (in insert mode)
26* Ctrl+r a - paste contents of register 'a' (in insert mode)
27* Ctrl+r Ay - append and yank into register 'a'
28* ciw - change (replace) entire word
29 - the cut word replaces whatever there was in the default register
30 - 'Ctrl+r a' will replace the original word with the contents of reg 'a'
31* to clear all the registers???
32[!] Note: registers are being stored in ~/.viminfo, and will be loaded again on
33 next restart of vim.
34[!] Note: Register 0 contains always the value of the last yank command.
xxxxxxxxxx
211bookmarks
2
3* :marks - list of marks
4* ma - set current position for mark 'a'
5* `a - jump to the position of mark 'a' in the line marked
6* 'a - jump to line with mark 'a' (NOT to the position where mark was placed)
7* y`a - yank text to position of mark 'a'
8* [' - jump to the previous mark line
9* ]' - jump to the next mark line
10* [` - jump to the previous mark
11* ]` - jump to the next mark
12* d'a - delete to the line with mark 'a'
13* y'a - yank (copy) from cursor to the mark 'a' (then bring cursor to the top
14 of the selection / '] to go to the bottom of the selection)
15* mA - set current position for mark 'A' (uppercase works the same way as the
16 lower case works as long as you are in the same file, mark with
17 uppercase can be referenced from a different file)
18* (in another file) 'A - open file and go to the mark 'A'
19* :delmarks a,A,C - delete marks 'a', 'A', 'C'
20* :delmarks A-Z - delete marks from 'A' to 'Z'
21* :delmarks! - delete all marks
xxxxxxxxxx
91vim macro feature allows you to record and play a sequence of actions inside of
2the vim editor (macros are stored in registers a-z)
3
4* qa - start recording a macro into the register 'a'
5* q - stop recording macro
6* @a - run macro stored in the register 'a'
7* 3@a - run macro stored in the register 'a' 3 times
8* @@ - return last run macro
9* :let @b='05^Xj' - setting '5Ctrl+x' to macro(register) 'b'
xxxxxxxxxx
61* :w - write (save) the file, but don't exit
2* :w !sudo tee % - write out the current file using sudo
3* :wq - write (save) and quit (:x, ZZ)
4* :q - quit (fails if there are unsaved changes)
5* :q! - quit and throw away unsaved changes (ZQ)
6* wqa - write (save) and quit on all tabs
xxxxxxxxxx
121
2* :vimgrep /pattern/ {`{file}`} - search for pattern in multiple files
3 (e.g. :vimrgrep /foo/ ??/?)
4* cn - jump to the next match
5* cp - jump to the previous match
6* copen - open a window containing the list of matches
7* :e file - edit a file in a new buffer
8* :bnext - go to the next buffer (:bn)
9* :bprev - go to the previous buffer (:bp)
10* :bd - delete a buffer (close a file)
11* :ls - list all open buffers
12* :r file - read file content (insert text content of file below the cursor)
xxxxxxxxxx
341* :split - split window horizontally (:new, :sp)
2* :vsplit - split window vertically (:vnew, :vsp)
3* :sp file - open a file in a new buffer and split window
4* :vsp file - open a file in a new buffer and vertically split window
5* :set splitright - set to make the split show up on the right
6* :enew - open new file in the current window
7* Ctrl+w s - split window
8* Ctrl+w v - split window vertically
9* Ctrl+w w - switch windows
10* Ctrl+w x - swap window position
11* Ctrl+w r - rotate windows
12* Ctrl+w R - rotate windows in opposite direction
13* Ctrl+w t - go to the top left window
14* Ctrl+w b - go to the bottom right window
15* Ctrl+w p - go to the previous window
16* Ctrl+w o - show only the active window (others still remain in buffer)
17* :ba - bring all buffers to split windows (horizontal)
18* :vert ba - bring all buffers to split windows (vertical)
19* :vert 3ba - show all buffers up to buffer 3 (vertical)
20* :vsp | b3 - split buffer 3 (vertical)
21 - if '|' is omitted, vim will try to split and open a file named b3
22* Ctrl+w q - quit a window
23* Ctrl+w h - move cursor to the left window (vertical split)
24* Ctrl+w l - move cursor to the right window (vertical split)
25* Ctrl+w j - move cursor to the window below (horizontal split)
26* Ctrl+w k - move cursor to the window above (horizontal split)
27* :resize 20 - resize the current window to 20 (horizontal)
28* :resize -5 - downsize 5 the current window (horizontal)
29* :vertical resize 80 - resize thecurrent window to 80 (vertical)
30* :vertical resize +25 - resize +25 the current window (vertical)
31* Ctrl+w = - make all windows the same size
32* Ctrl+w _ - max current window height
33* Ctrl+w | - max current window width
34* :help ctrl-w - show everything you can do with 'Ctrl+w'
xxxxxxxxxx
171piece of memory in RAM
2
3* :buffers - show all buffer info (:ls)
4 - %a currently active buffer
5 - # alternate buffer (where you just came from)
6 - h hidden buffer
7 - + buffer has unsaved changes
8* :e filename.txt - open up 'filename.txt' (will be added to 'buffers' list)
9* :bp - buffer previous (':bp!' force command)
10* :bn - buffer next
11* :set hidden - hide buffer (hidden setting applies to all files in buffer)
12 - ':set nohidden' to unset
13* b4 - jump to buffer 4
14* Ctrl+6 - toggle back and forth between the current and alternate buffers
15* Ctrl+^ - toggle back and forth between the current and alternate buffers
16* :bd - delete this buffer
17* e! - remove all the changes since the last save
xxxxxxxxxx
291* :tabeddit filename.txt - open and eddit a file in a new tab (:tabe)
2 - same file can be opened in multiple tabs
3* :tabnew or :tabnew {page.words.file} - open a file in a new tab
4* :tabnext - go to the next tab (to the right and loop around) (:tabn, :gt)
5* :3gt - go 3 tabs right
6* Ctrl+PgUp - go to the next tab
7* :tabnext 3 - go to the right 3 tabs
8* :tabprev - go to the previous tab (to the left and loop around) (:tabp, :gT)
9* :3gT - go 3 tabs left
10* Ctrl+PgDn - go to tne previous tab
11* Ctrl+wT - move the current split window into its own tab
12* :tab split - split a window into a new tab (without removing the original)
13* :tabmove # - move current tab to the #th position (indexed from 0) (:tabm #)
14* :tabm - move current tab to the far right
15* :tab 0 - move current tab to the far left
16* :w newname.txt - name the file and save
17* :tabclose - close the current tab and all its windows (:tabc)
18 - but they still remain in buffer
19* :tabclose 3 - close the tab 3
20* :tab ball - open all buffers each in its own tab
21* :set tabpagemax=9 - set tab page max value to 9
22* :tabonly - close all tabs except for the current one (:tabo)
23* :drop file.txt - drop the current file and open file.txt in the current tab
24 - if file.txt is already open in one of the tabs, current file
25 does not drop and it just goes to the file.txt tab
26* :tabdo command - run the command on all tabs (e.g. :tabdo q - closes all
27 opened tabs)
28[!] Note: when a tab contains multiple split windows, the tab name will change
29 depending on selected window
xxxxxxxxxx
111* :set wrap - word wrap
2* :set linebreak - break lines at words
3* :set cursorline - highlight current line
4* :set colorcolumn=x - show vertical line where 'x' is the column number
5* :set list - show all whitespaces
6* :set textwidth=x - automatic word wrapping (text wraps automatically as you
7 type, in order to make each line long 'x' characters at most)
8* :set number (:set nu)
9* :set nonumber (:set nonu)
10* :set relativenumber (:set rnu)
11* :set norelativenumber(:set nornu)
xxxxxxxxxx
591the way of hiding text from view
2
3* :set foldmethod - show current foldmethod (:set fdm)
4 - 'manual' is default and most popular (folds must be defined
5 by entering commands; like 'zf')
6 - 'indent' creates a fold for each indent
7 - 'syntax' creates a fold by the syntax of a programming
8 language
9 - 'expr' folds are created by a user-defined expression (like
10 a regex / regular expression)
11 - 'marker' creates folds for start and end characters a user
12 defines
13 - 'diff' is used to fold unchanged text when viewing
14 differences (automatically set in diff mode)
15
16FOLDMODE=MANUAL
17===============
18
19* (visually select text block) zf - create a fold
20* zf10j - fold up current line + next 10 lines
21* zf10k - fold up current line + prev 10 lines
22* :148,158fold - fold the designated scope of lines
23 (:148,158 fold, :148,158 fo)
24* :,+10 fo - fold current line + next 10 lines
25* :,-10 fo - fold current line + prev 10 lines
26* :zfa{ - create a fold between { and } (line wise)
27* zo - open up a fold
28* zO - open the fold and all the nested folds
29* zn - open up all folds
30* :86, 136 foldopen - open up folds located in lines 86 ~ 136
31 - to retrieve the last line of the file 'Ctrl+g'
32* :86, 136 foldclose - close folds located in lines 86 ~ 136
33* :% foldopen - open up all the folds in current file ('%' means 'everything')
34* :% foldclose - close all the folds in current file ('%' means 'everything')
35* zN - set all folds as they were before executing zn command
36* zj - go to the next fold
37* zk - go to the prev fold (last line of the previous fold)
38* [z - go to the top of the current fold
39* ]z - go to the bottom of the current fold
40* zc - close fold
41* zd - delete fold
42* zC - close this fold and all folds it is nested in
43* zA - toggle between zC and zO
44* zE - eliminate all folds from the curent file
45* :mkview - save a fold (saved folds goes to '~/.vim/vim')
46 - vim does not remember unsaved folds
47* :loadview - load the saved views
48 - saved views must be loaded to show up
49[!] Note: make this process easier by adding commands to .vimrc
50
51
52FOLDMODE=INDENT
53===============
54
55* :set fdm=indent - fold up all indented texts
56* zr - reduce all folds one level (same as 'zo' for all the nested folds)
57* zR - reduce all folds in the file
58* zm - fold up all folds one level (same as 'zc' for all folds)
59* zM - fold up all folds all the way (same as 'zC' for all folds)
Built in vim v7.0 or higher
xxxxxxxxxx
811* vim [directory] - open the directory with vim's built in file explorer
2 plugin('NetRW') and show what is in that directory
3* vim . - go to the file explorer in the current directory
4 - vim's file explorer shows hidden files by default (can hide them)
5* /[file/directory] - find file or directory in vim's file explorer
6* - - go up one directory level (or hit enter on '../')
7* :q - quit out of the file explorer
8* D - delete a file or directory with confirmation
9* R - rename a file or directory
10* s - sort files or directories
11* x - open the file with linux's default text editor
12* % - create a file
13* d - crate a directory
14* gh - hide hidden files ('Hiding' will appear on the header)
15 - 'gh' again will toggle the hidden files back on
16* I - hide the header
17 - 'I' again will toggle the header back on
18* o - open the file in a split window (new split window is placed on the top,
19 cursor is in that window)
20* v - open the file in a vertial split window (new split window is placed on
21 the left, cursor is in that window)
22 that window)
23* :let g:netrw altv=1 - set to open the split to the right
24* p - preview the file (cursor stays on explorer window, 'Ctrl+w w' to go to
25 the preview window)
26* Vex - split back into the vertical explorer window
27* Sex - split back into the horizontal explorer window
28
29HEADER INFO
30===========
31
32* Netwr Directory Listing (netrw v156)
33 - NetRW plugin version info
34* /home/kyungjae-lee/linux
35 - current working directory
36* Sorted by
37 - how the directory is sorted (hit 'enter' on the line or hit 's' anywhere
38 in the file explorer to change)
39 - name
40 - size
41 - exten(sion)
42* Sort sequence
43 - hit 'enter' on the line or hit 'S' anywhere in the file explorer to edit
44 the sequence
45* Quick Help
46 - hit 'enter' on the line and the quick help menu will loop around
47 - also can enter Quick Help by executing ':help quickhelp'
48
49COPY and MOVE
50=============
51copy a file or group of files from the current directory to another
52
531. mark the target directory
54 - put cursor to the target directory-to-bo and
55 - mt
56 - 'Copy/Move Tgt:' will newly appear on the file explorer header
57
582. mark a file or files to copy
59 - mf (make sure the file name is bold or highlighted)
60
613. copy the files
62 - mc (if successful, prviously highlighted file names will no longer be
63 highlighted)
64
65NetRW FIX FUZZY FIND
66====================
67* vim - enter vim
68
69* r filename.txt - read in filename.txt
70* e filename.txt - edit a filename.txt
71* :find filename.txt - find a 'filename.txt' (subfolder that the target file is
72 located must be specified! to fix this see ':set path')
73* :set path - show fuzzy search path (to make NetRW search all subdirectories and
74 recursively, see '.vimrc' section)
75 - ',' is a separator
76* (after editing the 'path') find filename.txt - search filename.txt through
77 all paths, spoting one by one as user hits 'Tab' key
78* (when 'wildmenu' is set) find filename.txt + Enter - enter the first file
79 that matches.
80* (when 'wildmenu' is set) find filename.txt + Tab - loop though all the files
81 that match. hit 'Enter' key to enter the target file.
xxxxxxxxxx
131vim's built-in command for searching across multiple files
2
3* :vimgrep /pattern/g % - search 'pattern' only in this open buffer(%)
4 (:vim /pattern/g %)
5* :vimgrep /pattern/g **/* - search 'pattern' through the entire project dir.
6 - '.vimrc' must be updated for this to work. (see
7 'set path' in '.vimrc' section)
8* :cope - (c open) show search result as a list (j, k to navigte, 'Enter' to go
9 to the occurrence) (:cw)
10* :cnext - go to the next match
11* :cprev - go to the previous match
12* :cfirst - go to the first match
13* :clast - go to the last match
xxxxxxxxxx
21* :help - to the main 'help' screen
2* :help [command] - to the '[command]' section of the 'help' screen
xxxxxxxxxx
51download plugins under the path '~/.vim/pluginname'
2 - make '~/.vim' directory if you don't have one
3 - it's good to make designated 'pluginname' directory for each plugin
4 (as long as '.vimrc' points to the right directory, there won't be any
5 problems running plugins)
xxxxxxxxxx
1511. download 'badwikf-master.zip' from http://github.com/sjl/badwolf
22. mkdir ~/.vim/color
3 - 'color' is user designated plugin directory name
43. cd ~/.vim/color
54. mv ~/Downloads/badwolf-master.zip .
65. unzip badwolf-master.zip
76. ls -lah
8 - check if the unzip was successfully done
97. cd ~
108. vim .vimrc
11 - set runtimepath^=~/.vim/color/badwolf-master
129. :wq vim and re-enter so that vim applies the new updates
1310. :colorscheme badwolf
14 - badwolf color scheme is working!
1511. to undo this color scheme change, comment out '9.', :wq and re-enter vim
xxxxxxxxxx
491https://vimawesome.com
2some examples of plugin manager
3 - Vundle
4 - NeoBundle
5 - VimPlug
6 - Pathogen
7
8VimPlug Manager
9~~~~~~~~~~~~~~~
10
111. download VimPlug manager from https://github.com/junegunn/vim-plug
122. mkdir ~/.vim/autoload
13 - 'autoload' is a special directory for vim. it's meant to delay loading
14 the code until it's actually needed. this is to keep vim running fast.
153. cd .vim/autoload
164. mv ~/Downloads/vim-plug-master.zip .
175. ls -lah
186. unzip vim-plug-master.zip
197. mv vim-plug-master/plug.vim .
208. cd (cd~)
219. vim .vimrc
22 - call plug#begin('~/.vim/plugged')
23 - 'call' is telling vim to look in the .vim/autoload directory for the
24 .vim file called 'plug'
25 - '~/.vim/plugged' does not exist yet but vim will take care of it and
26 this is where VimPlug will place the installed plugins
27 - call plug#end()
2810. go to https://vimawesome.com
29 - go to Syntastic plugin
30 - go to VimPlug
31 - copy 'Plug ...' into .vimrc (between 'call plug#begin' and 'plug#end')
3211. add a few more lines to .vimrc for Perl script (it is found that without
33 following lines, perl script errors were not being detected correctly)
34 - let g:syntastic_check_on_open = 1
35 - let g:syntastic_check_on_wq = 0
36 - let g:syntastic_enable_perl_checker = 1
37 - let g:syntastic_perl_checkers = [perl', 'podchecker']
38 [!] Note: above lines of code simply means turning on the perl checker and
39 telling syntastic what checker user wants to use
4011. source .vimrc
41 - it means to :wq and enter back in the .vimrc
4212. :PlugInstall
43 - install the plugin
4413. quit out of plugins window, quit out of .vimrc
45
46[!] Note: to clear the plugin,
47 - go to .vimrc and comment out everything but the ones we wrote at '9.'
48 - :PlugClean
49 - this actually removes the plugin with confirmation
xxxxxxxxxx
311vim's file compare feature that allows users to see the difference between 2 or
23 files
3
4* vimdiff file1.txt file2.txt
5 - open 'file1' to the left, 'file2' to the right
6 - highlight the differences between the two
7* :quitall - quit from both of the files (:qa)
8* vimdiff -o file1.txt file2.txt
9 - open 'file1' on the top, 'file2' on the bottom
10 (open one 'o'ver the other)
11* vim -d -o file1.txt file2.txt
12 - same as 'vimdiff -o file1.txt file2.txt'
13 - same as 'vim -do file.txt file2.txt'
14* :set noscrollbind
15 - the file with this command ran scrolls independently
16 - when the cursor is on the other file where this command has not yet been
17 run, both sides will scroll together
18* ]c - jump to the next change(difference)
19* [c - jump to the previous change(difference)
20* (cursor on the left file) :diffget
21 - :do - meaning diff obtain
22 - bring the line on the file right into the file on the left
23* (cursor on the left file) :diffput
24 - :dp - meaning diff put
25 - bring the line on the file left into the file on the right
26* (cursor on the file that the change was made to) u - undo
27 - notice that when you undo ':diffget' that specific difference is not
28 flagged anymore!
29 - rescanning needs to be done to detect it again!
30* :diffupdate
31 - rescan the difference
xxxxxxxxxx
1591* " - comment out
2* set nu
3 - set number (can be toggled by entering ':set nu!' multiple times)
4* set nonu
5 - set nonumber
6
7MAPPING
8=======
9
10* nmap <F3> :set nu! <CR>
11 - first 'n' stands for 'normal mode'
12 - map F3 to toggle on and off the line numbers in normal mode
13 - if there happen to be space after <CR>, cursor will move everytime the
14 comand is executed.
15* let mapleader = ','
16 - map <leader> key to comma
17 - unless otherwise specified, default <leader> is '\'
18* nmap <leader><F3> :set rnu! <CR>
19 - map <leader>F3 to toggle on and off the 'relative line numbers in normal
20 mode
21* imap <F3> <ESC> :set nu! <CR>i
22 - first 'i' stands for 'insert mode'
23 - map F3 to toggle on and off the line numbers in insert mode
24 - it has to go to the 'normal mode' first and then return to 'insert
25 mode' at the end
26* imap <F4> <ESC> :set rnu! <CR>i
27 - map F4 to toggle on and off the 'relative line numbers in insert
28 mode
29
30Re Assign Arrow Keys to No OPeration (in insert mode too)
31~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32You can set a key to no operation!
33(no remap means the keys are not allowed to be mapped afterwards)
34
35* nnoremap <Up> <Nop>
36* nnoremap <Down> <Nop>
37* nnoremap <Left> <Nop>
38* nnoremap <Right> <Nop>
39* inoremap <Up> <Nop>
40* inoremap <Down> <Nop>
41* inoremap <Left> <Nop>
42* inoremap <Right> <Nop>
43
44AUTOCORRECT DICTIONARY
45======================
46
47* abbr ture true
48* abbr flase false
49* abbr emailF kjxlee@gmail.com
50
51SET DEFAULT SEARCH HIGHLIGHTING ON
52==================================
53
54* set hlsearch (to set off ':set nohsearch')
55* set incsearch (to set off ':set noincsearch')
56
57UPDATING TAB AND END OF LINE CHARACTER
58======================================
59
60* set listchars=tab:→\ , eol:↲
61 - update the tab character to '→ unicode u2192'
62 - update the end of line character to '↲ unicode u21b2'
63
64FILETYPE INDENT
65===============
66
67* filetype indent on
68 - turn on filetype indent
69* autocmd Filetype perl setlocal noexpandtab tabstop=4 sw=4 sts=4
70 - change tab settings for perl programs
71
72TEXT FOLDING
73============
74lines to save text folding
75
76* autocmd BufWinLeave *.* mkview
77* autocmd BufWinEnter *.* loadview
78
79NETRW SETTING
80=============
81
82* nmap <F4> gh
83 - map F5 to toggle on and off the line numbers in normal mode
84
85* let ghregex='\(^\|\s\S\)\zs\.\S\+'
86 let g:netrw_list_hide=ghregex
87 - hide the dot files one startup
88
89* nmap <F6> I
90 - map F6 to toggle on and off the header (banner)
91
92* let g:netrw_banner=0
93 - turn off the header at the top of the screen on startup
94
95* let g:netrw liststyle= 0
96 - default view (directory name / file name)
97
98* let g:netrw liststyle= 1
99 - show time and size
100
101* let g:netrw liststyle= 2
102 - show listing in 2 columns
103
104* let g:netrw liststyle= 3
105 - show the tree listing
106
107* let g:netrw_winsize=0
108 - set default window size to be always equal
109
110* let g:netrw_preview=1
111 - open splits to the right
112
113FIX FUZZY FIND
114~~~~~~~~~~~~~~
115
116* autocmd FileType netrw setl bufhidden=delete (or use ':qa!')
117 - per default, netrw leaves unmodified buffers open. this autocommand
118 deletes netrw's buffer once it's hidden (using ':q;, for example)
119* set nocompatible - limit search to your project
120* set path+=** - search all subdirectories and recursively
121* set wildmenu - shows multiple matches on one line
122
123COLOR SHCEME
124============
125see 'PLUGIN' -> 'EXAMPLE' section!
126
127* colorscheme pablo
128 - use pablo colorscheme
129
130TEXTWRAP
131========
132* set textwidth=80
133
134[!] Note: if this command doesn't seemt to work,
135
1361. check 'formatoptions' option. it requires 't' (Vim default: tcq)
1372. check if 'paste' option is switched on (to switch it off 'set nopaste')
138 - when the 'paste' option is switched on (also when it was already on):
139 - mapping in Insert mode and Command-line mode is disabled
140 - abbreviations are disabled
141 - 'autoindent' is reset
142 - 'expandtab' is reset
143 - 'formatoptions' is used like it is empty
144 - 'revins' is reset
145 - 'ruler' is reset
146 - 'showmatch' is reset
147 - 'smartindent' is reset
148 - 'smarttab' is reset
149 - 'softtabstop' is set to 0
150 - 'textwidth' is set to 0
151 - 'wrapmargin' is set to 0
152 These options keep their value, but their effect is disabled:
153 - 'cindent'
154 - 'indentexpr'
155 - 'lisp'
1563. run ':verbose set fo' to check which file the 'formatoptions' option is
157 most recently set from.
158 - remove the cause of unintentional behavior and set 'formatoptions=tcq' if
159 necessary in your .vimrc file.