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

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


当前回答

在插入模式下,Ctrl-n将根据打开缓冲区中的所有单词自动完成您键入的任何单词。如果有多个匹配项,它将为您提供一个可能的单词列表,您可以使用ctrl-n和ctrl-p进行循环。

其他回答

通常,我喜欢在编辑时更改当前目录,所以我必须少指定路径。

cd %:h
==========================================================
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
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>"

我喜欢使用“sudobash”,我的系统管理员讨厌这样。他锁定了“sudo”,因此它只能与少数命令(ls、chmod、chown、vi等)一起使用,但无论如何我都能使用vim获得根shell:

bash$ sudo vi +'silent !bash' +q
Password: ******
root#

这些是我多年来收集的。

" 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