我一直在Vim中学习新的命令,但我相信每个人都偶尔会学习一些新东西。我最近才知道:
Zz, zt, zb -位置光标在中间,顶部或底部的屏幕
还有什么其他有用或优雅的命令是你希望很久以前就学会的?
我一直在Vim中学习新的命令,但我相信每个人都偶尔会学习一些新东西。我最近才知道:
Zz, zt, zb -位置光标在中间,顶部或底部的屏幕
还有什么其他有用或优雅的命令是你希望很久以前就学会的?
当前回答
Q <字母> -记录一个宏。
and
@<相同字母> -回放。
这些是到目前为止在Vim中最有用的命令,因为你可以让计算机为你做很多工作,你甚至不需要写一个程序或任何东西。
其他回答
我经常创建用于编辑任务的函数,并将它们存储在.vimrc文件中,这样我就可以再次找到它们。
例如,读取已转换为单行的.NET调用栈:
function! FixCallStacks()
:%s;\[NLN\];\r;g
:%s;\[TAB\];\t;g
endfunction
我为我的一个朋友创建了我最常用的命令的参考:
select v
select row(s) SHIFT + v
select blocks (columns) CTRL + v
indent selected text >
unindent selected text <
list buffers :ls
open buffer :bN (N = buffer number)
print :hardcopy
open a file :e /path/to/file.txt
:e C:\Path\To\File.txt
sort selected rows :sort
search for word under cursor *
open file under cursor gf
(absolute path or relative)
format selected code =
select contents of entire file ggVG
convert selected text to uppercase U
convert selected text to lowercase u
invert case of selected text ~
convert tabs to spaces :retab
start recording a macro qX (X = key to assign macro to)
stop recording a macro q
playback macro @X (X = key macro was assigned to)
replay previously played macro * @@
auto-complete a word you are typing ** CTRL + n
bookmark current place in file mX (X = key to assign bookmark to)
jump to bookmark `X (X = key bookmark was assigned to
` = back tick/tilde key)
show all bookmarks :marks
delete a bookmark :delm X (X = key bookmark to delete)
delete all bookmarks :delm!
split screen horizontally :split
split screen vertically :vsplit
navigating split screens CTRL + w + j = move down a screen
CTRL + w + k = move up a screen
CTRL + w + h = move left a screen
CTRL + w + l = move right a screen
close all other split screens :only
* - As with other commands in vi, you can playback a macro any number of times.
The following command would playback the macro assigned to the key `w' 100
times: 100@w
** - Vim uses words that exist in your current buffer and any other buffer you may have open for auto-complete suggestions.
Gi切换到插入模式,将光标放置在先前的相同位置。
对于强制Vim配置,请查看https://github.com/jmcantrell/dotfiles-vim
我刚刚在浏览Vim帮助时发现了这个:
:help index
这将把您带到一个单独的(可搜索的!)页面,其中包含所有模式的所有命令。
所以,如果你知道你要记住/学习的命令是从某个按键开始或涉及到某个按键,你可以搜索并浏览所有的可能性。或者你可以浏览你感兴趣的模式,看看/学习编辑的可能性。
我都数不清有多少次我只是按Ctrl + R或者其他键,然后得到了第一个东西,当然这不是你想要的。在我看来,这比:helpgrep好多了。
然后进入。vimrc:
nnoremap <silent> <F1> :help normal-index<CR>
inoremap <silent> <F1> <C-O>:help insert-index<CR>
:help仍然会让你进入默认的F1页面。