Vimの個人設定は.vimrcにVim scriptで記述し、ユーザディレクトリに.vimrcファイルを設置することで反映される。他の人が書いた拡張機能はVim pluginとして取り込むことができる。Vim pluginの拡張には、プラグイン管理ツールを使用するのが便利。代表的なプラグイン管理ツールが、(開発がストップ) → NeoBundleDein.vim。

Vim plugin
.vimrcに大量のVim scriptを書くのは大変
複数のVim scriptを標準のディレクトリ構成に配置したパッケージを使う
Vim pluginの整理や、インストール作業を行ってくれるツールの代表がNeoBundle
→ NeoBundleは開発がストップ(厳密には、バグフィックスのみに)
→ Deim.vim
プラグインの管理には Dein.vim を利用
昔はNeoBundleを使って管理するのが人気でしたが、開発がストップ。
Note: Active developement on NeoBundle has stopped. The only future changes will be bug fixes.
Please see Dein.vim -- A faster, well-tested plugin manager for Vim and Neovim. It can do everything NeoBundle does, including asynchronous installs.
同じ人が開発しているDein.vimを使って、プラグインの設定を行う。
.vimrcに下記コードを追加- 取り込みたいプラグインを "Add or remove your plugins here:" の部分に追加・削除するだけ
if &compatible
set nocompatible
endif
set runtimepath+=~/.cache/dein/repos/github.com/Shougo/dein.vim
if dein#load_state('~/.cache/dein')
call dein#begin('~/.cache/dein')
call dein#add('~/.cache/dein/repos/github.com/Shougo/dein.vim')
" Add or remove your plugins here:
call dein#add('Shougo/neosnippet.vim')
call dein#add('Shougo/neosnippet-snippets')
...
call dein#end()
call dein#save_state()
endif
filetype plugin indent on
if dein#check_install()
call dein#install()
endif
.vimrc のお作法メモ
<silent>- 実行するコマンドがコマンドラインに表示されないようにする
vim コマンド
| コマンド | 説明 |
|---|---|
| :split | 水平分割 |
| :vsplit | 垂直分割 |
| ウインドウ移動 | |
| ウインドウを移動 | |
| gt | 次のタブに切り替え |
| gT | 前のタブに切り替え |
共通系プラグイン
Denite.vim
Denite.vim は、ファイルアクセスを高速にするためのプラグイン
NeoBundleと同様に、昔はUnite.vimというプラグインだったのですが、いつのまにか開発がストップ。
https://github.com/Shougo/denite.nvim
Note: Active development on unite.vim has stopped. The only future changes will be bug fixes.
"-------------------------------------------------
" Denite.vim
"-------------------------------------------------
"" 入力モードで開始する
let g:unite_enable_start_insert=1
" バッファ一覧
noremap <C-P> :Denite buffer<CR>
" ファイル一覧
noremap <C-N> :Denite -buffer-name=file file<CR>
" 最近使ったファイルの一覧
noremap <C-Z> :Denite file_old<CR>
" カレントディレクトリ
noremap <C-C> :Denite file_rec<CR>
" ESCキーでdeniteを終了
call denite#custom#map('insert', '<esc>', '<denite:enter_mode:normal>', 'noremap')
call denite#custom#map('normal', '<esc>', '<denite:quit>', 'noremap')
" C-N,C-Pで上下移動
call denite#custom#map('insert', '<C-n>', '<denite:move_to_next_line>', 'noremap')
call denite#custom#map('insert', '<C-p>', '<denite:move_to_previous_line>', 'noremap')
The NERDTree
NERDTreeは、IDEのようにツリー型でファイル構成を表示できるようにするためのプラグイン
もちろんファイルを選択し開くこともできる
https://github.com/scrooloose/nerdtree
"-------------------------------------------------
" NERDTree
"-------------------------------------------------
nnoremap <silent><C-e> :NERDTreeToggle<CR>
" 隠しファイルをデフォルトで表示させる
let NERDTreeShowHidden = 1
" ツリーと編集領域を移動
nnoremap <Leader><Tab> <C-w>w
ファイル操作
| コマンド | 説明 |
|---|---|
| o(enter) | ファイルを開く |
| go | ファイルを開き、カーソルはツリーのまま |
| t | タブで開く |
| i | 水平分割して開く |
| s | 垂直分割して開く |
ディレクトリ操作
| コマンド | 説明 |
|---|---|
| o(enter) | ディレクトリを開く |
| O | 再帰的にディレクトリを開く |
| x | 親ディレクトリを閉じる |
| X | 再帰的に親ディレクトリを閉じる |
| e | 新しいツリーを生成する |
ツリー操作
| コマンド | 説明 |
|---|---|
| P | ルートディレクトリに移動 |
| p | 親ディレクトリに移動 |
| K | 一番上に移動 |
| J | 一番下に移動 |
| k | 1つ上に移動 |
| j | 1つ下に移動 |
| l | 隠しファイルを表示・非表示 |
| B | ブックマークの表示・非表示 |
| F | ファイルの表示・非表示 |
ファイルシステム系
| コマンド | 説明 |
|---|---|
| r | 現在のディレクトリをリフレッシュ |
| p | ルートディレクトリ配下を再帰的にリフレッシュ |
| m → a | ファイル・ディレクトリの作成 |
| m → m | 移動 |
| m → d | 削除 |
vim-trailling-whitespace
vim-trailling-whitespaceは、行末に入ってしまった不要な空白を可視化してくれるプラグイン
https://github.com/bronson/vim-trailing-whitespace
- [ ] あとで入れる
tcomment_vim
tcomment_vimは、vimで選択した範囲をコマンドでコメントアウトするためのプラグイン
https://github.com/tomtom/tcomment_vim
ale
aleは、Lintを非同期で実行するためのプラグイン- https://github.com/w0rp/ale
"-------------------------------------------------
" ale
"-------------------------------------------------
let g:ale_fixers = {
'ruby': ['rubocop'],
}
let g:ale_fix_on_save = 1
let g:ale_sign_column_always = 1
vim-quickrun
vim-quickrunは、vimを閉じずに編集中のファイルを実行するためのプラグイン
https://github.com/thinca/vim-quickrun
→ 消した
auto-ctags
ctagsの入れ方
$ brew install –HEAD universal-ctags/universal-ctags/universal-ctags
"-------------------------------------------------
" auto-ctags
"-------------------------------------------------
set tags+=.git/tags
nnoremap <C-]> g<C-]>
let g:auto_ctags = 1
let g:auto_ctags_directory_list = ['.git']
let g:auto_ctags_tags_args = '--recurse=yes --append=yes --tag-relative=yes'
Ruby系プラグイン
rails.vim
rails.vimは、Railsのファイル移動を便利にしてくれるプラグイン
https://github.com/tpope/vim-rails
endwise.vim
endwise.vimは、Rubyのコードを書くときに末尾のendを自動的に挿入してくれるプラグイン
https://github.com/tpope/vim-endwise
- [ ] あとで入れる
Markdown系プラグイン
Vim Markdown
https://github.com/plasticboy/vim-markdown
VIM Table Mode
vim-table-modeは、MarkDownでテーブルをキレイに入力できるように補助してくれるプラグイン
https://github.com/dhruvasagar/vim-table-mode
"-------------------------------------------------
" VIM Table Mode
"-------------------------------------------------
let g:table_mode_corner="|"
番外編 - NeoBundle
vimプラグインのパッケージマネージャー
.vimrcに一行追加するだけで、Vimプラグインを導入できるようになる
:NeoBundleUpdateコマンドを全プラグインを最新版にアップデートできるようになる
NeoBundleをMacでインストール
$ mkdir -p ~/.vim/bundle
$ git clone https://github.com/Shougo/neobundle.vim ~/.vim/bundle/neobundle.vim
NeoBundleを利用してプラグインをインストール
以下を記述してから、:NeoBundleInstallコマンドを叩く
if has('vim_starting')
set nocompatible " be iMproved
set runtimepath+=~/.vim/bundle/neobundle.vim
endif
" NeoBundleを初期化
call neobundle#begin(expand('~/.vim/bundle/'))
" インストールするプラグインを以下に記述
NeoBundle 'Shougo/neobundle.vim'
call neobundle#end()
NeoBundleCheck
NeoBundleを利用したプラグインのアップデート
NeoBundleUpdateコマンドを実行
番外編 tmux
session > window > pane
セッション操作
# 新規セッション作成
tmux
tmux new -s session名
# アタッチ
tmux a
tmux a -t session名
# デタッチ
<Prefix> + d
# セッション名変更
tmux rename -t 旧session名 新session名
<Prefix> + $
# セッションの削除
tmux kill-session
tmux kill-session -t session名
tmux kill-server
# セッションの一覧選択
<Prefix> + s
ウインドウ操作
c 新規ウインドウ作成
w ウインドウの一覧選択
0-9 指定番号のウインドウへ移動
& ウインドウの破棄
n 次のウインドウへ移動
p 前のウインドウへ移動
l 以前のウインドウへ移動
' 入力番号のウインドウへ移動
. 入力番号にウインドウ番号を変更
, ウインドウの名前変更
f ウインドウの検索
ペイン操作
% 左右にペイン分割
" 上下にペイン分割
q ペイン番号を表示
カーソル 指定方向のペインへ移動 ※連続押しでプレフィックス継続
Ctrl-カーソル ペインのサイズを変更 ※連続押しでプレフィックス継続
! ペインを解除してウインドウ化
x ペインの破棄
o ペインを順に移動
; 以前のペインへ移動
z 現在のペインを最大化/復帰
スペース レイアウトを変更
Alt-1-5 レイウトを変更
{ ペインの入れ替え(前方向)
} ペインの入れ替え(後方向)
ctrl+o ペインの入れ替え(全体)
t ペインに時計を表示