What's the most elegant way of commenting / uncommenting blocks of ruby code in Vim?

前端 未结 10 685
悲哀的现实
悲哀的现实 2021-01-30 13:23

In VIM, at the moment when I need to comment out a section of Ruby code:

  • I navigate to the first column in the row I want to comment out
  • I press CTRL-v t
10条回答
  •  一整个雨季
    2021-01-30 13:56

    I will recommend you an alternative way to comment using by Macro

    The first, just put this in to your .vimrc

    let @c="I#\ej"
    let @u="^xj"
    

    For the example

    To comment 12 lines:

    1. Navigate to the first row that you want to start your comment.
    2. Type 12@c on command mode to comment 12 lines

    To uncomment 12 lines:

    1. Navigate to the first row that you want to uncomment.
    2. Type 12@u on command mode to uncomment 12 lines

    The conclusion

    Commenting:

    [quantifier]@c 
    

    Uncommenting:

    [quantifier]@u
    

    note: These commands will start commenting/uncommenting from your current line.

    Additional:

    To improve you nevigation number.vim can help you a lot about quantifier number.

    https://github.com/myusuf3/numbers.vim

提交回复
热议问题