如何在vi中注释掉/注释掉haml的一段内容?

发布于 2025-01-03 09:51:00 字数 484 浏览 1 评论 0原文

我刚刚开始深入研究 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦途 2025-01-10 09:51:00

在逐块选择模式下,您可以按I在块前面插入,按A在块后面插入。

设置'relativenumber' (:set rnu) 可以帮助计算行数。

CTRL-V 开始切换到块选择模式,然后使用 8j 向下移动八行,然后使用 I#Esc 插入 #

要删除它:dCTRL-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 and A 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, then I#Esc to insert the #.

To remove it: dCTRL-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)

尾戒 2025-01-10 09:51:00

如果您对如何工作不太感兴趣而只是希望它工作,有许多插件可以为各种语言提供(取消)注释功能。 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

征棹 2025-01-10 09:51:00

如果你经常使用它,你可以在你的 .vimrc 中定义一个命令,

command -range=% C :<line1>,<line2>s/^/-#/

然后在 vi 中,你可以以通常的方式应用 :C 。您可以使用 :10,20C.,+10C 来完成此操作。您可以使用以下命令取消注释。

command -range=% D :<line1>,<line2>s/^-#//

由于我使用 vi 处理具有不同类型注释的语言,因此我还使用以下命令:

command -range=% -nargs=1 Ca :<line1>,<line2>s/^/<args>/
command -range=% -nargs=1 Da :<line1>,<line2>s/^<args>//

允许您只执行 :10,20Ca-#,您可以在其中替换 -# 使用所选的注释方法。

If you use it often, you can define a command in your .vimrc

command -range=% C :<line1>,<line2>s/^/-#/

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.

command -range=% D :<line1>,<line2>s/^-#//

Since I am using vi for with languages with different types of commenting, I also us these commands:

command -range=% -nargs=1 Ca :<line1>,<line2>s/^/<args>/
command -range=% -nargs=1 Da :<line1>,<line2>s/^<args>//

Allowing you to just do :10,20Ca-#, where you can replace -# with the commenting method of choice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文