在 Vim 中注释/取消注释行的快速方法是什么? [英] What's a quick way to comment/uncomment lines in Vim?

查看:29
本文介绍了在 Vim 中注释/取消注释行的快速方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 vi 中打开了一个 Ruby 代码文件,有些行用 # 注释掉:

I have a Ruby code file open in vi, there are lines commented out with #:

class Search < ActiveRecord::Migration
  def self.up
    # create_table :searches do |t|
    #   t.integer :user_id
    #   t.string :name
    #   t.string :all_of
    #   t.string :any_of
    #   t.string :none_of
    #   t.string :exact_phrase
    # 
    #   t.timestamps
    # end
  end

  def self.down
    # drop_table :searches
  end
end

假设我想取消注释第一个 def ... end 部分中的所有行.在 Vim 中执行此操作的有效方法是什么?

Say I want to uncomment all the lines in the first def ... end section. What's an efficient way to do that in Vim?

总的来说,我正在寻找一种简单流畅的方式来注释和取消注释行.这里我处理的是 Ruby 代码,但它可以是 JavaScript (//) 或 Haml (-#).

In general, I'm looking for an easy and fluid way to comment and uncomment lines. Here I'm dealing with Ruby code, but it could be JavaScript (//) or Haml (-#).

推荐答案

我使用 NERD 评论者脚本.它让您可以轻松地在代码中添加注释、取消注释或切换注释.

I use the NERD Commenter script. It lets you easily comment, uncomment or toggle comments in your code.

评论中所述:

对于那些对用法感到困惑的人来说,默认的领导者是",所以 10cc 将注释十行,而 10cu 将取消注释这十行

for anyone who is confused by the usage, default leader is "" so 10cc will comment ten lines and 10cu will uncomment those ten lines

这篇关于在 Vim 中注释/取消注释行的快速方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆