18
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

便利なvimテクニック

Posted at

内容

個人的なvimテクニックまとめです。vimを使っていて、後輩に「そんな機能あるんだ」と驚かれたもので、意外に知られていない便利機能をまとめました。

コマンド

次の空行に移動

  • Normalモード中に{, }
    • {: 前の空行へ移動
    • }: 次の空行へ移動
    • 関数間を移動するときに重宝

画面分割

  • :vsp
    • 現在の画面を垂直分割
  • :sp
    • 現在の画面を水平分割

タブ操作

  • :tabnew
    • 新しいタブを開く

カッコ内を選択する

  • カッコ内でvi(もしくはvi)

複数行の先頭に文字を入れる

矩形選択(C-v)で選択し、Shift + i -> 文字列を入力 -> EscでNormalモードに戻る。

複数行の末尾に文字を入れる

矩形選択(C-v)で選択し、$ -> Ctrl + a -> 文字列を入力 -> EscでNormalモードに戻る。

連番を生成

以下のような文章があったとき、2行目~3行目の数値部分を矩形選択(C-v)で選択し、g -> Ctrl + a

* 1 手順A
* 1 手順B
* 1 手順C

* 1 手順A
* 2 手順B
* 3 手順C

または、矩形選択し、g -> Ctrl + x

* 1 手順A
* 0 手順B
* -1 手順C

直前に選択していた範囲を再選択

  • Normalモード中にgv

Visualモードで始点/終点を変更・移動

  • Visualモードで文字列選択中にo押下で、hjklで移動する始点・終点を切替

その他

パイプでvimに渡す

コマンドの出力をそのままvimで編集できます。以下はコマンド例です。

ls -l | vim -

他にも、diffで色がつかず見にくいときなどに重宝します。

diff -U 0 a.txt b.txt | vim -d -
18
16
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
18
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?