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!?
我是一名Ruby编程人员,试图从Textmate切换到MacVim,而我却遇到了麻烦,费力地浏览着VIM中可以做的事情的庞大列表,以及它们的所有按键。我厌倦了听到“你可以用“我”来插入文本,或附加的一个“文本字符后,或附加的一个“文本的末尾,或者……”我无法想象每个人都使用20个不同的按键导航文字,10左右键开始添加文本,18岁的方法直观地选择一个内在的块。或者你! ?
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.
我理想的备忘单是30-40个最常用的按键或命令,每个人每天都用它来编写代码,以及rubyists每天使用的绝对必需的插件和10个最常用的命令。从理论上讲,一旦我拥有了这一点,并且开始像我在Textmate中那样精通VIM,那么我就可以开始学习其他成千上万的VIM命令,这将使我更有效率。
Or, am I learning VIM the wrong way altogether?
或者,我是否完全错误地学习了VIM ?
10 个解决方案
#1
211
Here's a tip sheet I wrote up once, with the commands I actually use regularly:
这是我写过的一个提示表,我经常使用的命令是:
References
- vim documentation online
- vim文档在线
- advanced vim tips
- 先进的vim技巧
- more useful tips and graphical cheat sheet
- 更有用的提示和图形的备忘单。
General
- Nearly all commands can be preceded by a number for a repeat count. eg. 5dd delete 5 lines
- 几乎所有的命令都可以用一个数字进行重复计数。如。5 dd删除5行
-
<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
- :帮助帮助任何命令。
Navigation
- Cursor movement: ←h ↓j ↑k l→
- 光标移动: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)
- b背单词(通过标点符号);B背单词(按空格)
- e end word (by punctuation); E end word (by spaces)
- e end单词(通过标点符号);E结束字(按空格)
- 单词:下一个单词(通过标点符号);下一个单词(由空格)b背单词(用标点符号);B back word (by space) e end word(通过标点符号);E结束字(按空格)
- By line:
- 0 start of line; ^ first non-whitespace
- 0开始线;^第一个非空
- $ end of line
- 美元行结束
- 逐行:0开始行;^第一个非空行结束美元
- By paragraph:
- { previous blank line; } next blank line
- {前空行;}下一个空行
- 根据段落:{先前的空白行;}下一个空行
- By file:
- gg start of file; G end of file
- gg开始的文件;G文件结束
- 123G go to specific line number
- 123G到特定的行号。
- 档案:gg开始档案;文件123G的G端到特定的行号。
- By marker:
- mx set mark x; 'x go to mark x
- mx设置标记x;x去标记x。
- '. go to position of last edit
- ”。进入最后编辑的位置。
- ' ' go back to last point before jump
- 回到最后一点,然后再跳。
- 标记:mx set mark x;“x去标记x”。进入最后一个编辑的位置,在跳转前回到最后一个点。
- Scrolling:
- ^F forward full screen; ^B backward full screen
- ^ F向前全屏;^ B向后全屏
- ^D down half screen; ^U up half screen
- ^ D屏幕一半;^你一半的屏幕
- ^E scroll one line up; ^Y scroll one line down
- ^ E滚动一行;^ Y滚动一行
- zz centre cursor line
- zz中心光标线
- 向前滚动:^ F全屏;^ B向后全屏^ D屏幕一半;^ ^你一半屏幕E滚动一行;^ Y zz中心鼠标滚动一行
Editing
- u undo; ^R redo
- 你撤销;^ R重做
- . repeat last editing command
- 。重复最后一次编辑命令
Inserting
All insertion commands are terminated with <Esc>
to return to command mode.
所有插入命令都以
- 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
- o打开下面的新线路;O打开上面的新行。
Changing
All change commands except r and R are terminated with <Esc>
to return to command mode.
除r和r之外的所有更改命令都以
- r replace single character; R replace multiple characters
- r代替单个字符;R取代多个字符
- s change single character
- 年代改变单个字符
- cw change word; C change to end of line; cc change whole line
- 连续波改变词;C更改为行尾;cc改变整个行
-
c
<motion>
changes text in the direction of the motion -
c
改变了文本的运动方向。 - ci( change inside parentheses (see text object selection for more examples)
- ci(在括号内更改(更多例子参见文本对象选择)
Deleting
- x delete char
- x删除字符
- dw delete word; D delete to end of line; dd delete whole line
- dw删除词;D delete to end of line;dd删除整行
-
d
<motion>
deletes in the direction of the motion -
d
在运动的方向上删除。
Cut and paste
- yy copy line into paste buffer; dd cut line into paste buffer
- yy复制线到粘贴缓冲区;dd剪切行到粘贴缓冲区。
- p paste buffer below cursor line; P paste buffer above cursor line
- p粘贴缓冲区低于光标线;P粘贴缓冲区在光标线上。
- xp swap two characters (x to delete one character, then p to put it back after the cursor position)
- xp交换两个字符(x删除一个字符,然后p将其放回光标位置)
Blocks
-
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
- o将光标移到块的另一端。
- v视觉块流;V视觉块线;大多数动作命令将块扩展到新的光标位置o将光标移到块的另一端。
- d or x cut block into paste buffer
- 将d或x切割块放入粘贴缓冲区。
- y copy block into paste buffer
- 复制块到粘贴缓冲区。
- > indent block; < unindent block
- >块缩进;< unindent块
- gv reselect last visual block
- gv重新选择最后一个可视块。
Global
-
:%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
- g是一个标志,它可以改变一行中的所有事件,而不是第一个。
- :%s/foo/bar/g将所有出现的“foo”替换为“bar”%是一个范围,表示文件/g中的每一行都是一个标志,它会改变一行中的所有事件,而不是第一个。
Searching
- / 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
- n次匹配方向相同;下一场比赛向相反的方向。
- fx forward to next character x; Fx backward to previous character x
- fx转发到下一个角色x;返回到前一个字符x。
- ; move again to same character in same direction; , move again to same character in opposite direction
- ;再次向同一方向移动;,再次向相反的方向移动。
Files
- :w write file to disk
- :w写入文件到磁盘。
-
:w
name
write file to disk asname
- :将文件名写入磁盘作为名称。
- ZZ write file to disk and quit
- ZZ写入磁盘并退出。
- :n edit a new file; :n! edit a new file without saving current changes
- :n编辑新文件;:n !编辑新文件而不保存当前更改。
- :q quit editing a file; :q! quit editing without saving changes
- :q退出编辑文件;:问!退出编辑而不保存更改。
- :e edit same file again (if changed outside vim)
- :e编辑同一个文件(如果在vim外部更改)
- :e . directory explorer
- :e。目录浏览器
Windows
- ^Wn new window
- ^ Wn新窗口
- ^Wj down to next window; ^Wk up to previous window
- ^ Wj到下一个窗口;
- ^W_ maximise current window; ^W= make all windows equal size
- ^ W_最大化当前窗口;^ W =让所有窗口大小相等
- ^W+ increase window size; ^W- decrease window size
- ^ W +增加窗口大小;^ W -减少窗口大小
Source Navigation
- % 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
- gd在光标下定义本地符号;^ O回到先前的位置
-
^] jump to definition of global symbol (requires
tags
file); ^T return to previous position (arbitrary stack of positions maintained) - ^)跳转到全局符号的定义(需要标记文件);^ T回到先前的位置(任意堆栈的位置保持)
- ^N (in insert mode) automatic word completion
- ^ N(在插入模式)自动完成
Show local changes
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具有一些特性,可以很容易地突出显示已从源代码控制的基本版本更改的行。我创建了一个小的vim脚本,它使这个简单:http://github.com/ghewgill/vim-scmdiff。
#2
19
http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html
http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html
This is the greatest thing ever for learning VIM.
这是学习VIM最伟大的事情。
#4
3
What most people do is start out with the bare basics, like maybe i, yw, yy, and p. You can continue to use arrow keys to move around, selecting text with the mouse, using the menus, etc. Then when something is slowing you down, you look up the faster way to do it, and gradually add more and more commands. You might learn one new command per day for a while, then it will trickle to one per week. You'll feel fairly productive in a month. After a year you will have a pretty solid repertoire, and after 2-3 years you won't even consciously think what your fingers are typing, and it will look weird if you have to spell it out for someone. I learned vi in 1993 and still pick up 2 or 3 new commands a year.
大多数人做的就是从最基本的开始,比如我,yw,yy,p。你可以继续使用箭头键移动,用鼠标选择文本,使用菜单,等等。当你正在放缓下来,你查找速度的方法,并逐步添加越来越多的命令。你可以每天学习一个新的命令,然后它会慢慢地变成一个星期。一个月后你会觉得很有成效。一年后,你会有一个非常扎实的技能,2-3年后,你甚至不会有意识地去思考你的手指在打什么,如果你必须把它拼出来,它看起来会很奇怪。我在1993年学会了vi,每年仍能获得2到3个新的命令。
#5
3
Have you run through Vim's built-in tutorial? If not, drop to the command-line and type vimtutor
. It's a great way to learn the initial commands.
你是否浏览过Vim的内置教程?如果没有,请访问命令行和类型vimtutor。这是学习初始命令的好方法。
Vim has an incredible amount of flexibility and power and, if you're like most vim users, you'll learn a lot of new commands and forget old ones, then relearn them. The built-in help is good and worthy of periodic browsing to learn new stuff.
Vim具有不可思议的灵活性和强大的力量,如果您像大多数Vim用户一样,您将学习许多新的命令,并且忘记旧的命令,然后重新学习它们。内置的帮助是好的,值得定期浏览来学习新东西。
There are several good FAQs and cheatsheets for vim on the internet. I'd recommend searching for vim + faq
and vim + cheatsheet
. Cheat-Sheets.org#vim is a good source, as is Vim Tips wiki.
在互联网上有很多关于vim的faq和cheatsheets。我建议搜索vim + faq和vim + cheatsheet。org#vim是一个很好的来源,vim提示wiki。
#6
3
@Greg Hewgill's cheatsheet is very good. I started my switch from TextMate a few months ago. Now I'm as productive as I was with TM and constantly amazed by Vim's power.
@Greg Hewgill的cheatsheet非常好。几个月前,我从TextMate开始了我的转换。现在我和TM一样富有成效,并且经常被Vim的力量所震撼。
Here is how I switched. Maybe it can be useful to you.
这里是我的切换方式。也许它对你有用。
Grosso modo, I don't think it's a good idea to do a radical switch. Vim is very different and it's best to go progressively.
格罗索·莫多,我不认为做一个激进的转变是个好主意。Vim是非常不同的,最好是渐进的。
And to answer your subquestion, yes, I use all of iaIAoO
everyday to enter insert mode. It certainly seems weird at first but you don't really think about it after a while.
为了回答你的子问题,是的,我每天都用iaIAoO来进入插入模式。一开始肯定很奇怪,但过了一段时间后你就不会再想它了。
Some commands incredibly useful for any programming related tasks:
对于任何与编程相关的任务,有些命令非常有用:
-
r
andR
to replace characters - r和r替换字符。
-
<C-a>
and<C-x>
to increase and decrease numbers -
和 增加和减少数字。 -
cit
to change the content of an HTML tag, and its variants (cat
,dit
,dat
,ci(
, etc.) - 更改HTML标记的内容及其变体(cat、dit、dat、ci(等))
-
<C-x><C-o>
(mapped to,,
) for omnicompletion -
(映射到,)用于omnicompletion。 - visual block selection with
<C-v>
-
带有
的可视块选择。 - and so on…
- 等等……
Once you are accustomed to the Vim way it becomes really hard to not hit o
or x
all the time when editing text in some other editor or textfield.
一旦您习惯了Vim方式,在其他编辑器或textfield编辑文本的时候,就很难不使用o或x了。
#7
2
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!?
我无法想象每个人都使用20个不同的按键来导航文本,10个左右键开始添加文本,还有18种视觉选择一个内块的方法。或者你! ?
I do.
我做的事。
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.
从理论上讲,一旦我拥有了这一点,并且开始像我在Textmate中那样精通VIM,那么我就可以开始学习其他成千上万的VIM命令,这将使我更有效率。
That's the right way to do it. Start with basic commands and then pick up ones that improve your productivity. I like following this blog for tips on how to improve my productivity with vim.
这是正确的方法。从基本的命令开始,然后选择那些能提高你的效率的命令。我喜欢跟随这个博客,了解如何用vim来提高我的工作效率。
#8
2
tuxfiles.org holds a pretty good cheat sheet. I think there are a couple of points to learning the commands:
org拥有一个很好的备忘单。我认为学习这些命令有几个要点:
- Read the cheat sheet regularly. Don't worry about using all of them, or remembering all the keys, just know that the command exists. Look up the command and use it when you find yourself doing something repetitive.
- 定期阅读备忘单。不要担心使用它们,或者记住所有的键,只需要知道命令的存在。当你发现自己在做一些重复的事情时,请查找命令并使用它。
- If you find yourself doing something regularly (like deleting an entire line after a particular character
d$
), go a quick google search to see if you can find a command for it. - 如果你发现自己有规律地做某事(比如在某个特定的字符d后删除一整行),那么就快速搜索一下谷歌,看看你是否能找到它的命令。
- Write down commands you think you'll find useful and keep that list where you can see it while you're writing your code. I would argue against printing something out and instead encourage you to use post it notes for just a few commands at a time.
- 写下你认为你会发现有用的命令并把它保存在你写代码的地方。我反对打印一些东西,而是鼓励你每次只使用几个命令。
- If possible, watch other programmers use vim, and ask them what commands they are using as you see them do something interesting.
- 如果可能,观察其他程序员使用vim,并询问他们使用什么命令,因为您看到他们做了一些有趣的事情。
Besides these tips, there are some basic concepts you should understand.
除了这些建议,还有一些基本的概念你应该了解。
- vim will use the same character to represent the same function. For example, to delete a line after a character use
d$
. To highlight a line after a particular character usev$
. So notice that$
indicates you will be doing something to the end of the line from where your cursor currently is. - vim将使用相同的字符来表示相同的函数。例如,在字符使用d$之后删除一行。在特定字符使用v$后突出一行。请注意,$表示您将从当前光标所在的位置执行某些操作。
-
u
is undo, andctrl+r
is redo. - u是撤销,ctrl+r是重做。
- putting a number in front of a command will execute it repeatedly.
3dd
will delete the line your cursor is on and the two lines that follow, similarly3yy
will copy the line your cursor is on and the two lines that follow. - 在命令前面加上一个数字将会重复执行。3dd将会删除你的光标所在的行和后面的两条线,类似的3yy将复制你的光标所在的行和后面的两条线。
- understand how to navigate through the buffers use
:ls
to list the buffers, and:bn
,:bp
to cycle through them. - 了解如何在缓冲区中导航:ls列出缓冲区,以及:bn:bp在它们之间循环。
-
read through the tutorial found in
:help
This is probably the best way to 'learn the ropes', and the rest of the commands you will learn through usage. - 阅读下面的教程:help This is probably the best way to“learn the ropes”,and the rest of the commands you will learn through usage。
#9
2
Put this in your .bashrc to open vim with last edited file at last edited line
将这个放在.bashrc中,在最后编辑的行中使用最后编辑的文件打开vim。
alias vil="vim +\"'\"0"
#10
1
Go to Efficient Editing with vim and learn what you need to get started. Not everything on that page is essential starting off, so cherry pick what you want.
使用vim进行高效的编辑,并学习您需要启动的内容。不是所有的东西都是必须的,所以樱桃选择你想要的。
From there, use vim for everything. "hjkl", "y", and "p" will get you a long way, even if it's not the most efficient way. When you come up against a task for which you don't know the magic key to do it efficiently (or at all), and you find yourself doing it more than a few times, go look it up. Little by little it will become second nature.
从那里,一切都用vim。“hjkl”、“y”和“p”会让你走得更远,即使这不是最有效的方式。当你遇到一个你不知道如何有效地完成任务的任务时,你会发现自己做了不止几次,去查一下。慢慢地,它将变成第二天性。
I found vim daunting many moons ago (back when it didn't have the "m" on the end), but it only took about a week of steady use to get efficient. I still find it the quickest editor in which to get stuff done.
我发现许多卫星都是令人望而生畏的(当它最后没有“m”的时候),但它只花了一个星期的稳定使用来提高效率。我仍然觉得它是最快的编辑器。
#1
211
Here's a tip sheet I wrote up once, with the commands I actually use regularly:
这是我写过的一个提示表,我经常使用的命令是:
References
- vim documentation online
- vim文档在线
- advanced vim tips
- 先进的vim技巧
- more useful tips and graphical cheat sheet
- 更有用的提示和图形的备忘单。
General
- Nearly all commands can be preceded by a number for a repeat count. eg. 5dd delete 5 lines
- 几乎所有的命令都可以用一个数字进行重复计数。如。5 dd删除5行
-
<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
- :帮助帮助任何命令。
Navigation
- Cursor movement: ←h ↓j ↑k l→
- 光标移动: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)
- b背单词(通过标点符号);B背单词(按空格)
- e end word (by punctuation); E end word (by spaces)
- e end单词(通过标点符号);E结束字(按空格)
- 单词:下一个单词(通过标点符号);下一个单词(由空格)b背单词(用标点符号);B back word (by space) e end word(通过标点符号);E结束字(按空格)
- By line:
- 0 start of line; ^ first non-whitespace
- 0开始线;^第一个非空
- $ end of line
- 美元行结束
- 逐行:0开始行;^第一个非空行结束美元
- By paragraph:
- { previous blank line; } next blank line
- {前空行;}下一个空行
- 根据段落:{先前的空白行;}下一个空行
- By file:
- gg start of file; G end of file
- gg开始的文件;G文件结束
- 123G go to specific line number
- 123G到特定的行号。
- 档案:gg开始档案;文件123G的G端到特定的行号。
- By marker:
- mx set mark x; 'x go to mark x
- mx设置标记x;x去标记x。
- '. go to position of last edit
- ”。进入最后编辑的位置。
- ' ' go back to last point before jump
- 回到最后一点,然后再跳。
- 标记:mx set mark x;“x去标记x”。进入最后一个编辑的位置,在跳转前回到最后一个点。
- Scrolling:
- ^F forward full screen; ^B backward full screen
- ^ F向前全屏;^ B向后全屏
- ^D down half screen; ^U up half screen
- ^ D屏幕一半;^你一半的屏幕
- ^E scroll one line up; ^Y scroll one line down
- ^ E滚动一行;^ Y滚动一行
- zz centre cursor line
- zz中心光标线
- 向前滚动:^ F全屏;^ B向后全屏^ D屏幕一半;^ ^你一半屏幕E滚动一行;^ Y zz中心鼠标滚动一行
Editing
- u undo; ^R redo
- 你撤销;^ R重做
- . repeat last editing command
- 。重复最后一次编辑命令
Inserting
All insertion commands are terminated with <Esc>
to return to command mode.
所有插入命令都以
- 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
- o打开下面的新线路;O打开上面的新行。
Changing
All change commands except r and R are terminated with <Esc>
to return to command mode.
除r和r之外的所有更改命令都以
- r replace single character; R replace multiple characters
- r代替单个字符;R取代多个字符
- s change single character
- 年代改变单个字符
- cw change word; C change to end of line; cc change whole line
- 连续波改变词;C更改为行尾;cc改变整个行
-
c
<motion>
changes text in the direction of the motion -
c
改变了文本的运动方向。 - ci( change inside parentheses (see text object selection for more examples)
- ci(在括号内更改(更多例子参见文本对象选择)
Deleting
- x delete char
- x删除字符
- dw delete word; D delete to end of line; dd delete whole line
- dw删除词;D delete to end of line;dd删除整行
-
d
<motion>
deletes in the direction of the motion -
d
在运动的方向上删除。
Cut and paste
- yy copy line into paste buffer; dd cut line into paste buffer
- yy复制线到粘贴缓冲区;dd剪切行到粘贴缓冲区。
- p paste buffer below cursor line; P paste buffer above cursor line
- p粘贴缓冲区低于光标线;P粘贴缓冲区在光标线上。
- xp swap two characters (x to delete one character, then p to put it back after the cursor position)
- xp交换两个字符(x删除一个字符,然后p将其放回光标位置)
Blocks
-
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
- o将光标移到块的另一端。
- v视觉块流;V视觉块线;大多数动作命令将块扩展到新的光标位置o将光标移到块的另一端。
- d or x cut block into paste buffer
- 将d或x切割块放入粘贴缓冲区。
- y copy block into paste buffer
- 复制块到粘贴缓冲区。
- > indent block; < unindent block
- >块缩进;< unindent块
- gv reselect last visual block
- gv重新选择最后一个可视块。
Global
-
:%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
- g是一个标志,它可以改变一行中的所有事件,而不是第一个。
- :%s/foo/bar/g将所有出现的“foo”替换为“bar”%是一个范围,表示文件/g中的每一行都是一个标志,它会改变一行中的所有事件,而不是第一个。
Searching
- / 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
- n次匹配方向相同;下一场比赛向相反的方向。
- fx forward to next character x; Fx backward to previous character x
- fx转发到下一个角色x;返回到前一个字符x。
- ; move again to same character in same direction; , move again to same character in opposite direction
- ;再次向同一方向移动;,再次向相反的方向移动。
Files
- :w write file to disk
- :w写入文件到磁盘。
-
:w
name
write file to disk asname
- :将文件名写入磁盘作为名称。
- ZZ write file to disk and quit
- ZZ写入磁盘并退出。
- :n edit a new file; :n! edit a new file without saving current changes
- :n编辑新文件;:n !编辑新文件而不保存当前更改。
- :q quit editing a file; :q! quit editing without saving changes
- :q退出编辑文件;:问!退出编辑而不保存更改。
- :e edit same file again (if changed outside vim)
- :e编辑同一个文件(如果在vim外部更改)
- :e . directory explorer
- :e。目录浏览器
Windows
- ^Wn new window
- ^ Wn新窗口
- ^Wj down to next window; ^Wk up to previous window
- ^ Wj到下一个窗口;
- ^W_ maximise current window; ^W= make all windows equal size
- ^ W_最大化当前窗口;^ W =让所有窗口大小相等
- ^W+ increase window size; ^W- decrease window size
- ^ W +增加窗口大小;^ W -减少窗口大小
Source Navigation
- % 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
- gd在光标下定义本地符号;^ O回到先前的位置
-
^] jump to definition of global symbol (requires
tags
file); ^T return to previous position (arbitrary stack of positions maintained) - ^)跳转到全局符号的定义(需要标记文件);^ T回到先前的位置(任意堆栈的位置保持)
- ^N (in insert mode) automatic word completion
- ^ N(在插入模式)自动完成
Show local changes
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具有一些特性,可以很容易地突出显示已从源代码控制的基本版本更改的行。我创建了一个小的vim脚本,它使这个简单:http://github.com/ghewgill/vim-scmdiff。
#2
19
http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html
http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html
This is the greatest thing ever for learning VIM.
这是学习VIM最伟大的事情。
#3
#4
3
What most people do is start out with the bare basics, like maybe i, yw, yy, and p. You can continue to use arrow keys to move around, selecting text with the mouse, using the menus, etc. Then when something is slowing you down, you look up the faster way to do it, and gradually add more and more commands. You might learn one new command per day for a while, then it will trickle to one per week. You'll feel fairly productive in a month. After a year you will have a pretty solid repertoire, and after 2-3 years you won't even consciously think what your fingers are typing, and it will look weird if you have to spell it out for someone. I learned vi in 1993 and still pick up 2 or 3 new commands a year.
大多数人做的就是从最基本的开始,比如我,yw,yy,p。你可以继续使用箭头键移动,用鼠标选择文本,使用菜单,等等。当你正在放缓下来,你查找速度的方法,并逐步添加越来越多的命令。你可以每天学习一个新的命令,然后它会慢慢地变成一个星期。一个月后你会觉得很有成效。一年后,你会有一个非常扎实的技能,2-3年后,你甚至不会有意识地去思考你的手指在打什么,如果你必须把它拼出来,它看起来会很奇怪。我在1993年学会了vi,每年仍能获得2到3个新的命令。
#5
3
Have you run through Vim's built-in tutorial? If not, drop to the command-line and type vimtutor
. It's a great way to learn the initial commands.
你是否浏览过Vim的内置教程?如果没有,请访问命令行和类型vimtutor。这是学习初始命令的好方法。
Vim has an incredible amount of flexibility and power and, if you're like most vim users, you'll learn a lot of new commands and forget old ones, then relearn them. The built-in help is good and worthy of periodic browsing to learn new stuff.
Vim具有不可思议的灵活性和强大的力量,如果您像大多数Vim用户一样,您将学习许多新的命令,并且忘记旧的命令,然后重新学习它们。内置的帮助是好的,值得定期浏览来学习新东西。
There are several good FAQs and cheatsheets for vim on the internet. I'd recommend searching for vim + faq
and vim + cheatsheet
. Cheat-Sheets.org#vim is a good source, as is Vim Tips wiki.
在互联网上有很多关于vim的faq和cheatsheets。我建议搜索vim + faq和vim + cheatsheet。org#vim是一个很好的来源,vim提示wiki。
#6
3
@Greg Hewgill's cheatsheet is very good. I started my switch from TextMate a few months ago. Now I'm as productive as I was with TM and constantly amazed by Vim's power.
@Greg Hewgill的cheatsheet非常好。几个月前,我从TextMate开始了我的转换。现在我和TM一样富有成效,并且经常被Vim的力量所震撼。
Here is how I switched. Maybe it can be useful to you.
这里是我的切换方式。也许它对你有用。
Grosso modo, I don't think it's a good idea to do a radical switch. Vim is very different and it's best to go progressively.
格罗索·莫多,我不认为做一个激进的转变是个好主意。Vim是非常不同的,最好是渐进的。
And to answer your subquestion, yes, I use all of iaIAoO
everyday to enter insert mode. It certainly seems weird at first but you don't really think about it after a while.
为了回答你的子问题,是的,我每天都用iaIAoO来进入插入模式。一开始肯定很奇怪,但过了一段时间后你就不会再想它了。
Some commands incredibly useful for any programming related tasks:
对于任何与编程相关的任务,有些命令非常有用:
-
r
andR
to replace characters - r和r替换字符。
-
<C-a>
and<C-x>
to increase and decrease numbers -
和 增加和减少数字。 -
cit
to change the content of an HTML tag, and its variants (cat
,dit
,dat
,ci(
, etc.) - 更改HTML标记的内容及其变体(cat、dit、dat、ci(等))
-
<C-x><C-o>
(mapped to,,
) for omnicompletion -
(映射到,)用于omnicompletion。 - visual block selection with
<C-v>
-
带有
的可视块选择。 - and so on…
- 等等……
Once you are accustomed to the Vim way it becomes really hard to not hit o
or x
all the time when editing text in some other editor or textfield.
一旦您习惯了Vim方式,在其他编辑器或textfield编辑文本的时候,就很难不使用o或x了。
#7
2
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!?
我无法想象每个人都使用20个不同的按键来导航文本,10个左右键开始添加文本,还有18种视觉选择一个内块的方法。或者你! ?
I do.
我做的事。
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.
从理论上讲,一旦我拥有了这一点,并且开始像我在Textmate中那样精通VIM,那么我就可以开始学习其他成千上万的VIM命令,这将使我更有效率。
That's the right way to do it. Start with basic commands and then pick up ones that improve your productivity. I like following this blog for tips on how to improve my productivity with vim.
这是正确的方法。从基本的命令开始,然后选择那些能提高你的效率的命令。我喜欢跟随这个博客,了解如何用vim来提高我的工作效率。
#8
2
tuxfiles.org holds a pretty good cheat sheet. I think there are a couple of points to learning the commands:
org拥有一个很好的备忘单。我认为学习这些命令有几个要点:
- Read the cheat sheet regularly. Don't worry about using all of them, or remembering all the keys, just know that the command exists. Look up the command and use it when you find yourself doing something repetitive.
- 定期阅读备忘单。不要担心使用它们,或者记住所有的键,只需要知道命令的存在。当你发现自己在做一些重复的事情时,请查找命令并使用它。
- If you find yourself doing something regularly (like deleting an entire line after a particular character
d$
), go a quick google search to see if you can find a command for it. - 如果你发现自己有规律地做某事(比如在某个特定的字符d后删除一整行),那么就快速搜索一下谷歌,看看你是否能找到它的命令。
- Write down commands you think you'll find useful and keep that list where you can see it while you're writing your code. I would argue against printing something out and instead encourage you to use post it notes for just a few commands at a time.
- 写下你认为你会发现有用的命令并把它保存在你写代码的地方。我反对打印一些东西,而是鼓励你每次只使用几个命令。
- If possible, watch other programmers use vim, and ask them what commands they are using as you see them do something interesting.
- 如果可能,观察其他程序员使用vim,并询问他们使用什么命令,因为您看到他们做了一些有趣的事情。
Besides these tips, there are some basic concepts you should understand.
除了这些建议,还有一些基本的概念你应该了解。
- vim will use the same character to represent the same function. For example, to delete a line after a character use
d$
. To highlight a line after a particular character usev$
. So notice that$
indicates you will be doing something to the end of the line from where your cursor currently is. - vim将使用相同的字符来表示相同的函数。例如,在字符使用d$之后删除一行。在特定字符使用v$后突出一行。请注意,$表示您将从当前光标所在的位置执行某些操作。
-
u
is undo, andctrl+r
is redo. - u是撤销,ctrl+r是重做。
- putting a number in front of a command will execute it repeatedly.
3dd
will delete the line your cursor is on and the two lines that follow, similarly3yy
will copy the line your cursor is on and the two lines that follow. - 在命令前面加上一个数字将会重复执行。3dd将会删除你的光标所在的行和后面的两条线,类似的3yy将复制你的光标所在的行和后面的两条线。
- understand how to navigate through the buffers use
:ls
to list the buffers, and:bn
,:bp
to cycle through them. - 了解如何在缓冲区中导航:ls列出缓冲区,以及:bn:bp在它们之间循环。
-
read through the tutorial found in
:help
This is probably the best way to 'learn the ropes', and the rest of the commands you will learn through usage. - 阅读下面的教程:help This is probably the best way to“learn the ropes”,and the rest of the commands you will learn through usage。
#9
2
Put this in your .bashrc to open vim with last edited file at last edited line
将这个放在.bashrc中,在最后编辑的行中使用最后编辑的文件打开vim。
alias vil="vim +\"'\"0"
#10
1
Go to Efficient Editing with vim and learn what you need to get started. Not everything on that page is essential starting off, so cherry pick what you want.
使用vim进行高效的编辑,并学习您需要启动的内容。不是所有的东西都是必须的,所以樱桃选择你想要的。
From there, use vim for everything. "hjkl", "y", and "p" will get you a long way, even if it's not the most efficient way. When you come up against a task for which you don't know the magic key to do it efficiently (or at all), and you find yourself doing it more than a few times, go look it up. Little by little it will become second nature.
从那里,一切都用vim。“hjkl”、“y”和“p”会让你走得更远,即使这不是最有效的方式。当你遇到一个你不知道如何有效地完成任务的任务时,你会发现自己做了不止几次,去查一下。慢慢地,它将变成第二天性。
I found vim daunting many moons ago (back when it didn't have the "m" on the end), but it only took about a week of steady use to get efficient. I still find it the quickest editor in which to get stuff done.
我发现许多卫星都是令人望而生畏的(当它最后没有“m”的时候),但它只花了一个星期的稳定使用来提高效率。我仍然觉得它是最快的编辑器。