我一直在Vim中学习新的命令,但我相信每个人都偶尔会学习一些新东西。我最近才知道:
Zz, zt, zb -位置光标在中间,顶部或底部的屏幕
还有什么其他有用或优雅的命令是你希望很久以前就学会的?
我一直在Vim中学习新的命令,但我相信每个人都偶尔会学习一些新东西。我最近才知道:
Zz, zt, zb -位置光标在中间,顶部或底部的屏幕
还有什么其他有用或优雅的命令是你希望很久以前就学会的?
当前回答
我为我的一个朋友创建了我最常用的命令的参考:
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.
其他回答
Qx将开始记录击键。你几乎可以做任何编辑任务,Vim都记得。当你完成时再次点击q,然后按@x来重放你的击键。这对于过于复杂而无法编写映射的重复编辑非常有用。可以使用x以外的字符进行多次记录。
我不得不说,我最喜欢的一个方法是把帮助窗口放在一个新标签中:
:tab help <help_topic>
这将在一个新标签中打开帮助,作为一个喜欢Vim标签的人,这是非常有用的。
使用选项卡打开多个文件
:tabe filepath
在打开的文件之间导航
gt and gT or :tabn and :tabp
保存打开的会话,以便稍后可以返回打开的文件列表
:mksession session_file_name.vim
打开已创建的会话
vim -S session_file_name.vim
立即关闭所有文件
:qa
这是我最近学到的另一个命令
autocmd
它允许你在一个事件上运行命令,所以你可以在保存文件时使用如下命令:
:autocmd BufWritePost *.cpp :make
cw
更改单词-删除光标下的单词,并将您置于插入模式下键入一个新的单词。当然,这也适用于其他移动键,所以你可以做c$之类的事情来改变到行尾。
F +字符
查找当前行上字符的下一个出现位置。因此,您可以使用vft来选择当前行上下一个“t”之前的所有文本。这是另一个移动键,所以它也适用于其他命令。
这句话总是让我高兴起来:
:help 42