vim operation
note: 转自 www.quora.com ,很好的网站。
具体链接如下:
https://www.quora.com/What-are-some-impressive-demos-of-Vim-possibilities-for-beginners
其实看英文更容易记住一些,所以贴在这里以后常看看,也希望更多的人看看。
========== Navigation ==========
CTRL+C OR Ctrl+[ instead of ESC.
1/2 ½ BOL (Begin-of-line)
0 BOL (Begin-of-line)
$ EOL (End-of-line)
H Goto HEADER (Top of the screen)
M Goto MIDDLE of BUFFER
L Goto last (bottom).
CTRL+F Page down
CTRL+B Page up
(Handy Page Up / Page Down for Mac where Fn+Up/Down is scrolling Term)
^ Cursor to first non whitespace character
g_ Cursor to last whitespace character
gg (BOF) Beginning of File
G (EOF) End of the file.
10G Goto line 10
:10 Goto line 10
fc Move forward to c (c= character)
Fc Move back to c
gd Goto Definition of Variable
[m Go to function opening
Ctrl+D Page-by-page scrolling
CTRL+O Last location (cursor)
CTRL-I Next location (cursor)
CTRL+^ Alternate file (last edited file in current window)
* Next word
# Previous word
% on brackets {} () [] will find the matching one.
3dd - delete 3 lines
d2f. - delete to the second period.
d% - delete till next pair [, {, (, etc.
v$% - Select whole function (incl. function name)
vi{ - Select function contents
:n /folder/** Open all files (and directories) in folder as buffers (Delete directories and save session for projects)
# [], [[, ]] og ][ what?
zz Cursor to center of screen
z. Cursor to center of screen
z- Cursor to bottom of screen
zb Cursor to bottom of screen
z Cursor to top of screen
zt Cursor to top of screen
========== Change ==========
I INSERT (at beginning)
A INSERT (at end of line)
go INSERT (at end of file)
ci} Change inside brackets
vi} Select inside brackets
dit Delete the text between matching XML tags. (it is for "inner tag block".)
cit Change the text between matching XML tags. (it is for "inner tag block".)
s Substitute char
S Substitute line
c2w Change the next 2 words
dgg Delete to top
dG Delete to bottom
d^ Delete to start of line
D Delete to end of line (or d$)
dt; Delete until ;
d/foo Delete until foo
d} Delete next p-graph
d{ Delete previous p-graph
SHIFT-J Join below line to above ("LINE1\nLINE2" becomes "LINE1 LINE2")
cc Replace Line
S Replace Line
s Replace Letter (Delete then Insert Mode)
cw Replace word
c$ Replace to EOL
c/word Change word and put in INSERT mode.
c?word Change word (search backwards) and put in INSERT mode.
deep Swap two words in front of cursor (Cursor on empty space)
ddp Swap two lines
g- Undo Change
u Undo Change
g+ Redo Change
CTRL+R Redo Change
:earlier Undo by time
:later Redo by time
:undo n Undo by number of actions
:undolist Leaves of undo tree with numbers
y Copy marked text
Y Copy/Yank whole line
y$ Copy/Yank whole line
2yy Copy 2 lines
yw Copy word
ALT+j Move current line UP
ALT+k Move current line DOWN
CTRL-6 Switch between open buffers
ggVG Select All
ggvG= Auto-indenting
== Indent current line
x Delete current character
CTRL+A Increment Number
1CTRL+A Increment Multi-Digit Number
CTRL+X Decrements Number
1CTRL+X Decrements Multi-Digit Number
CTRL+O (Insert-Mode) run normal mode commands and Ex-commands (:echo) temporarily in insert-mode.
:diffthis In two buffers/windows enables diffmode.
ggVGJ join all lines
========== Windows ==========
CTRL+H Window Left ̂
CTRL+L Window Right ̂
CTRL+J Window Down ̂
CTRL+K Window Up ^
CTRL+WW Switch between Windows
CTRL+WR Rotate
CTRL+WQ Quit window
CTRL+WV Split Windows Vertical
CTRL-W_ Minimize window
CTRL-W| Maximize window
CTRL-W+ Grow window
CTRL-W- Shrink window
CTRL+W_ Max height
CTRL + W| Max width
CTRL+W= Set all windows to equal size.
CTRL+W+R Rotate windows (swap left/right top/bottom)
CTRL+W+T Put window in a tab.
CTRL+W+O Close every window but current one.
========== Macro ==========
q Record Macro
qa Run macro (a)
3@q Run macro 3 times
========== Navigation/Files ==========
:cwd Show current working directory
:lcwd Show current (Tab/Window) directory
:ls Show current buffers
:cd Change directory
:lcd Change current (Tab/Window) directory
:new will create a split window with an unnamed buffer.
:enew will open one in the current window.
:vnew will open one in a vertically split window.
:tabnew will open one in a new tab.
vim scp://root@adrafinil//etc/udev/rules.d/10-network.rules
========== Visual commands ==========
> Indent Right
< Indent Left
d Delete marked text
~ Switch case
V Select whole line
========== Insert commands ==========
CTRL-R * will insert in the contents of the clipboard
CTRL-R " (the unnamed register) inserts the the last delete or yank.
========== Search / Replace ==========
/ Search
<SPACE> Search
? Backwards Search
n Next Search ¯
N Previous Search
c/word Change word and put in INSERT mode.
c?word Change word (search backwards) and put in INSERT mode.
:bufdo /searchstr/ Search in all open files
:%s/old/new/g replace all old with new throughout file
:%s/foo/bar/gi The same as above, but ignore the case of the pattern you want to substitute. This replaces foo, FOO, Foo, and so on.
:%s/old/new/gc replace all old with new throughout file with confirmations
:%s/foo/bar/c For each line on the file, replace the first occurrence of foo with bar and confirm every substitution.
:/.*word1\&.*word2 Search for both words simultaneously
:g/^%/s/foo/bar/g Replace every line starting with % with foo with bar
# replace space with newline - literally CTRL-V
:%s/ /<CTRL-V>/g
:sort u - remove duplicate lines
# highlight duplicate lines
:syn clear Repeat | g/^\(.*\)\n\ze\%(.*\n\)*\1$/exe 'syn match Repeat "^' . escape(getline('.'), '".\^$*[]') . '$"' | nohlsearch
:rs/foo/bar/a Substitute foo with bar. r determines the range and a determines the arguments.
:g/^#/d Delete all lines that begins with #
:g/^$/d Delete all lines that are empty
:g/^///d Delete all // comments
:g/^s*$/d Delete all whitespace lines
:ab mail mail@provider.org Define mail as abbreviation of mail@provider.org (replace when "mail" is written)
:%s/<Ctrl-V><Ctrl-M>//g Remove ^M from files.
========== Marks ==========
m+[A-Z] marks the current line with an alias of the key pressed.
'[A-Z] goes to this mark.
Using marks
========== Misc ==========
. Repeat Command
0p Paste BOL
$p Paste EOL
*p Paste (without indentation) similar to :set paste
# Insert mode
CTRL+R " Paste unnamed/yank register (Insert Mode)
CTRL+R * will insert in the contents of the clipboard (:h i_ctrl-r)
CTRL+R #
CTRL+R : Will insert last cmdline (ex command) (useful for adding a recently typed command to vimrc)
# Normal mode
#p
ZZ Save and quit
g CTRL-G Show Col 1 of 0; Line 5 of 6; Word 1 of 11; Byte 968 of 1019
:help g_CTRL-G
:f Show bufname, modify-status,
"[No Name]" [Modified] line 6 of 6 --100%-- col 49
:help :f
:command show all functions/commands in vim (plugins, custom functions, etc.)
SHIFT+K "Man page" of command under cursor
:%!python -m json.tool - Format JSON pretty in current buffer via Python.
:bn Next Buffer
:bp Previous Buffer
:b # Goto # Buffer. (eg. ':b 1' goto buffer 1)
:b filename
:tab sball Opens a new tab for each open buffer #not recommended, learn to use it, the "right" (tm) way. eg. buffers == tabs, tabs = different viewport arrangement/splits/layout
gt Next Tab
gT Previous Tab
,pp Toggle Paste Mode
,cd Switch CWD to Dir of Open Buffer
:r Read from file into buffer
:r!shellcmd Read shell command into buffer
gf open file under cursor (or import statement)
<c-w>f open in a new window (Ctrl-w f)
<c-w>gf open in a new tab (Ctrl-w gf)
# Set tabline to current directory
:set tabline=[_%{getcwd()}_]
# Relative Directory
:set tabline=%{expand('%:p:h')}
Absolute Path
:set tabline=%{expand('%:p')}
File name
:set tabline=%{expand('%:t')}
#CTAGS
# Generate tags (for goto definition, goto file, taglist) for PHP and template files (*.tpl)
ctags -R --languages=php --langmap=PHP:+.tpl .
ctags -R --languages=php --langmap=PHP:+.tpl --tag-relative=yes --PHP-kinds=+cf .
# Avoid loading vimrc/plugins
gvim -N -u NONE -i NONE (to check for .vimrc/_vimrc causing it)
# Who set filetype?
:verbose set filetype
# Step-by-step autocmd go-through ..
:debug wincmd p
# Output Vim command to file (:buffers in this case)
:redir > outputFile
:buffers
:redir END
# Show character hex, octal, code under cursor
ga
# Quickfix Window (Compiler Messages etc.)
:cw
# Clear last search highlightning
set nohlsearch
# Reverse line order (explanation: Reverse all lines)
:g/^/m0
# Pipe to vim
echo "lel" | vim -
# Show all "set" vim variables
:options
========== Folding ==========
za Toggle folding
zA Toggle folding recursively
zc Close one or count folds under the cursor
zC Close all folds under cursor
zD Delete folds recursively
zE Delete ALL Folds
zf motion - Create a fold
zF Create a fold for count lines
zi Toggle foldenable
zM Close all folds, set foldlevel=0, set foldenable
zR Open all folds and set foldlevel to highest fold level.
zn Fold "none": reset foldenable and open all folds
zN Fold "normal": set foldenable and restore all folds
zo Open one or count folds
z0 Open all folds under the cursor
========== netrw / Explorer ==============
(Built-in filebrowser)
<leftmouse> open
<rightmouse> delete
d New directory
D Delete file(s)/directory(ies)
p Preview file
qb list bookmarks (and recent dirs) ?
mb make bookmark
mB delete bookmark
mf OR <s-leftmouse> Mark files
gb goto bookmark
md diff marked files
mp print marked files
mu unmark all
t enter file in new tab
1u go back 1 history (corresponds to qb-listing)
u forward one directory in history
U backwards one directory in history
========== Plugins / Extensions ==========
Benchmark/Profiling Scripts
vim --startuptime vim.log
--- vim-surround ---
# cs = change surround
# ds = delete surround
# tpope/vim-surround
cs({ - change () to {} - (cursor inside)
ds" - remove " - y
#cst" - surround with "
cs'<b> - add <b> tag (on 'Text' only)
ysiw] - add [] to word (works for <b> tags too)
yss) - add ) to line (works for <b> tags too)
#Visual mode
S" - surround selection with "
gS" - surround with " with newlines before and after content
(V) select text, S<div class="wrap"> -- wrap in this tag
================== Regex ======================
BTsync secrets vim regex
- magic vim "perl regex" operator
- A-Z 0-9
- times 33
- \< \> # means word boundary in-between (this is a word/string)
/\<[A-Z0-9]\{33}\>
======= Win x32/x64 Optimizations NOTES =======
Download custom build from:
#Vim 7.4.796 builds for Windows (32-bit, latest)
Haroogan/veegee are best for YCM compatibility and more..
Page on bitbucket.org (64-bit)
#Cream (for Vim) - Browse /Vim at SourceForge.net
#Wu Yongwei's Programming Page