もた日記

くだらないことを真面目にやる

Vimメモ : vim-nerdtree-tabsでタブページ使用時に使いやすくする

vim-nerdtree-tabs


github.com

ディレクトリツリーを表示するThe NERD Treeは便利だが、タブページ使用時にそれぞれのタブで独立に状態を保持しているのが不便に感じることがある。vim-nerdtree-tabsプラグインをインストールすれば、あたかも1つのThe NERD Treeを使用しているように全てのタブで同じ状態のものを使うことができる。
また、The NERD TreeにフォーカスがあるとNERD_tree_1のような名前がタブタイトルとして表示され、タブが非アクティブになっても表示され続けるが、このプラグインを使うとタブが非アクティブになったときはファイル名が表示されるようになる。

インストール


NeoBundleの場合は下記設定をvimrcに追加。もちろんThe NERD Tree本体は必要。

NeoBundle 'scrooloose/nerdtree'
NeoBundle 'jistr/vim-nerdtree-tabs'


使い方


The NERD Treeの呼び出し方法を変更する必要がある。以下は<C-n>キーで呼び出す例だがNERDTreeToggleのかわりにNERDTreeTabsToggleを呼ぶようにする。あとは、いつも通りの使用方法でよい。

map <C-n> <plug>NERDTreeTabsToggle<CR>


設定


以下のような設定項目がある。

" デフォルトで値が1(有効)の設定
" Open NERDTree on gvim/macvim startup
g:nerdtree_tabs_open_on_gui_startup
" Do not open NERDTree if vim starts in diff mode
g:nerdtree_tabs_no_startup_for_diff
" On startup, focus NERDTree if opening a directory, focus file if opening a file. (When set to 2, always focus file window after startup).
g:nerdtree_tabs_smart_startup_focus
" Open NERDTree on new tab creation (if NERDTree was globally opened by :NERDTreeTabsToggle)
g:nerdtree_tabs_open_on_new_tab
" Unfocus NERDTree when leaving a tab for descriptive tab names
g:nerdtree_tabs_meaningful_tab_names
" Close current tab if there is only one window in it and it's NERDTree
g:nerdtree_tabs_autoclose
" Synchronize view of all NERDTree windows (scroll and cursor position)
g:nerdtree_tabs_synchronize_view
" Synchronize focus when switching windows (focus NERDTree after tab switch if and only if it was focused before tab switch)
g:nerdtree_tabs_synchronize_focus
" When given a directory name as a command line parameter when launching Vim, :cd into it.
g:nerdtree_tabs_startup_cd
" デフォルトで値が0(無効)の設定
" Open NERDTree on console vim startup
g:nerdtree_tabs_open_on_console_startup
" When switching into a tab, make sure that focus is on the file window, not in the NERDTree window. (Note that this can get annoying if you use NERDTree's feature "open in new tab silently", as you will lose focus on the NERDTree.)
g:nerdtree_tabs_focus_on_files
" Automatically find and select currently opened file in NERDTree.
g:nerdtree_tabs_autofind

基本的に設定は変更しなくてもよいと思うが、Vim起動時(コンソール)にThe NERD Treeを開きたい場合は以下設定をvimrcに追加。

let g:nerdtree_tabs_open_on_console_startup=1