人们谈论常见技巧的问题很多,特别是“Vim+ctags提示和技巧”。

然而,我并没有提到Vim新手会觉得很酷的常用快捷方式。我所说的是一位经验丰富的Unix用户(无论是开发人员、管理员,还是两者都有),他们认为自己知道99%的人从未听说过或梦想过的东西。这不仅让他们的工作更容易,而且很酷,很粗糙。毕竟,Vim位于世界上最黑暗的角落丰富的操作系统中,因此它应该具有只有少数特权人士知道并想与我们分享的复杂性。


当前回答

键入==将根据上面的行更正当前行的缩进。

实际上,您可以在任何移动命令后执行一个=符号={移动}

例如,可以使用在匹配大括号之间移动的%移动。将光标放在以下代码中的{上:

if (thisA == that) {
//not indented
if (some == other) {
x = y;
}
}

然后按=%立即获得:

if (thisA == that) {
    //not indented
    if (some == other) {
        x = y;
    }
}

或者,您可以在代码块中执行=a{,而不是将自己定位在{字符上。

其他回答

==========================================================
In normal mode
==========================================================
gf ................ open file under cursor in same window --> see :h path
Ctrl-w f .......... open file under cursor in new window
Ctrl-w q .......... close current window
Ctrl-w 6 .......... open alternate file --> see :h #
gi ................ init insert mode in last insertion position
'0 ................ place the cursor where it was when the file was last edited

这些是我多年来收集的。

" Pasting in normal mode should append to the right of cursor
nmap <C-V>      a<C-V><ESC>
" Saving
imap <C-S>      <C-o>:up<CR>
nmap <C-S>      :up<CR>
" Insert mode control delete
imap <C-Backspace> <C-W>
imap <C-Delete> <C-O>dw
nmap    <Leader>o       o<ESC>k
nmap    <Leader>O       O<ESC>j
" tired of my typo
nmap :W     :w
:r! <command>

将外部命令的输出粘贴到缓冲区中。

做一些数学运算,直接在文本中得到结果:

:r! echo $((3 + 5 + 8))

获取编写Makefile时要编译的文件列表:

:r! ls *.c

不要在维基百科上查找你阅读的事实,直接将其粘贴到你正在编写的文档中:

:r! lynx -dump http://en.wikipedia.org/wiki/Whatever
In Insert mode 
<C-A>   - Increments the number under cursor 
<C-X>   - Decrements the number under cursor

如果我们想在vim中生成序列号,这将非常有用假设我们想插入1-10行,数字从1到10[如第1行的“1”,第2行的“2”…]在第一行插入“0”并复制该行和过去的9次因此,所有行都将显示“0”。

运行以下Ex命令

:g/^/exe "norm " . line(".") . "\<C-A>"

有时,.vimrc中的设置会被插件或自动命令覆盖。要调试这一点,一个有用的技巧是将:verbose命令与:set结合使用。例如,要确定cindent在何处设置/取消设置:

:verbose set cindent?

这将输出如下内容:

cindent
    Last set from /usr/share/vim/vim71/indent/c.vim

这也适用于地图和高光。(感谢joeytwiddle指出这一点。)例如:

:verbose nmap U
n  U             <C-R>
        Last set from ~/.vimrc

:verbose highlight Normal
Normal         xxx guifg=#dddddd guibg=#111111 font=Inconsolata Medium 14
        Last set from ~/src/vim-holodark/colors/holodark.vim