如何在vi中注释掉/注释掉haml的一段内容?
我刚刚开始深入研究 vi,到目前为止只学习了基本的移动/编辑命令。当我浏览这本书时,是否有一种快速方法可以在与光标位置相同的列中用 -#
注释掉段落(相应地缩进行)?
假设我有一段代码:
%table
- unless paginate(@clients).nil?
%tr
%th
=t('index.name')
%th
=t('index.address')
%th
=t('index.phone')
=render :partial => 'client', :collection => @clients
我想用 -#
注释掉 - except
和 =render :partial
之间的行列,然后可以再次对其进行评论。那会是什么命令?
I just started diving into vi and so far learned only basic moving around/editing commands. While I am going through the book, is there a fast way to comment out a paragraph with -#
in the same column with the cursor position (indenting the lines accordingly)?
Let's say I have a piece of code:
%table
- unless paginate(@clients).nil?
%tr
%th
=t('index.name')
%th
=t('index.address')
%th
=t('index.phone')
=render :partial => 'client', :collection => @clients
and I want to comment out lines between - unless
and =render :partial
with -#
in one column and then be able to comment them in again. What command would that be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在逐块选择模式下,您可以按
I
在块前面插入,按A
在块后面插入。设置
'relativenumber'
(:set rnu
) 可以帮助计算行数。从 CTRL-V 开始切换到块选择模式,然后使用
8j
向下移动八行,然后使用I#
Esc 插入#
。要删除它:
d
CTRL-V8j 将按块删除。警告,如果您碰巧在 Windows 上使用 vanilla gvim.exe,您可能已经激活了
mswin.vim
来重新映射 CTRL-V,然后使用 CTRL-Q (或禁用此插件)In blockwise select mode, you can press
I
to insert in front of the block andA
to insert after the block.Setting
'relativenumber'
(:set rnu
) could help to count lines.Start with CTRL-V to switch to blockwise select mode, then
8j
to go down eight lines, thenI#
Esc to insert the#
.To remove it:
d
CTRL-V8j will delete blockwise.Warning, if you happen to use vanilla gvim.exe on Windows, you probably have
mswin.vim
activated which remaps CTRL-V, use then CTRL-Q instead (or disable this plugin)如果您对如何工作不太感兴趣而只是希望它工作,有许多插件可以为各种语言提供(取消)注释功能。 Tim Pope 的 commentary.vim 是我最近才开始使用的,作为 nerdcommenter 的替代品。
我刚刚安装了它,所以我不能谈论任何缺陷,但蒂姆波普的东西(几乎?)总是很棒。使用该插件,您可以通过选择一个可视块并输入
\\\
来注释 Haml 段落。它还需要动作,例如\\ap
。链接:
https://github.com/tpope/vim-commentary
If you're less interested about the how and just want it to work, there are a number of plugins that provide (un)commenting functionality for varieties of languages. Tim Pope's commentary.vim is the one I just started using recently, as a replacement for nerdcommenter.
I just installed it so I can't speak to any defects, but Tim Pope's stuff is (nearly?) always excellent. With the plugin you could comment a Haml paragraph by selecting a visual block and typing
\\\
. It also takes motions, e.g.\\ap
.The link:
https://github.com/tpope/vim-commentary
如果你经常使用它,你可以在你的
.vimrc
中定义一个命令,然后在 vi 中,你可以以通常的方式应用
:C
。您可以使用:10,20C
或.,+10C
来完成此操作。您可以使用以下命令取消注释。由于我使用 vi 处理具有不同类型注释的语言,因此我还使用以下命令:
允许您只执行
:10,20Ca-#
,您可以在其中替换-# 使用所选的注释方法。
If you use it often, you can define a command in your
.vimrc
Then in vi, you can apply
:<range>C
in the usual manner. You can do this with:10,20C
or.,+10C
. You can use the following command for uncommenting.Since I am using vi for with languages with different types of commenting, I also us these commands:
Allowing you to just do
:10,20Ca-#
, where you can replace-#
with the commenting method of choice.