Open4

『マスタリングVim』を読んでみるあれこれ

うみうし3号うみうし3号

読書メモを連ねていく。

書籍のコードについては、Githubにサンプルがある。
https://github.com/PacktPublishing/Mastering-Vim

Ch1: Vimをはじめる

この章のトピックは初期設定、基本操作周り。たぶん公式ドキュメント見に行けばわかる内容。

インストール

Linux

Mac

Windows

Windows環境で開発しないので知らなかった。GUI vs CLIのprosconsはわからん。
CLIに抵抗ないのでGUIにするとどうなるのか?詰まりどころがあるのかなどは気になる。

.vimrc基本編

軽い説明なのでゴリゴリではない。
https://github.com/PacktPublishing/Mastering-Vim/blob/master/Chapter01/.vimrc

:set autoindentのように、":"のあとにvimrcへの設定を書くことで設定を一時反映させて確認することができるのは知らなかった。

vim操作導入

基本操作なのでまあという感じ。vimtutorやればわかりそう。
以下忘れてたコマンド。

  • "{","}" : 段落単位での移動
  • "cc":行をまるごと削除してinsert modeへ。インデントは保持される。

その他

swapファイルの扱い、永続undoの設定などは要確認。

set undofileで永続undoを有効化できるが、編集したファイルごとに作成され環境が汚れる。
なので以下で1つのディレクトリにまとめられるそう。

set undofile
if !isdirectory(expand("$HOME/.vim/undodir"))
  call mkdir(expand("$HOME/.vim/undodir"),"p")
endif
set undodir=$HOME/.vim/undodir
うみうし3号うみうし3号

Ch2.高度な編集と移動

この章ではプラグインの使い方、バッファやウィンドウ操作やレジスタ、それに関するプラグイン紹介がされている。

今まで単一ウィンドウでvimをカリカリしていただけだったので、バッファとウィンドウとタブの違いがわからない生き物となっていたが、ヘルプページに書いてあった。

Summary:
   A buffer is the in-memory text of a file.
   A window is a viewport on a buffer.
   A tab page is a collection of windows.

A window is a viewport onto a buffer.  You can use multiple windows on one
buffer, or several windows on different buffers.

A buffer is a file loaded into memory for editing.  The original file remains
unchanged until you write the buffer to the file.

A buffer can be in one of three states:

							*active-buffer*
active:   The buffer is displayed in a window.  If there is a file for this
	  buffer, it has been read into the buffer.  The buffer may have been
	  modified since then and thus be different from the file.
							*hidden-buffer*
hidden:   The buffer is not displayed.  If there is a file for this buffer, it
	  has been read into the buffer.  Otherwise it's the same as an active
	  buffer, you just can't see it.
							*inactive-buffer*
inactive: The buffer is not displayed and does not contain anything.  Options
	  for the buffer are remembered if the file was once loaded.  It can
	  contain marks from the |shada| file.  But the buffer doesn't
	  contain text.

なるほど。

バッファ

なんか書籍の記述がかなりラフなので結構ググった。
https://qiita.com/r12tkmt/items/1f396ddb4c701b59e1e8
https://zenn.dev/sa2knight/articles/e0a1b2ee30e9ec22dea9

ウィンドウ

キーマッピングの紹介は参考になった。

タブ

基本コマンドの説明。

折りたたみ

折りたたみのデフォルト設定などの紹介。

総じて、バッファ・ウィンドウ・タブの使い分け、easymotion系、grep系の整備ができてないので今後要検討。