Rails Vim 实用技巧

zgs225 · January 18, 2016 · Last by boyishwei replied at January 19, 2016 · 2396 hits

原文发表在:Vim 技巧,希望留言指正错误或者发表不同意见。

在 Github 上看到的一些挺有用的技巧,转载、汇总过来。文章最后会有来源。

行为一致的 n 和 N

nN在搜索中用来查找下一个或者上一个搜索结果。但是在使用/或者?搜索时,它 移动的方向不同,这个经常会混淆。所以,如果你希望n总是查找下一个搜索结果,N总 是查找上一个搜索结果的话,你可以这么做:

nnoremap <expr> n  'Nn'[v:searchforward]
nnoremap <expr> N  'nN'[v:searchforward]

快速移动当前行

如果你想将当前行快速上移或者下移几行的话,你可以这么做:

nnoremap [e  :<c-u>execute 'move -1-'. v:count1<cr>
nnoremap ]e  :<c-u>execute 'move +'. v:count1<cr>

上面两个映射接受数字做为参数,例如:2]e表示将当前行下移两行。

快速宏编辑

这条非常有用!这个快捷键打开了一个命令历史窗口,你可以编辑,然后按<cr>键执行。

nnoremap <leader>m  :<c-u><c-r>='let @'. v:register .' = '. string(getreg(v:register))<cr><c-f><left>

<leader>m使用这条技巧。

高亮光标所在当前行和当前列

au WinLeave * set nocursorline nocursorcolumn
au WinEnter * set cursorline cursorcolumn
set cursorline cursorcolumn

显示多余的空白字符

set list listchars=tab:»·,trail:·

在 GUI 中快速改变字体大小

测试在控制台的 Vim 中无效。

command! Bigger  :let &guifont = substitute(&guifont, '\d\+$', '\=submatch(0)+1', '')
command! Smaller :let &guifont = substitute(&guifont, '\d\+$', '\=submatch(0)-1', '')

参考

Vimer 表示支持!看了你另一篇如何把 vim 搞成 IDE, 表示很赞!

You need to Sign in before reply, if you don't have an account, please Sign up first.