LoginSignup
33
33

More than 3 years have passed since last update.

dein.vimでプラグイン管理[toml]

Posted at

.vimrcだけで管理していたvimの設定やプラグインをtomlファイルで管理することにした。
読み込み遅延などの設定をしたら、以前より起動や挙動が高速になった。

環境

  • Mojave 10.14.5(18F132)
  • NEOVIM v0.3.4

はじめに

当方のとりあえずvimrc晒すをQiitaで公開してから1年半以上が経過して、各種プラグインのアップデートや、当方の業務内容にも変化が出てきたため、記事も都度編集はしてきましたが、結果的にかつての.vimrcからは大きく内容が変わりました。

加えて、当方でdein.vimとtomlファイルによるプラグインの管理方法が確立してきたため、もう一度まとめて、公開しようと思い立ちました。

私自身が先人の素晴らしいリソースに幾度となく救われてきた身です。
この稚拙な記事が、少しでも困っている方の参考になれば幸いです。

ファイル構成

~
├── .config/
│   └── nvim/
│       └── init.vim
│
└── .vim/
    │
    ├── colors/
    │   └── Benokai.vim(省略)
    │
    ├── dein/
    │   └── (省略)
    │
    └── userautoload/
        │
        ├── dein/
        │   ├── lazy.toml
        │   └── plugins.toml
        │
        └── init/
            ├── basic.vim
            └── mapping.vim

init.vim

~/.config/nvim/init.vim
if $compatible
  set nocompatible " Be iMproved
endif

set rtp+=~/.vim/
runtime! userautoload/init/*.vim
runtime! userautoload/dein/*.vim

let s:dein_dir = expand('~/.vim/dein')

"コマンド実行する $ git clone https://github.com/Shougo/dein.vim.git ~/.vim/dein/repos/github.com/Shougo/dein.vim
set rtp+=~/.vim/dein/repos/github.com/Shougo/dein.vim

" dein.vim がなければ github から落としてくる
if &runtimepath !~# '/dein.vim'
  if !isdirectory(s:dein_repo_dir)
    execute '!git clone https://github.com/Shougo/dein.vim' s:dein_repo_dir
  endif
  execute 'set runtimepath^=' . fnamemodify(s:dein_repo_dir, ':p')
endif

if dein#load_state(s:dein_dir)
  call dein#begin(s:dein_dir)

  call dein#load_toml('~/.vim/userautoload/dein/plugins.toml', {'lazy': 0})
  call dein#load_toml('~/.vim/userautoload/dein/lazy.toml', {'lazy': 1})

  call dein#end()
  call dein#save_state()
endif

if dein#check_install()
  call dein#install()
endif

"シンタックスハイライト
syntax on

"配色設定
set t_Co=256
autocmd ColorScheme * highlight Normal ctermbg=none
autocmd ColorScheme * highlight LineNr ctermbg=none

"カラースキーマ
"http://pyoonn.hatenablog.com/entry/2014/10/04/225321
"https://github.com/benjaminwhite/Benokai
colorscheme Benokai

"配色・ハイライト設定
highlight Comment ctermfg=239
highlight Number ctermfg=09
highlight LineNr ctermfg=07
highlight Directory ctermfg=118
highlight RubyInstanceVariable ctermfg=208
highlight htmlTag ctermfg=15
highlight htmlEndTag ctermfg=15
highlight Search term=reverse ctermfg=black ctermbg=248
"補完の配色
highlight Pmenu ctermbg=239
highlight PmenuSel ctermbg=6
highlight PMenuSbar ctermbg=239

" gitgutterの色
set updatetime=250
let g:gitgutter_max_signs = 500
let g:gitgutter_map_keys = 0
let g:gitgutter_override_sign_column_highlight = 0
highlight clear SignColumn
highlight GitGutterAdd ctermfg=2
highlight GitGutterChange ctermfg=3
highlight GitGutterDelete ctermfg=1
highlight GitGutterChangeDelete ctermfg=4

"シンタックスハイライト(syntax onより前に書かない)
autocmd User Rails.view*                 NeoSnippetSource ~/.vim/snippet/ruby.rails.view.snip
autocmd User Rails.controller*           NeoSnippetSource ~/.vim/snippet/ruby.rails.controller.snip
autocmd User Rails/db/migrate/*          NeoSnippetSource ~/.vim/snippet/ruby.rails.migrate.snip
autocmd User Rails/config/routes.rb      NeoSnippetSource ~/.vim/snippet/ruby.rails.route.snip

" 奇数インデントのカラー
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd  guibg=#333333 ctermbg=235
" 偶数インデントのカラー
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=#2c2c2c ctermbg=240

"全角スペースをハイライト表示
function! ZenkakuSpace()
  highlight ZenkakuSpace cterm=reverse ctermfg=DarkMagenta gui=reverse guifg=DarkMagenta
endfunction
if has('syntax')
  augroup ZenkakuSpace
  autocmd!
  autocmd ColorScheme       * call ZenkakuSpace()
  autocmd VimEnter,WinEnter * match ZenkakuSpace / /
  augroup END
  call ZenkakuSpace()
endif

lazy.toml

~/.vim/userautoload/dein/lazy.toml
[[plugins]]
repo = 'Shougo/denite.nvim'

[[plugins]]
repo = 'Shougo/unite.vim'

[[plugins]]
repo = 'ujihisa/unite-colorscheme'
on_source = ['unite.vim']

[[plugins]]
repo = 'Shougo/deoplete.nvim'
hook_add = '''
  let g:deoplete#enable_at_startup = 1
  set completeopt+=noinsert
'''

[[plugins]]
repo = 'Shougo/neosnippet.vim'

[[plugins]]
repo = 'Shougo/neosnippet-snippets'
on_source = ['neosnippet.vim']

[[plugins]]
repo = 'othree/html5.vim'
on_ft = ['html','vue']
hook_add = '''
  let g:html5_event_handler_attributes_complete = 1
  let g:html5_rdfa_attributes_complete = 1
  let g:html5_microdata_attributes_complete = 1
  let g:html5_aria_attributes_complete = 1
'''

[[plugins]]
repo = 'vim-ruby/vim-ruby'
on_ft = ['ruby']

[[plugins]]
repo = 'tpope/vim-rails'
on_ft = ['ruby']

[[plugins]]
repo = 'alpaca-tc/vim-endwise.git'
on_ft = ['ruby']
hook_add = '''
  let g:endwise_no_mappings=1
'''

[[plugins]]
repo = 'jelera/vim-javascript-syntax'
on_ft = ['javascript']

[[plugins]]
repo = 'digitaltoad/vim-pug'
on_ft = ['pug']

[[plugins]]
repo = 'hail2u/vim-css3-syntax'
on_ft = ['css','scss','sass']

[[plugins]]
repo = 'cakebaker/scss-syntax.vim'
on_ft = ['css','scss','sass']

[[plugins]]
repo = 'slim-template/vim-slim'
on_ft = ['slim']

[[plugins]]
repo = 'posva/vim-vue'
on_ft = ['vue']

[[plugins]]
repo = 'cespare/vim-toml'
on_ft = ['toml']

[[plugins]]
repo = 'plasticboy/vim-markdown'
on_ft = ['markdown']

[[plugins]]
repo = 'elzr/vim-json'
hook_add = '''
  let g:vim_json_syntax_conceal = 0
'''
on_ft = ['json']

plugins.toml

~/.vim/userautoload/dein/plugins.toml
[[plugins]]
repo = 'vim-airline/vim-airline'
depends = ['/vim-airline-themes']

[[plugins]]
repo = 'vim-airline/vim-airline-themes'
hook_add = '''
  set laststatus=2
  let g:airline_powerline_fonts = 1
  let g:airline#extensions#tabline#enabled = 1
  let g:airline#extensions#tabline#buffer_idx_mode = 1
  let g:airline#extensions#whitespace#mixed_indent_algo = 1
  let g:airline_theme = 'dark'
'''

[[plugins]]
repo = 'Shougo/vimfiler.vim'
hook_add = '''
  augroup vimfiler
    autocmd!
    autocmd FileType vimfiler call s:vimfiler_settings()
  augroup END

  function! s:vimfiler_settings()
    nnoremap <silent><buffer><expr> s vimfiler#do_switch_action('split')
    nnoremap <silent><buffer><expr> v vimfiler#do_switch_action('vsplit')
  endfunction

  let g:vimfiler_as_default_explorer=1
  let g:vimfiler_safe_mode_by_default = 0
  let g:vimfiler_tree_leaf_icon = " "
  let g:vimfiler_tree_opened_icon = ' '
  let g:vimfiler_tree_closed_icon = ' '
  let g:vimfiler_file_icon = '- '
  let g:vimfiler_marked_file_icon = '✓ '
  let g:vimfiler_readonly_file_icon = '✗ '
  let g:vimfiler_ignore_pattern = '^\%(.git\|.DS_Store\)$'

  nnoremap fi :VimFilerBufferDir<CR>
  nnoremap fe :VimFilerExplorer  -split -winwidth=35 -toggle -no-quit<CR>
'''

[[plugins]]
repo = 'ryanoasis/vim-devicons'
hook_add = '''
  let g:WebDevIconsUnicodeDecorateFileNodesExtensionSymbols = {}
  let g:WebDevIconsUnicodeDecorateFileNodesExtensionSymbols['html'] = ''
  let g:WebDevIconsUnicodeDecorateFileNodesExtensionSymbols['css'] = ''
  let g:WebDevIconsUnicodeDecorateFileNodesExtensionSymbols['md'] = ''
  let g:WebDevIconsUnicodeDecorateFileNodesExtensionSymbols['txt'] = ''
  let g:WebDevIconsUnicodeDecorateFileNodesExtensionSymbols['erb'] = ''
  let g:WebDevIconsUnicodeDecorateFileNodesExtensionSymbols['slim'] = ''
  let g:WebDevIconsUnicodeDecorateFileNodesExtensionSymbols['scss'] = ''
  let g:WebDevIconsUnicodeDecorateFileNodesExtensionSymbols['sass'] = ''
  let g:WebDevIconsUnicodeDecorateFileNodesExtensionSymbols['js'] = ''
  let g:WebDevIconsUnicodeDecorateFileNodesExtensionSymbols['coffee'] = ''
  let g:WebDevIconsUnicodeDecorateFileNodesExtensionSymbols['rb'] = ''
'''

[[plugins]]
repo = 'terryma/vim-multiple-cursors'
hook_add = '''
function! Multiple_cursors_before()
  if exists(':NeoCompleteLock')==2
    exe 'NeoCompleteLock'
  endif
endfunction
function! Multiple_cursors_after()
  if exists(':NeoCompleteUnlock')==2
    exe 'NeoCompleteUnlock'
  endif
endfunction
'''

[[plugins]]
repo = 'tpope/vim-fugitive'
hook_add = '''
  let g:airline#extensions#branch#enabled = 1
  nnoremap [fugitive]  <Nop>
  nmap <space>g [fugitive]
  nnoremap <silent> [fugitive]s :Gstatus<CR><C-w>T
  nnoremap <silent> [fugitive]a :Gwrite<CR>
  nnoremap <silent> [fugitive]c :Gcommit-v<CR>
  nnoremap <silent> [fugitive]b :Gblame<CR>
  nnoremap <silent> [fugitive]p :Gpull<CR>
  nnoremap <silent> [fugitive]d :Gdiff<CR>
  nnoremap <silent> [fugitive]m :Gmerge<CR>
'''

[[plugins]]
repo = 'airblade/vim-gitgutter'

[[plugins]]
repo = 'cohama/agit.vim'

[[plugins]]
repo = 'itchyny/vim-parenmatch'

[[plugins]]
repo = 'itchyny/vim-cursorword'


[[plugins]]
repo = 'tomtom/tcomment_vim'
hook_add = '''
  nmap ww gcc
  vmap ww gcc
  if !exists('g:tcomment_types')
      let g:tcomment_types = {}
  endif
  let g:tcomment_types['eruby'] = '<%# %s %>'
  let g:tcomment_types['erb'] = '<%# %s %>'
  let g:tcomment_types['scss'] = '/* %s */'
  let g:tcomment_types['pug'] = '// %s'
  let g:tcomment_types['toml'] = '# %s'
'''

[[plugins]]
repo = 'alvan/vim-closetag'
hook_add = '''
  let g:closetag_filenames = '*.html,*.xhtml,*.phtml,*.erb,*.php,*.vue'
'''

[[plugins]]
repo = 'mikoto2000/buffer_selector.vim'
hook_add = '''
  noremap <Space><Space> <Esc>:call buffer_selector#OpenBufferSelector()<Enter>
'''

[[plugins]]
repo = 'lilydjwg/colorizer'

[[plugins]]
repo = 'Shougo/context_filetype.vim'

[[plugins]]
repo = 'osyo-manga/vim-precious'

[[plugins]]
repo = 'nathanaelkane/vim-indent-guides'
hook_add = '''
  let g:indent_guides_enable_on_vim_startup=1
  let g:indent_guides_auto_colors = 0
  let g:indent_guides_exclude_filetypes = ['help', 'vimfiler']
'''

[[plugins]]
repo = 'machakann/vim-highlightedyank'
hook_add = '''
  let g:highlightedyank_highlight_duration = 200
'''

[[plugins]]
repo = 'bfredl/nvim-miniyank'
hook_add = '''
  map p <Plug>(miniyank-autoput)
  map P <Plug>(miniyank-autoPut)
'''

[[plugins]]
repo = 'junegunn/fzf'
build = './install --bin'
merged = '0'

[[plugins]]
repo = 'junegunn/fzf.vim'
depends = 'fzf'
hook_add = '''
  command! -bang -nargs=* Rg
    \ call fzf#vim#grep(
    \   'rg --line-number --no-heading '.shellescape(<q-args>), 0,
    \   fzf#vim#with_preview({'options': '--exact --reverse'}, 'right:50%:wrap'))
'''

[[plugins]]
repo = 'wakatime/vim-wakatime'

[[plugins]]
repo = 'neoclide/coc.nvim'
build = './install.sh nightly'
hook_add = 'source ~/.config/nvim/coc-settings.json'

basic.vim

~/.vim/userautoload/init/basic.vim
"エンコード系
set encoding=utf-8
set fileencoding=utf-8
set termencoding=utf-8

"ファイルフォーマット
set fileformat=unix

"ビープ音を消す
set belloff=all

"スクロール時に一番下までカーソルが移動しない
set scrolloff=5

"行番号表示
set number

"行の相対表示をやめる
set norelativenumber

"backspaceの機能設定(字下げ、行末、挿入の開始点を超えて削除)
set backspace=2

"カーソルがある行をハイライト表示
set cursorline

"カーソル位置のカラムをハイライト表示しない
set nocursorcolumn

"左右のカーソル移動で行移動
set whichwrap=b,s,h,l,<,>,[,]

"swapfileを生成しない
set noswapfile

"Always display the statusline in all windows
set laststatus=2

"Always display the tabline, even if there is only one tab
set showtabline=2

"検索したワードをハイライト
set hlsearch

"モード表示をOFF
set noshowmode

" クリップボード
set clipboard&
set clipboard^=unnamedplus

"Don't autofold anything
set foldlevel=100

"対応括弧に<>を追加
set matchpairs& matchpairs+=<:>

"対応括弧をハイライト表示する
set showmatch

"対応括弧の表示秒数を3秒にする
set matchtime=3

"改行時に前の行のインデントを計測
set autoindent

"改行時に入力された行の末尾に合わせて次の行のインデントを増減する
set smartindent

"新しい行を作った時に高度な自動インデントを行う
set smarttab

"タブをスペースに変換
set expandtab

"ファイル上のタブ文字の見た目の幅
set tabstop=4

"自動インデント時に挿入されるスペース量
set shiftwidth=2

"tabを押した時に挿入されるスペース量
set softtabstop=2

"高速ターミナル接続を行う
set ttyfast

"マクロなどの途中経過を描写しない
set lazyredraw

"カーソルの形指定
set guicursor=v:block-Cursor/lCursor-blinkon0,n-i-c-ci:ver50-Cursor/lCursor,r-cr:hor20-Cursor/lCursor

"タブ、空白、改行の可視化
set list
set listchars=tab:>.,trail:_,eol:,extends:>,precedes:<,nbsp:%

"ファイルを開いたときにタブ文字があったらスペースに変換
autocmd BufNewFile,BufRead * set expandtab
autocmd BufNewFile,BufRead * retab

"ファイルタイプ
autocmd FileType vue syntax sync fromstart
autocmd FileType eruby syntax sync fromstart
autocmd BufNewFile,BufRead *.{html,htm} set filetype=html
autocmd BufNewFile,BufRead *.html.erb set filetype=html.eruby
autocmd BufNewFile,BufRead *.{pug*} set filetype=pug
autocmd BufNewFile,BufRead *.{jade*} set filetype=pug
autocmd BufRead,BufNewFile *.scss set filetype=sass
autocmd BufRead,BufNewFile *.json set filetype=json
autocmd BufRead,BufNewFile *.md set filetype=markdown
autocmd BufRead,BufNewFile *.rb set filetype=ruby
autocmd BufRead,BufNewFile *.slim set filetype=slim
autocmd BufRead,BufNewFile *.js set filetype=javascript
autocmd BufRead,BufNewFile jquery.*.js set filetype=javascript syntax=jquery
autocmd BufRead,BufNewFile *.vue setlocal filetype=vue.pug.javascript.css
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\""

mapping.vim

~/.vim/userautoload/init/mapping.vim
"prefix
nnoremap FF <C-w>

"Escape
inoremap ff <Esc>
vnoremap ff <Esc>

"ノーマルモードで行のどこにいても改行
nnoremap <CR> A<CR><Esc>

"上スライド
nnoremap MM ddkkp

"下スライド
nnoremap mm ddp

"行複製
nnoremap tt Yp
vnoremap tt yP

"shift+dでvisualモードで単語選択
nnoremap D viw

"閉じ括弧自動保管
inoremap { {}<LEFT>
inoremap [ []<LEFT>
inoremap ( ()<LEFT>
" inoremap < <><LEFT>
inoremap " ""<LEFT>
inoremap ' ''<LEFT>

"カーソル上の単語検索
nnoremap <C-j> g*:noh<Enter>
nnoremap <C-k> g#:noh<Enter>

"ウインドウサイズ変更
"カレントウインドウの幅を増やす
nnoremap > <C-w>5>
"カレントウインドウの幅を減らす
nnoremap < <C-w>5<

"ハイライト切り替え
nnoremap <F3> :set hlsearch!<CR>

"ハイライト消す
nnoremap noh :noh<CR>

"タブリファクタリング
nnoremap tab :set expandtab<Enter>:retab<Enter>:w<Enter>

"設定ファイル読み込み
nnoremap <F5> :source ~/.config/nvim/init.vim<Enter>
nnoremap sou :source ~/.config/nvim/init.vim<Enter>


"文頭・文末
nnoremap H ^
vnoremap H ^
nnoremap L $
vnoremap L $

" fzfショートカット
nnoremap gr :Ag<CR>
33
33
1

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
33
33