『マスタリングVim』を読んでみるあれこれ
読書メモを連ねていく。
書籍のコードについては、Githubにサンプルがある。
Ch1: Vimをはじめる
この章のトピックは初期設定、基本操作周り。たぶん公式ドキュメント見に行けばわかる内容。
インストール
Linux
- GitHubからとってきてビルドして入れる方法
Mac
-
homebrewで入れる方法
$brew install vim
-
MacVimを入れる方法(GUI)
https://macvim-dev.github.io/macvim/
Windows
- Cygwinを入れる方法
- WindowsでUNIXコマンドを叩けるもの。触ったことない
- https://www.ne.jp/asahi/hishidama/home/tech/windows/cygwin.html
- gVimを入れる方法(GUI)
Windows環境で開発しないので知らなかった。GUI vs CLIのprosconsはわからん。
CLIに抵抗ないのでGUIにするとどうなるのか?詰まりどころがあるのかなどは気になる。
.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
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.
なるほど。
バッファ
なんか書籍の記述がかなりラフなので結構ググった。
ウィンドウ
キーマッピングの紹介は参考になった。
タブ
基本コマンドの説明。
折りたたみ
折りたたみのデフォルト設定などの紹介。
総じて、バッファ・ウィンドウ・タブの使い分け、easymotion系、grep系の整備ができてないので今後要検討。
insertモードから抜けるときに自動でIMEをOFFにする方法を模索中。。
一旦fctixを入力メソッドにして、ESCでIME OFFにバインドしてみた。
あとはvimrcでコマンドバインドしようとしてたけど、autocmdで直接離脱イベントからfctixのIME OFF呼び出す方法もあるっぽい??