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
- vim编辑指令(转)
跳跃指令 类似于游览器中的<前进><后退>按钮 CTRL-] -> 跟着link/tag转入 (follow link/tag) CTRL-o -> 回到上一次 ...
- 实习之vim基本学习
最近实习学到了写vim的基本用法,记录一下 批量注释 ctrl+v进入列模式,按“I”进入插入模式,按// #等在每行开头插入注释,esc 批量去除注释 ctrl + v 进入列模式,按“x”即可. ...
- vim 常用快捷键 二[转]
键盘移动 (Move) 一切都从键盘的移动k -> 上 upj -> 下 downh -> 左 leftl -> 右 rightz -> 重画屏幕,当前光标变成屏幕的第一 ...
- -bash: ulimit: max user processes: cannot modify limit: Operation not permitted
安装oracle时候在创建oracle用户后,切换oracle用户时,报如下错 [root@localhost ~]# su - oracle-bash: ulimit: max user proce ...
- vim模式下报错E37: No write since last change (add ! to override)
故障现象: 使用vim修改文件报错,系统提示如下: E37: No write since last change (add ! to override) 故障原因: 文件为只读文件,无法修改. 解决 ...
- 转:vim模式下报错E37: No write since last change (add ! to override)
故障现象: 使用vim修改文件报错,系统提示如下: E37: No write since last change (add ! to override) 故障原因: 文件为只读文件,无法修改. 解决 ...
- vim 常用 NERDTree 快捷键
ctrl + w + h 光标 focus 左侧树形目录 ctrl + w + l 光标 focus 右侧文件显示窗口 ctrl + w + w 光标自动在左右侧窗口切换 ctrl + w + r 移 ...
- 清理messages提示-bash: /var/log/messages: Operation not permitted的处理
报警提示系统盘容量不足了/var/log下查看messages日志已经很大了,所以就想着把messages清空一下,以此来释放空间.在删除的时候提示没有权限. 看了下日志,发现是大量的haproxy日 ...
- Hadoop 系列文章(一) Hadoop 的安装,以及 Standalone Operation 的启动模式测试
以前都是玩 java,没搞过 hadoop,所以以此系列文章来记录下学习过程 安装的文件版本.操作系统说明 centos-6.5-x86_64 [bamboo@hadoop-senior opt]$ ...
随机推荐
- 咱就入个门之NHibernate映射文件配置(一)
之前写了数据库连接配置,这次说说映射文件的配置,即表映射[ORM的核心就是此啦!]. 下面我们使用最原始的手动配置hbm.xml文件. 步骤: 1.添加People类 namespace NHiber ...
- 在64位Win7中使用Navicat Premium 和PL\SQL Developer连接Oracle数据库备忘
最近接手了一个项目,服务器端数据库是oracle 11g 64位.由于主要工作不是开发,也不想在自己的电脑上安装庞大的oracle数据库,因此寻思着只通过数据库管理工具连接数据库进行一些常用的查询操作 ...
- CmRegisterCallback使用方法
部分代码 #include "my_sys_fun.h"#ifdef __cplusplusextern "C"{#endif //驱动加载函数 NTSTATU ...
- SSH 小总
SSH 为 struts+spring+hibernate的一个集成框架,是目前较流行的一种Web应用程序开源框架. 集成SSH框架的系统从职责上分为四层:表示层.业务逻辑层.数据持久层和域模块层,以 ...
- input上下居中问题
IE:不管该行有没有文字,光标高度与font-size一致.FF:该行有文字时,光标高度与font-size一致.该行无文字时,光标高度与input的height一致.Chrome:该行无文字时,光标 ...
- android常用对话框封装
在android开发中,经常会用到对话框跟用户进行交互,方便用户可操作性:接下来就对常用对话框进行简单封装,避免在项目中出现冗余代码,加重后期项目的维护量:代码如有问题欢迎大家拍砖指正一起进步. 先贴 ...
- ASP.NET中Url编码解码
今天遇到Url编码解码的问题,纠结了一天的时间,结果上网一查才发现太二了我们. 同事写的代码把url用HttpUtility.UrlEncode编码和解码了,本地测试没有问题,部署到服务器上就提示转码 ...
- JS获得鼠标位置
<body> <script> function mouseMove(ev) { ev = ev || window.event; var mousePos = mouseCo ...
- SpringMVC解析1-使用示例
Spring MVC分离了控制器.模型对象.分派器以及处理程序对象的角色,这种分离让它们更容易进行定制.Spring的MVC是基于servlet功能实现的,通过实现Servlet接口的Dispatch ...
- hdu1078 dp(递推)+搜索
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1078 题意:老鼠从(1.1)点出发,每次最多只能走K步,而且下一步走的位置的值必须必当前值 ...