Skip to content

Instantly share code, notes, and snippets.

@robertDurst
Forked from m3nd3s/NERDTree.mkd
Created August 15, 2019 22:01
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 robertDurst/8caf296642f4afb1514f28957ccd2158 to your computer and use it in GitHub Desktop.
Save robertDurst/8caf296642f4afb1514f28957ccd2158 to your computer and use it in GitHub Desktop.
My Vim Cheat Sheet

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

Fonte: Usando correção ortográfica no Vim7

Para habilitar a correção ortográfica no Vim7:

Pegue o arquivo de dicionário aqui: http://www.broffice.org/?q=verortografico Crie um diretório e descompacte o danado lá. Abra o Vim e digite :mkspell pt pt_BR (atenção: isso vai gerar um processamento lascado, não diga que eu não avisei!). Vai ser gerado um arquivo chamado pt.latin1.spl. Copie esse arquivo para o diretório ~/.vim/spell/. Abra o vim e digite :set spell spelllang=pt, ou já configure isso no seu ~/.vimrc. Digite algum texto. As palavras que ele não reconhecer vão ficar sublinhadas. Para achar sugestões para as palavras sublinhadas, use z= ou no modo de inserção, CTRL+X s. CTRL+N vai para a próxima sugestão e CTRL+P cancela. As palavras sublinhadas em azul (pelo menos no meu esquema de cores) são palavras que precisam estar em maiúsculas e as que estão em vermelho são palavras que não existem. Algumas palavras meio óbvias faltam no dicionário, mas dá para usar. Como eles mencionam na página do projeto, ARREGACE AS MANGAS, o que é que você está esperando?, se estiver incomodando muito essa falta de palavras. :-)

Atualizado: O amigo Aurélio escreveu um artigo sobre o Vim7 aqui, onde ele dá duas dicas ótimas para complementar as acima:

Inserir uma palavra no dicionário: Coloque o cursor na palavra e digite zg ('g' de 'good', boa palavra) Remover uma palavra do dicionário: Coloque o cursor sobre ela e digite zw ('w' de 'wrong', palavra errada). Pronto! :-)

#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