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

查看:103
本文介绍了什么是快速的方式来评论/取消注释行在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 (-#).

推荐答案

对于这些任务,我大部分时间使用块选择

For those tasks I use most of the time block selection.

将光标置于第一个字符,请按 Ctrl V (或 Ctrl Q for gVim)最后一条注释行,然后按 x ,将垂直删除所有字符。

Put your cursor on the first # character, press CtrlV (or CtrlQ for gVim), and go down until the last commented line and press x, that will delete all the # characters vertically.

对注释一个文本块几乎是一样的:首先,转到要注释的第一行,按 Ctrl V ,然后选择直到最后一行。其次,按 Shift I Esc (然后再给它一个) c $ c>#字符。对于默认情况下附带debian / ubuntu的vim的精简版本,请改为在第二步中键入:s / ^ /#

For commenting a block of text is almost the same: First, go to the first line you want to comment, press CtrlV, and select until the last line. Second, press ShiftI#Esc (then give it a second), and it will insert a # character on all selected lines. For the stripped-down version of vim shipped with debian/ubuntu by default, type : s/^/# in the second step instead.

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

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