最常用的 vim 命令/按键是什么?
我是一名 Ruby 编程人员,试图从 Textmate 切换到 MacVim,但我在遍历 VIM 中可以执行的操作的庞大列表以及它们的所有按键时遇到了麻烦。我厌倦了听到“你可以使用‘I’插入文本,或‘a’在字符后附加文本,或‘A’在行尾附加文本,或者......”我无法想象每个人都使用 20 个不同的按键来导航文本,使用 10 个左右的按键来开始添加文本,以及 18 种方式来直观地选择内部块。还是你呢!?
我理想的备忘单是每个人每天用来编写代码的 30-40 个最常用的按键或命令,以及 Ruby 开发者每天使用的绝对必要的插件和 10 个最常用的命令。理论上,一旦我掌握了这些命令并开始像使用 Textmate 一样精通 VIM,那么我就可以开始学习数千个其他 VIM 命令,这将使我更多高效的。
或者,我学习 VIM 的方式完全错误吗?
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!?
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.
Or, am I learning VIM the wrong way altogether?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
这是我曾经写过的提示表,其中包含我实际经常使用的命令:
参考文献
概述
让您退出任何模式并返回命令模式导航
编辑
插入
所有插入命令均以
终止以返回到命令模式。更改
更改移动方向上的文本删除
<; Motion>
沿运动方向删除 将yy 复制行剪切并粘贴
块
全局
搜索
文件
名称
将文件写入disk asname
Windows
源导航
tags
文件); ^T 返回到上一个位置(保留任意位置堆栈)显示本地更改
Vim 有一些功能可以轻松突出显示已从源代码管理中的基本版本更改的行。我创建了一个小 vim 脚本,使这变得简单: http://github.com/ghewgill/vim-scmdiff
Here's a tip sheet I wrote up once, with the commands I actually use regularly:
References
General
<Esc>
gets you out of any mode and back to command modeNavigation
Editing
Inserting
All insertion commands are terminated with
<Esc>
to return to command mode.Changing
<motion>
changes text in the direction of the motionDeleting
<motion>
deletes in the direction of the motionCut and paste
Blocks
Global
Searching
Files
name
write file to disk asname
Windows
Source Navigation
tags
file); ^T return to previous position (arbitrary stack of positions maintained)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
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 备忘单:
Here is a great cheat sheet for vim:
您学过 Vim 的内置教程吗?如果没有,请转到命令行并输入
vimtutor
。这是学习初始命令的好方法。Vim 具有令人难以置信的灵活性和强大功能,如果您像大多数 vim 用户一样,您将学习很多新命令并忘记旧命令,然后重新学习它们。内置的帮助很好,值得定期浏览以学习新东西。
互联网上有一些很好的 vim 常见问题解答和备忘单。我建议搜索
vim + faq
和vim + cheatsheet
。 Cheat-Sheets.org#vim 是一个很好的来源,Vim 提示 wiki。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 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.
There are several good FAQs and cheatsheets for vim on the internet. I'd recommend searching for
vim + faq
andvim + cheatsheet
. Cheat-Sheets.org#vim is a good source, as is Vim Tips wiki.tuxfiles.org 拥有一份非常好的备忘单。我认为学习这些命令有几个要点:
d$
之后的整行),请快速进行 google 搜索,看看是否可以找到相应的命令。除了这些提示之外,您还应该了解一些基本概念。
d$
。要突出显示特定字符后的一行,请使用v$
。因此,请注意$
表示您将从光标当前所在位置开始执行某些操作,直至行尾。u
是撤消,ctrl+r
是重做。3dd
将删除光标所在的行及其后面的两行,类似地3yy
将复制光标所在的行及其后面的两行。:ls
列出缓冲区,并使用:bn
、:bp
循环浏览缓冲区。:help中的教程
这可能是“熟悉诀窍”的最佳方式,其余命令您将通过使用来学习。tuxfiles.org holds a pretty good cheat sheet. I think there are a couple of points to learning the commands:
d$
), go a quick google search to see if you can find a command for it.Besides these tips, there are some basic concepts you should understand.
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.u
is undo, andctrl+r
is redo.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.:ls
to list the buffers, and:bn
,:bp
to cycle through them.:help
This is probably the best way to 'learn the ropes', and the rest of the commands you will learn through usage.大多数人所做的都是从最基本的开始,例如 i、yw、yy 和 p 。您可以继续使用箭头键四处移动,用鼠标选择文本,使用菜单等。然后,当某些事情拖慢您的速度时,您会寻找更快的方法来完成它,并逐渐添加越来越多的命令。您可能会在一段时间内每天学习一个新命令,然后逐渐增加到每周一个。一个月后你会感觉相当有成效。一年后,你就会拥有相当扎实的曲目,两三年后,你甚至不会有意识地思考你的手指在打字什么,如果你必须为别人拼写出来,那会看起来很奇怪。我在 1993 年学习了 vi,每年仍然学习 2 到 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.
@Greg Hewgill 的备忘单非常好。几个月前我开始从 TextMate 转向。现在我的工作效率就像使用 TM 时一样,并且不断对 Vim 的强大功能感到惊讶。
这是我是如何切换的。也许它对你有用。
Grosso modo,我认为进行彻底的转变不是一个好主意。 Vim 非常不同,最好循序渐进。
为了回答你的子问题,是的,我每天都使用 iaIAoO 的所有内容来进入插入模式。一开始这确实看起来很奇怪,但过了一段时间你就不会真正考虑它了。
一些命令对于任何编程相关任务都非常有用:
r
和R
用于替换字符
和cit
更改 HTML 标记的内容及其变体(cat
、dit
、dat
、ci(
等)
(映射到,,
)用于全能补全
进行块选择一旦你习惯了 Vim 的方式,就很难不敲
o
或x
在其他编辑器或文本字段中编辑文本时始终如此。@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.
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.
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.Some commands incredibly useful for any programming related tasks:
r
andR
to replace characters<C-a>
and<C-x>
to increase and decrease numberscit
to change the content of an HTML tag, and its variants (cat
,dit
,dat
,ci(
, etc.)<C-x><C-o>
(mapped to,,
) for omnicompletion<C-v>
Once you are accustomed to the Vim way it becomes really hard to not hit
o
orx
all the time when editing text in some other editor or textfield.我愿意。
这是正确的做法。从基本命令开始,然后选择可以提高工作效率的命令。我喜欢关注此博客,获取有关如何使用 vim 提高工作效率的提示。
I do.
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 进行高效编辑 并了解入门所需的内容。并非该页面上的所有内容都是必不可少的,因此请挑选您想要的内容。
从那里开始,使用 vim 完成所有事情。 “hjkl”、“y”和“p”会让你走得很远,即使这不是最有效的方法。当你遇到一项任务,而你不知道有效(或根本不知道)完成它的秘诀时,并且你发现自己已经做了多次,那就去查一下。渐渐地,它将成为第二天性。
很多年前我就发现 vim 令人望而生畏(当时它的末尾还没有“m”),但只需要大约一周的稳定使用就可以提高效率。我仍然发现它是完成工作最快的编辑器。
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.
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.
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.
将其放入 .bashrc 中,以在最后编辑的行中使用上次编辑的文件打开 vim
Put this in your .bashrc to open vim with last edited file at last edited line