0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Vimで複数行コメント(ブロックコメント)

Last updated at Posted at 2021-03-25

概要

Vimで複数行の先頭に//とか入れてコメントアウトする方法はよく見かけるのですが,
コメントアウトしたい範囲の上下にコメント文字を入れる,いわゆるブロックコメントを簡単に行う方法が見当たらなかったので,メモします.

コマンド

例えばC言語の場合, Shift-Vで行選択をして

:s/\%V\(^\_.*$\)\%V/\/\*\r\1\r\*\//

と打つことで,選択範囲をコメントアウトできます.
また,解除には再び行選択をして

:s/[\*\/]\{2}\n//

と打つことで, コメントアウトを解除できます.
demo.gif

コマンドが長すぎる...

というわけで,プラグインを用意しました.
.vim/plugin などに置いてお使いください.
,, で選択範囲のブロックコメント
,u で選択範囲のブロックコメント解除
になります.C以外の複数の言語でも動作します.

もっと簡単な方法があったら教えて下さい.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?