vim で複数行にコメントアウトを挿入・削除する方法

2021-06-22

概要

1回1回、行頭に#を挿入したり、行頭の#を削除するのは、結構地味で面倒だと思いますので、vimでコメントアウトを複数行に挿入したり、削除したりする方法を説明します

  • コメントアウトを挿入する場合前のApacheの設定ファイル
<LocationMatch "^/+$">
    Options -Indexes
    ErrorDocument 403 /.noindex.html
</LocationMatch>

<Directory /usr/share/httpd/noindex>
    AllowOverride None
    Require all granted
</Directory>

Alias /.noindex.html /usr/share/httpd/noindex/index.html
Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css
Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css
Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif
Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png
  • コメントアウトを挿入する場合後のApacheの設定ファイル
#<LocationMatch "^/+$">
#    Options -Indexes
#    ErrorDocument 403 /.noindex.html
#</LocationMatch>
#
#<Directory /usr/share/httpd/noindex>
#    AllowOverride None
#    Require all granted
#</Directory>
#
#Alias /.noindex.html /usr/share/httpd/noindex/index.html
#Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css
#Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css
#Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif
#Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png

複数行にコメントアウトを挿入する方法

複数行にコメントアウトされる手順は以下となります

  1. Ctrl+v」 で矩形選択にします
  2. コメントアウトしたい行を選択(j , k or キーボードの上下キー選択)
  3. Shift+i」 (iの大文字)で挿入モードにします
  4. # や // などのコメントアウトの文字を入力します
  5. Esc」を入力すればコメントアウトされます

画面キャプチャー付きの説明

1.「Ctrl+v」 で矩形選択にします

2.コメントアウトしたい行を選択(j , k or キーボードの上下キー選択)

vim01

3.「Shift+i」 (iの大文字)で挿入モードにします

vim02

4.# や // などのコメントアウトの文字を入力します

vim03

5.「Esc」を入力すればコメントアウトされます

vim04

複数行にコメントアウトを削除する方法

複数行に行頭にコメントアウトされる場合に、行頭の文字を1文字削除する手順は以下となります

  1. Ctrl+v」 で矩形選択にします
  2. コメントアウト削除したい行を選択(j , k or キーボードの上下キー選択)
  3. d」を入力すれば行頭の1文字が削除されます

画面キャプチャー付きの説明

1.「Ctrl+v」 で矩形選択にします

2.コメントアウト削除したい行を選択(j , k or キーボードの上下キー選択)

vim_d01

3.「d」を入力すれば行頭の1文字が削除されます

vim_d02

 

 

スポンサーリンク

0
0

LinuxCentOS 6,CentOS 7

Posted by admin