Skip to content

Instantly share code, notes, and snippets.

@nzajt
Forked from m3nd3s/NERDTree.mkd
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nzajt/8845365 to your computer and use it in GitHub Desktop.
Save nzajt/8845365 to your computer and use it in GitHub Desktop.

NERDTree

o.......Open files, directories and bookmarks....................|NERDTree-o|
go......Open selected file, but leave cursor in the NERDTree.....|NERDTree-go|
t.......Open selected node/bookmark in a new tab.................|NERDTree-t|
T.......Same as 't' but keep the focus on the current tab........|NERDTree-T|
i.......Open selected file in a split window.....................|NERDTree-i|
gi......Same as i, but leave the cursor on the NERDTree..........|NERDTree-gi|
s.......Open selected file in a new vsplit.......................|NERDTree-s|
gs......Same as s, but leave the cursor on the NERDTree..........|NERDTree-gs|
O.......Recursively open the selected directory..................|NERDTree-O|
x.......Close the current nodes parent...........................|NERDTree-x|
X.......Recursively close all children of the current node.......|NERDTree-X|
e.......Edit the current dif.....................................|NERDTree-e|

<CR>...............same as |NERDTree-o|.
double-click.......same as the |NERDTree-o| map.
middle-click.......same as |NERDTree-i| for files, same as
                  |NERDTree-e| for dirs.

D.......Delete the current bookmark .............................|NERDTree-D|

P.......Jump to the root node....................................|NERDTree-P|
p.......Jump to current nodes parent.............................|NERDTree-p|
K.......Jump up inside directories at the current tree depth.....|NERDTree-K|
J.......Jump down inside directories at the current tree depth...|NERDTree-J|
<C-J>...Jump down to the next sibling of the current directory...|NERDTree-C-J|
<C-K>...Jump up to the previous sibling of the current directory.|NERDTree-C-K|

C.......Change the tree root to the selected dir.................|NERDTree-C|
u.......Move the tree root up one directory......................|NERDTree-u|
U.......Same as 'u' except the old root node is left open........|NERDTree-U|
r.......Recursively refresh the current directory................|NERDTree-r|
R.......Recursively refresh the current root.....................|NERDTree-R|
m.......Display the NERD tree menu...............................|NERDTree-m|
cd......Change the CWD to the dir of the selected node...........|NERDTree-cd|

I.......Toggle whether hidden files displayed....................|NERDTree-I|
f.......Toggle whether the file filters are used.................|NERDTree-f|
F.......Toggle whether files are displayed.......................|NERDTree-F|
B.......Toggle whether the bookmark table is displayed...........|NERDTree-B|

q.......Close the NERDTree window................................|NERDTree-q|
A.......Zoom (maximize/minimize) the NERDTree window.............|NERDTree-A|
?.......Toggle the display of the quick help.....................|NERDTree-?|

Vim Tips

:g/^$/d      # Delete all blank lines

Spell

This command switches on spell checking:

:setlocal spell spelllang=en_us

This switches on the 'spell' option and specifies to check for US English.

The words that are not recognized are highlighted with one of these: SpellBad word not recognized |hl-SpellBad| SpellCap word not capitalised |hl-SpellCap| SpellRare rare word |hl-SpellRare| SpellLocal wrong spelling for selected region |hl-SpellLocal|

Vim only checks words for spelling, there is no grammar check.

If the 'mousemodel' option is set to "popup" and the cursor is on a badly spelled word or it is "popup_setpos" and the mouse pointer is on a badly spelled word, then the popup menu will contain a submenu to replace the bad word. Note: this slows down the appearance of the popup menu. Note for GTK: don't release the right mouse button until the menu appears, otherwise it won't work.

To search for the next misspelled word:

						*]s*

]s Move to next misspelled word after the cursor. A count before the command can be used to repeat. 'wrapscan' applies.

						*[s*

[s Like "]s" but search backwards, find the misspelled word before the cursor. Doesn't recognize words split over two lines, thus may stop at words that are not highlighted as bad. Does not stop at word with missing capital at the start of a line.

						*]S*

]S Like "]s" but only stop at bad words, not at rare words or words for another region.

						*[S*

[S Like "]S" but search backwards.

To add words to your own word list:

						*zg*

zg Add word under the cursor as a good word to the first name in 'spellfile'. A count may precede the command to indicate the entry in 'spellfile' to be used. A count of two uses the second entry.

		In Visual mode the selected characters are added as a
		word (including white space!).
		When the cursor is on text that is marked as badly
		spelled then the marked text is used.
		Otherwise the word under the cursor, separated by
		non-word characters, is used.

		If the word is explicitly marked as bad word in
		another spell file the result is unpredictable.


						*zG*

zG Like "zg" but add the word to the internal word list |internal-wordlist|.

						*zw*

zw Like "zg" but mark the word as a wrong (bad) word. If the word already appears in 'spellfile' it is turned into a comment line. See |spellfile-cleanup| for getting rid of those.

						*zW*

zW Like "zw" but add the word to the internal word list |internal-wordlist|.

zuw zug zuw zug Undo |zw| and |zg|, remove the word from the entry in 'spellfile'. Count used as with |zg|.

zuW zuG zuW zuG Undo |zW| and |zG|, remove the word from the internal word list. Count used as with |zg|.

						*:spe* *:spellgood*

:[count]spe[llgood] {word} Add {word} as a good word to 'spellfile', like with |zg|. Without count the first name is used, with a count of two the second entry, etc.

:spe[llgood]! {word} Add {word} as a good word to the internal word list, like with |zG|.

						*:spellw* *:spellwrong*

:[count]spellw[rong] {word} Add {word} as a wrong (bad) word to 'spellfile', as with |zw|. Without count the first name is used, with a count of two the second entry, etc.

:spellw[rong]! {word} Add {word} as a wrong (bad) word to the internal word list, like with |zW|.

:[count]spellu[ndo] {word} :spellu :spellundo Like |zuw|. [count] used as with |:spellgood|.

:spellu[ndo]! {word} Like |zuW|. [count] used as with |:spellgood|.

After adding a word to 'spellfile' with the above commands its associated ".spl" file will automatically be updated and reloaded. If you change 'spellfile' manually you need to use the |:mkspell| command. This sequence of commands mostly works well: :edit <file in 'spellfile'> (make changes to the spell file) :mkspell! %

More details about the 'spellfile' format below |spell-wordlist-format|.

						*internal-wordlist*

The internal word list is used for all buffers where 'spell' is set. It is not stored, it is lost when you exit Vim. It is also cleared when 'encoding' is set.

Finding suggestions for bad words:

						*z=*

z= For the word under/after the cursor suggest correctly spelled words. This also works to find alternatives for a word that is not highlighted as a bad word, e.g., when the word after it is bad. In Visual mode the highlighted text is taken as the word to be replaced. The results are sorted on similarity to the word being replaced. This may take a long time. Hit CTRL-C when you get bored.

		If the command is used without a count the
		alternatives are listed and you can enter the number
		of your choice or press <Enter> if you don't want to
		replace.  You can also use the mouse to click on your
		choice (only works if the mouse can be used in Normal
		mode and when there are no line wraps).  Click on the
		first line (the header) to cancel.

		The suggestions listed normally replace a highlighted
		bad word.  Sometimes they include other text, in that
		case the replaced text is also listed after a "<".

		If a count is used that suggestion is used, without
		prompting.  For example, "1z=" always takes the first
		suggestion.

		If 'verbose' is non-zero a score will be displayed
		with the suggestions to indicate the likeliness to the
		badly spelled word (the higher the score the more
		different).
		When a word was replaced the redo command "." will
		repeat the word replacement.  This works like "ciw",
		the good word and <Esc>.  This does NOT work for Thai
		and other languages without spaces between words.


				*:spellr* *:spellrepall* *E752* *E753*

:spellr[epall] Repeat the replacement done by |z=| for all matches with the replaced word in the current window.

In Insert mode, when the cursor is after a badly spelled word, you can use CTRL-X s to find suggestions. This works like Insert mode completion. Use CTRL-N to use the next suggestion, CTRL-P to go back. |i_CTRL-X_s|

The 'spellsuggest' option influences how the list of suggestions is generated and sorted. See |'spellsuggest'|.

The 'spellcapcheck' option is used to check the first word of a sentence starts with a capital. This doesn't work for the first word in the file. When there is a line break right after a sentence the highlighting of the next line may be postponed. Use |CTRL-L| when needed. Also see |set-spc-auto| for how it can be set automatically when 'spelllang' is set.

Vim counts the number of times a good word is encountered. This is used to sort the suggestions: words that have been seen before get a small bonus, words that have been seen often get a bigger bonus. The COMMON item in the affix file can be used to define common words, so that this mechanism also works in a new or short file |spell-COMMON|.

#Cursor movement

h - move left
j - move down
k - move up
l - move right
ctrl-b - page up
ctrl-f - page down
% - jump to matching brace
w - jump by start of words (punctuation considered words)
W - jump by words (spaces separate words)
e - jump to end of words (punctuation considered words)
E - jump to end of words (no punctuation)
b - jump backward by words (punctuation considered words)
B - jump backward by words (no punctuation)
ge - jump backward to end of words (punctuation considered words)
gE - jump backward to end of words (no punctuation)
0 - (zero) start of line
^ - first non-blank character of line
$ - end of line
gg - Go to first line
[N]G - Go To line N. No N: last line
Note: Prefix a cursor movement command with a number to repeat it. For example,
4j moves down 4 lines.

Inserting/Appending text

i - start insert mode at cursor
I - insert at the beginning of the line
a - append after the cursor
A - append at the end of the line
o - open (append) blank line below current line (no need to press return)
O - open blank line above current line
ea - append at end of word
Esc - exit insert mode

Editing

r - replace a single character (does not use insert mode)
J - join line below to the current one
cc - change (replace) an entire line
cw - change (replace) to the end of word
c$ - change (replace) to the end of line
s - delete character at cursor and subsitute text
S - delete line at cursor and substitute text (same as cc)
xp - transpose two letters (delete and paste, technically)
u - undo
ctrl-r - redo
. - repeat last command
~ - switch case
g~iw - switch case of current word
gUiw - make current word uppercase
guiw - make current word lowercase
>> - indent line one column to right
<< - indet line one column to left
== - auto-indent current line
ddp - swap current line with next
ddkP - swap current line with previous

Cut and Paste

dd - delete (cut) a line
dw - delete the current word
x - delete current character
X - delete previous character
D - delete from cursor to end of line
yy - yank (copy) a line
2yy - yank 2 lines
yw - yank word
y$ - yank to end of line
p - put (paste) the clipboard after cursor/current line
P - put (paste) before cursor/current line
:set paste - avoid unexpected effects in pasting

Visual Mode - Marking text

v - start visual mode, mark lines, then do command (such as y-yank)
V - start Linewise visual mode
o - move to other end of marked area
U - upper case of marked area
ctrl+v - start visual block mode
O - move to Other corner of block
aw - mark a word
ab - a () block (with braces)
aB - a {} block (with brackets)
ib - inner () block
iB - inner {} block
Esc - exit visual mode

Visual Mode

Commands

> - shift right
< - shift left
c - change (replace) marked text
y - yank (copy) marked text
d - delete (cut) marked text
~ - switch case

Cut and paste

1. Place the cursor at the start of your text.
2. ma (marks the location as point 'a')
3. Place the cursor at the end of your text.
4. d'a (cuts back to location 'a')

Exiting

:w - write (save) the file, but don't exit
:wq - write (save) and quit
:x - same as :wq
:q - quit (fails if anything has changed)
:q! - quit and throw away changes

Search/Replace

/pattern - search for pattern
?pattern - search backward for pattern
n - repeat search in same direction
N - repeat search in opposite direction
:%s/old/new/g - replace all old with new throughout file
:%s/old/new/gc - replace all old with new throughout file with confirmations

Working with multiple files

:e filename - Edit a file in a new buffer
:n **/*.pl - Open all perl files under the current directory, recursively
:tabe filename - Edit a file in a new tab (Vim7, gVim)
:bnext (or :bn) - go to next buffer
:bprev (or :bp) - go to previous buffer
:bd - delete a buffer (close a file)
:sp filename - Open a file in a new buffer and split window
ctrl-w s - Split windows
ctrl-w w - switch between windows
ctrl-w q - Quit a window
ctrl-w v - Split windows vertically

Tabs (Vim7)

{i}gt  - go to tab in position i
gt - Next tab
gT - Previous tab
:tabr - First tab
:tabl - Last tab
:tabm [N] - Move current tab after tab N. No N: last. N=0: first.
$vim -p file1 file2 fileN  - Open multiple files in different tabs (vim7) 

Command Line Options

$vim -c "vim command" file - execute an editor command on startup

Commands

:setlocal fileformat=dos|unix
:setlocal fileencoding=utf-8

More help

:help - main help portal (with links to more help pages)
:viusage - show a huge cheat sheet listing every command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment