:global/test/substitute/^/#/ 或 :g/ test/s/^/#/ 将搜索包含短语 test 的行,并通过替换正则表达式锚点 ^ (beginning-of-行)并带有符号#。
您还可以通过将搜索动作 /pattern 或 ?pattern 作为范围传递来做一些很酷的事情:
:?test?move . 向后搜索包含 test 的行,并将其移动到文件
:/test/copy 中的当前位置。 向前搜索包含 test 的行,并将其复制到文件中的当前位置
祝你好运,祝学习 Vim 愉快!
Note that I don't use Visual Studio, and know little about the available features in it. The following are examples of what I find useful in Vim, not a list of missing features in Visual Studio.
Macros
It's easy to create macros for complex (but repetitive) operations. To illustrate with a simple example, let's say we start with:
Line1 Line2 Line3 Line4 Line5
Now we want to envelop each line in a print(""); statement. Place the cursor on the first line, and enter:
qx to start recording a macro to the register x
Shift+Iprint("Esc to insert text at the beginning of the line
Shift+A");Esc to append text at the end of the line
j to go down one line
q to stop recording the macro
4@x to execute the macro in register x 4 times
See :help complex-repeat for more info on Vim macros.
Text objects
Note that this is one of the improvements Vim has over the traditional Vi. If it doesn't work, you're probably running in Vi compatibility mode; use :set nocompatible to enable the full functionality of Vim.
Text objects allow you to easily select regions of text. Let's say we start with the following text, and place the cursor on some text:
<b><i>some text</i></b>
Now we want to delete everything between <i> and </i>. This can be done by simply typing the command dit (d'elete i'nner t'ag)! Or if we want to include the tags themselves in our selection, use dat (d'elete at'ag). To delete everything inside the <b> tags, use d2it (d'elete twoi'nner t'ags).
You can similarly use daw (delete a word), dap (delete a paragraph), di" (delete inside double-quotes), etc; see :help text-objects for the complete list.
Another useful example of text objects:
v2ap"+y
v toggles visual mode. This makes it easier to see what you're selecting, and lets you adjust your selection with a series of multiple motions before you execute a command.
2ap selects this paragraph and the next one
"+ selects the system clipboard as register for the next operation
y yanks the selection to the given register
In other words, that command would copy two paragraphs from your text to the system clipboard (e.g. for pasting them here at StackOverflow).
Global editing The global command is used to apply an Ex command to all lines matching a given regular expression. Examples:
:global/test/print or :g/test/p would print all lines containing the phrase test
:global/test/delete or :g/test/d would delete said lines
:global/test/substitute/^/#/ or :g/test/s/^/#/ would search for lines containing the phrase test, and comment them out by substituting the regexp anchor ^ (beginning-of-line) with the symbol #.
You can also do some cool stuff by passing the search motions /pattern or ?pattern as ranges:
:?test?move . searches backwards for a line containing test, and moves it to your current position in the file
:/test/copy . searches forwards for a line containing test, and copies it to the current position in the file
As far as I can tell (in Visual C# express 2010) ctrl-click just selects whatever word you click on. To do the same in VIM, you can combine the yank command with a movement command.
So you press "y" for yank (copy) then "e" or "w" to copy to the end of the word.
您始终可以使用 Visual Studio 的 Vim 模拟器/插件,并将 vim 的一些强大功能与 VS 的功能结合起来。如果你已经在使用 Visual Studio,我假设你正在使用 .NET 语言,如果没有 VS,使用起来会更加痛苦。
You could always use the Vim emulator/add-on for Visual Studio and get some of the power of vim mixed with the features of VS. If you're already using Visual Studio, I assume you're using a .NET language, which without VS, would be much more painful to use.
Personally, I got used to vi a long time ago, when we didn't have the luxury of a mouse in student's Unix terminals. Since then, I used vi/vim for everything safe for writing emails.
To this day, I probably use only 1/20 of the commands, but never felt the need to write code with another text editor, and reaching for a mouse in an IDE feels very clumsy to me.
Using high level and expressive languages, that do not require an IDE (mainly python, sql, javascript) really helps. I suppose it wouldn't be as easy with Java or C++.
Not having to move and point with the mouse when coding (safe for using the browser) also helps preventing Carpal tunnel syndrome.
BTW, I suppose Vim integrates better with Unix than with Windows... and who said 30 minutes was a little optimistic :)
发布评论
评论(13)
我只会留下一个链接到 这个答案< /a> 这里。
I'll just leave a link to this SO answer here.
VI 意味着手指永远不必离开键盘。
VI means never ever having to take you fingers off the keyboard.
请注意,我不使用 Visual Studio,并且对其中的可用功能知之甚少。以下是我认为 Vim 中有用的功能示例,而不是 Visual Studio 中缺少的功能列表。
宏
可以轻松地为复杂(但重复)的操作创建宏。为了用一个简单的例子来说明,假设我们从以下开始:
现在我们要将每一行包含在
print("");
语句中。将光标放在第一行,然后输入:
qx
开始将宏录制到寄存器x
print("
Esc 在行首插入文本");
Esc 在行尾附加文本j
向下一行q
停止录制宏4@x
执行宏注册x
4 次有关 Vim 宏的更多信息,请参阅
:help complex-repeat
。文本对象
请注意,这是 Vim 相对于传统 Vi 的改进之一。如果它不起作用,您可能正在 Vi 兼容模式下运行;使用
:set no兼容
启用 Vim 的全部功能。文本对象允许您轻松选择文本区域。假设我们从以下文本开始,并将光标放在某些文本上:
现在我们要删除
和
<; 之间的所有内容。 /i>
。只需输入命令dit
(d'elete i'nner t'ag) 即可完成此操作!或者,如果我们想将标签本身包含在我们的选择中,请使用dat
(d'elete a t'ag)。要删除标记内的所有内容,请使用
d2it
(d'elete two i'nner t'ags)。您可以类似地使用
daw
(删除单词)、dap
(删除段落)、di"
(删除双引号内)等; 请参阅:help text-objects
了解文本对象的另一个有用示例:
v
切换可视模式。这样可以更轻松地查看您所选择的内容,并让您在执行之前通过一系列多个动作来调整您的选择"+
选择系统剪贴板作为下一个操作的寄存器y
将所选内容拉到换句话说,该命令会将文本中的两个段落复制到系统剪贴板(例如,将它们粘贴到 StackOverflow 上)。
全局编辑
global
命令用于将 Ex 命令应用于与给定正则表达式匹配的所有行。示例::global/test/print
或:g/test/p
将打印包含短语 test 的所有行:global/ test/delete
或:g/test/d
将删除所述行:global/test/substitute/^/#/
或:g/ test/s/^/#/
将搜索包含短语 test 的行,并通过替换正则表达式锚点^
(beginning-of-行)并带有符号#
。您还可以通过将搜索动作
/pattern
或?pattern
作为范围传递来做一些很酷的事情::?test?move .
向后搜索包含 test 的行,并将其移动到文件:/test/copy 中的当前位置。
向前搜索包含 test 的行,并将其复制到文件中的当前位置祝你好运,祝学习 Vim 愉快!
Note that I don't use Visual Studio, and know little about the available features in it. The following are examples of what I find useful in Vim, not a list of missing features in Visual Studio.
Macros
It's easy to create macros for complex (but repetitive) operations. To illustrate with a simple example, let's say we start with:
Now we want to envelop each line in a
print("");
statement.Place the cursor on the first line, and enter:
qx
to start recording a macro to the registerx
print("
Esc to insert text at the beginning of the line");
Esc to append text at the end of the linej
to go down one lineq
to stop recording the macro4@x
to execute the macro in registerx
4 timesSee
:help complex-repeat
for more info on Vim macros.Text objects
Note that this is one of the improvements Vim has over the traditional Vi. If it doesn't work, you're probably running in Vi compatibility mode; use
:set nocompatible
to enable the full functionality of Vim.Text objects allow you to easily select regions of text. Let's say we start with the following text, and place the cursor on some text:
Now we want to delete everything between
<i>
and</i>
. This can be done by simply typing the commanddit
(d'elete i'nner t'ag)! Or if we want to include the tags themselves in our selection, usedat
(d'elete a t'ag). To delete everything inside the<b>
tags, used2it
(d'elete two i'nner t'ags).You can similarly use
daw
(delete a word),dap
(delete a paragraph),di"
(delete inside double-quotes), etc; see:help text-objects
for the complete list.Another useful example of text objects:
v
toggles visual mode. This makes it easier to see what you're selecting, and lets you adjust your selection with a series of multiple motions before you execute a command.2ap
selects this paragraph and the next one"+
selects the system clipboard as register for the next operationy
yanks the selection to the given registerIn other words, that command would copy two paragraphs from your text to the system clipboard (e.g. for pasting them here at StackOverflow).
Global editing
The
global
command is used to apply an Ex command to all lines matching a given regular expression. Examples::global/test/print
or:g/test/p
would print all lines containing the phrase test:global/test/delete
or:g/test/d
would delete said lines:global/test/substitute/^/#/
or:g/test/s/^/#/
would search for lines containing the phrase test, and comment them out by substituting the regexp anchor^
(beginning-of-line) with the symbol#
.You can also do some cool stuff by passing the search motions
/pattern
or?pattern
as ranges::?test?move .
searches backwards for a line containing test, and moves it to your current position in the file:/test/copy .
searches forwards for a line containing test, and copies it to the current position in the fileGood luck and have fun learning Vim!
在仅允许 SSH 访问的 Solaris 计算机上编辑文件。
Edit a file on a Solaris machine that only allows SSH access.
这篇文章让我开始使用 Vim,并且我再也没有回头:
http:// /www.viemu.com/a-why-vi-vim.html
它有一些关于 Vim 功能的很好的例子。
This article is what got me started on Vim, and I never looked back:
http://www.viemu.com/a-why-vi-vim.html
It has some great examples on Vim's power.
使用 screen 保持会话在通过 ssh 访问的远程计算机上运行
Use screen to keep a session running on a remote machine accessed over ssh
Visual Studio 的正则表达式有点像米老鼠。 Vim 拥有触手可及的完整 POSIX 正则表达式语言。
Visual Studio's regular expressions are a little bit Mickey Mouse. Vim has the full POSIX regular expression language at your fingertips.
据我所知(在 Visual C# Express 2010 中)按住 Ctrl 键单击只会选择您单击的任何单词。要在 VIM 中执行相同的操作,您可以将 yank 命令与移动命令结合起来。
因此,您按“y”进行复制(复制),然后按“e”或“w”复制到单词的末尾。
As far as I can tell (in Visual C# express 2010) ctrl-click just selects whatever word you click on. To do the same in VIM, you can combine the yank command with a movement command.
So you press "y" for yank (copy) then "e" or "w" to copy to the end of the word.
有很多差异。
我建议您在 http://vimcasts.org 观看一些截屏视频/ 来感受一下 vim 的强大。
例如:
There is many differences.
I suggest you watch some screencasts at http://vimcasts.org/ to get a feeling of the power of vim.
e.g.:
您始终可以使用 Visual Studio 的 Vim 模拟器/插件,并将 vim 的一些强大功能与 VS 的功能结合起来。如果你已经在使用 Visual Studio,我假设你正在使用 .NET 语言,如果没有 VS,使用起来会更加痛苦。
You could always use the Vim emulator/add-on for Visual Studio and get some of the power of vim mixed with the features of VS. If you're already using Visual Studio, I assume you're using a .NET language, which without VS, would be much more painful to use.
Vim Essentials 是一组很棒的幻灯片。
就我个人而言,我很久以前就习惯了 vi,当时我们学生的 Unix 终端上还没有鼠标。从那时起,我就使用 vi/vim 来安全地编写电子邮件。
直到今天,我可能只使用了 1/20 的命令,但从未觉得需要使用另一个文本编辑器编写代码,并且在 IDE 中使用鼠标对我来说非常笨拙。
使用不需要 IDE 的高级且富有表现力的语言(主要是 python、sql、javascript)确实很有帮助。我认为使用 Java 或 C++ 就不会那么容易了。
编码时不必移动和用鼠标指向(可以安全地使用浏览器)也有助于预防腕管综合症。
顺便说一句,我认为 Vim 与 Unix 的集成比与 Windows 的集成更好......而且谁说 30 分钟有点乐观:)
Vim Essentials is a nice set of slides.
Personally, I got used to vi a long time ago, when we didn't have the luxury of a mouse in student's Unix terminals. Since then, I used vi/vim for everything safe for writing emails.
To this day, I probably use only 1/20 of the commands, but never felt the need to write code with another text editor, and reaching for a mouse in an IDE feels very clumsy to me.
Using high level and expressive languages, that do not require an IDE (mainly python, sql, javascript) really helps. I suppose it wouldn't be as easy with Java or C++.
Not having to move and point with the mouse when coding (safe for using the browser) also helps preventing Carpal tunnel syndrome.
BTW, I suppose Vim integrates better with Unix than with Windows... and who said 30 minutes was a little optimistic :)
通过 SSH 编辑文档。 Vim 确实很擅长这一点。
编辑:看起来很多人已经说过了:)
Edit documents over SSH. Vim's really nice for that.
Edit: looks like a lot of people have already said that :)
东元就是你的答案。您只需要一台 PDP-10 和一台 ASR-33,就可以了!
teco is your answer. You only need a PDP-10 and an ASR-33 and you're on your way!