最常用的vim命令/按键是什么? [英] What are the most-used vim commands/keypresses?
问题描述
我是一个Ruby程序,试图从Textmate切换到MacVim,但在浏览庞大的VIM列表以及它们的所有按键时遇到麻烦.我厌倦了听到您可以使用'I'来插入文本,或'a'来在字符后添加文本,或使用'A'来在行的末尾添加文本,或者……"我无法想象每个人都使用全部20种不同的按键来导航文本,使用大约10种按键来开始添加文本,并使用18种方式直观地选择内部块.还是你!?
I'm a Ruby programming trying to switch from Textmate to MacVim, and I'm having trouble wading through the gargantuan lists of things you can do in VIM and all of the keypresses for them. I'm tired of hearing "You can use 'I' for inserting text, or 'a' for appending text after the character, or 'A' for appending text at the end of the line, or…" I can't imagine everyone uses all 20 different keypresses to navigate text, 10 or so keys to start adding text, and 18 ways to visually select an inner block. Or do you!?
我理想的备忘单是每个人每天用于编写代码的30-40个最常用的按键或命令,以及红宝石学家每天使用的绝对必要的插件以及10个最常用的命令.从理论上讲,一旦我有了并开始像在Textmate中一样熟练使用VIM,然后,我就可以开始学习成千上万的其他VIM命令,这将使我更多
My ideal cheat sheet would be the 30-40 most-used keypresses or commands that everyone uses for writing code on a daily basis, along with the absolute essential plugins that rubyists use daily and the 10 most-used commands for them. In theory, once I have that and start becoming as proficient in VIM as I am in Textmate, then I can start learning the thousands of other VIM commands that will make me more efficient.
或者,我是否完全以错误的方式学习了VIM?
Or, am I learning VIM the wrong way altogether?
推荐答案
这是我曾经写过的小技巧,其中包含我经常使用的命令:
Here's a tip sheet I wrote up once, with the commands I actually use regularly:
- vim documentation online
- advanced vim tips
- more useful tips and graphical cheat sheet
- 几乎所有命令都可以在数字后加上重复计数.例如. 5dd 删除5行
-
<Esc>
使您退出任何模式并返回命令模式 - 以:开头的命令在屏幕底部的命令行上执行
- :帮助有关任何命令的帮助
- Nearly all commands can be preceded by a number for a repeat count. eg. 5dd delete 5 lines
<Esc>
gets you out of any mode and back to command mode- Commands preceded by : are executed on the command line at the bottom of the screen
- :help help with any command
- 光标移动:← h ↓ j ↑ k l→
- 用词:
- w 下一个单词(标点符号); W 下一个单词(按空格)
- b 后单词(标点符号); B 后单词(按空格)
- e 结束词(标点符号); E 结束词(按空格)
- Cursor movement: ←h ↓j ↑k l→
- By words:
- w next word (by punctuation); W next word (by spaces)
- b back word (by punctuation); B back word (by spaces)
- e end word (by punctuation); E end word (by spaces)
- 0 行首; ^ 第一个非空白
- $ 行尾
- 0 start of line; ^ first non-whitespace
- $ end of line
- {"上一个空白行; } 下一个空白行
- { previous blank line; } next blank line
- gg 文件开始; G 文件结尾
- 123G 转到特定的行号
- gg start of file; G end of file
- 123G go to specific line number
- mx 设置标记 x ; 'x 标记 x
- '.转到上次编辑的位置
- ''回到跳跃之前的最后一点
- mx set mark x; 'x go to mark x
- '. go to position of last edit
- ' ' go back to last point before jump
- ^ F 转发全屏; ^ B 向后全屏
- ^ D 下半屏; ^ U 向上半屏
- ^ E 向上滚动一行; ^ Y 向下滚动一行
- zz 中心光标线
- ^F forward full screen; ^B backward full screen
- ^D down half screen; ^U up half screen
- ^E scroll one line up; ^Y scroll one line down
- zz centre cursor line
- u 撤消; ^ R 重做
- .重复上一个编辑命令
- u undo; ^R redo
- . repeat last editing command
所有插入命令均以
<Esc>
终止,以返回命令模式.All insertion commands are terminated with
<Esc>
to return to command mode.- i 在光标处插入文本; 我在行首插入文字
- a 在光标后附加文本; A 在行尾添加文字
- o 在下面打开新行; O 在上方打开新行
- i insert text at cursor; I insert text at start of line
- a append text after cursor; A append text after end of line
- o open new line below; O open new line above
- r 替换单个字符; R 替换多个字符
- s 更改单个字符
- cw 更改单词; C 更改为行尾; cc 更改整行
- c
<motion>
沿运动方向更改文本 - ci()更改括号内的内容(请参见文本对象选择以获取更多示例)
- r replace single character; R replace multiple characters
- s change single character
- cw change word; C change to end of line; cc change whole line
- c
<motion>
changes text in the direction of the motion - ci( change inside parentheses (see text object selection for more examples)
- x 删除字符
- dw 删除单词; D 删除到行尾; dd 删除整行
- d
<motion>
沿运动方向删除
- x delete char
- dw delete word; D delete to end of line; dd delete whole line
- d
<motion>
deletes in the direction of the motion
- yy 将行复制到粘贴缓冲区中; dd 将行剪切到粘贴缓冲区中
- p 在光标行下方粘贴缓冲区; P 在光标行上方粘贴缓冲区
- xp 交换两个字符( x 删除一个字符,然后 p 将其放回光标位置之后)
- yy copy line into paste buffer; dd cut line into paste buffer
- p paste buffer below cursor line; P paste buffer above cursor line
- xp swap two characters (x to delete one character, then p to put it back after the cursor position)
- v 可视块流; V 视觉界线; ^ V 可视块列
- 大多数运动命令将块扩展到新的光标位置
- o 将光标移动到块的另一端
- v visual block stream; V visual block line; ^V visual block column
- most motion commands extend the block to the new cursor position
- o moves the cursor to the other end of the block
- :%s/foo/bar/g 替换所有出现的"foo"到"bar"
- %是范围,它指示文件中的每一行 >
- /g是一个标志,用于更改一行中的所有匹配项,而不仅仅是第一个
- :%s/foo/bar/g substitute all occurrences of "foo" to "bar"
- % is a range that indicates every line in the file
- /g is a flag that changes all occurrences on a line instead of just the first one
- /向前搜索; ?向后搜索
- * 向前搜索光标下的单词; #向后搜索光标下方的单词
- n 相同方向的下一场比赛; N 相反方向的下一场比赛
- fx 转到下一个字符 x ; Fx 后退到前一个字符 x
- ; 再次沿相同方向移至相同字符; ,再次以相反的方向移至相同字符
- / search forward; ? search backward
- * search forward for word under cursor; # search backward for word under cursor
- n next match in same direction; N next match in opposite direction
- fx forward to next character x; Fx backward to previous character x
- ; move again to same character in same direction; , move again to same character in opposite direction
- :w 将文件写入磁盘
- :w
name
以name
的形式将文件写入磁盘
- ZZ 将文件写入磁盘并退出
- :n 编辑一个新文件; :n!,但不保存当前更改即可编辑新文件
- :q 退出编辑文件; :q!,不保存更改就退出编辑
- :e 再次编辑同一文件(如果在vim之外更改)
- :e.目录浏览器
- :w write file to disk
- :w
name
write file to disk asname
- ZZ write file to disk and quit
- :n edit a new file; :n! edit a new file without saving current changes
- :q quit editing a file; :q! quit editing without saving changes
- :e edit same file again (if changed outside vim)
- :e . directory explorer
- ^ Wn 新窗口
- ^ Wj 到下一个窗口; ^ Wk 直到上一个窗口
- ^ W _ 最大化当前窗口; ^ W = 使所有窗口大小相等
- ^ W + 增加窗口大小; ^ W-减小窗口大小
- ^Wn new window
- ^Wj down to next window; ^Wk up to previous window
- ^W_ maximise current window; ^W= make all windows equal size
- ^W+ increase window size; ^W- decrease window size
- %跳转到匹配的括号/中括号/大括号,或者如果已加载语言模块,则跳转到语言块
- gd 转到光标下的本地符号定义; ^ O 返回上一个位置
- ^] 跳转到全局符号的定义(需要
tags
文件); ^ T 返回上一个位置(保留任意堆栈的位置) - ^ N (在插入模式下)自动单词补全
- % jump to matching parenthesis/bracket/brace, or language block if language module loaded
- gd go to definition of local symbol under cursor; ^O return to previous position
- ^] jump to definition of global symbol (requires
tags
file); ^T return to previous position (arbitrary stack of positions maintained) - ^N (in insert mode) automatic word completion
Vim具有一些功能,可轻松突出显示从源代码管理中的基本版本更改的行.我创建了一个小vim脚本,它使此操作变得容易: http://github.com/ghewgill/vim-scmdiff
Vim has some features that make it easy to highlight lines that have been changed from a base version in source control. I have created a small vim script that makes this easy: http://github.com/ghewgill/vim-scmdiff
这篇关于最常用的vim命令/按键是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!