Wednesday, April 28, 2010

Vim basic commands

c$ - change (replace) to the end of line
r - replace character at cursors by another 
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
Marking text (visual mode)

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
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 commands

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

Cut and Paste

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
P - put (paste) before cursor
dd - delete (cut) a line
dw - delete (cut) the current word
x - delete (cut) current character
Exiting

:w - write (save) the file, but don't exit
:wq   or   :x  or  shitf zz  -  write (save) and quit
: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
search or replace beginign with patern
/^patern
:%s/^patern/new/g
search or replace ending with patern
/patern$
:%s/pattern$/new/g

Sort and remove duplicates
:sort
:sort u

Registers in Vim let you run actions or commands on text stored within them. To access a register, you type "a before a command, where a is the name of a register. If you want to copy the current line into register k, you can type
    "kyy
Or you can append to a register by using a capital letter
    "Kyy
You can then move through the document and paste it elsewhere using
    "kp
To paste from system clipboard on Linux
    "+p
To paste from system clipboard on Windows (or from "mouse highlight" clipboard on Linux)
    "*p
To access all currently defined registers type
    :reg

Copy to clipboard
"+y
ora
"*y

in search mode
Ctrl + r, Ctrl +w - paste current word under cursor
Ctrl + r, "   - paste current yanked text

Working with multiple files

:e filename - Edit a file in a new buffer
:bnext (or :bn) - go to next buffer
:bprev (of :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+ws - Split windows
ctrl+ww - switch between windows
ctrl+wq - Quit a window
ctrl+wv - Split windows vertically

Retirado do site www.worldtimzone.com/res/vi.html
outra boa referencia
www.fprintf.net/vimCheatSheet.html




Ctrl+w _                  - Minimize vertical split
Ctrl+w |                  - Minimize horizontal split
Ctrl+w =                  - Resize all split to same size
Ctrl+w T                  - Move all split to a different tab
Ctrl+w o                  - Close all other split but not the current
sudo apt install vim-gtk  - Enable copy to clipboard with ("+y")
g Ctrl+a                  - increment numbers in sequence Select with Ctr+v            
:%s/pattern//gn           - Number of matchs of a pattern
:%s/pattern//n            - Number of lines that contains matchs of a pattern

No comments:

Blog Archive