vim pluginまわり作業内容。

Vimのpluginまわりの整理整頓をしたいと思います。

というか、VPSには、なにもしてないVimしかないので、
いちから環境を作ります。

入っていたVimのVersionは、7.4.629でした。
わらわらと(以前使っていたものとか、新たに使ってみたいなーと思っていた)pluginを入れたいと思います。


まずは、plugin managerのDein.vimを入れます*1
GitHub - Shougo/dein.vim: Dark powered Vim/Neovim plugin manager

どのディレクトリにおいておくのが便利?通例?なのかわからなかったので、とりあえず、.vim/bundleを作って指定*2

 $ mkdir -p ~/.vim/bundle
 $ curl https://raw.githubusercontent.com/Shougo/dein.vim/master/bin/installer.sh > installer.sh
 $ sh ./installer.sh ~/.vim/bundle

で、メッセージで、以下のdein Scriptsを.vimrcに加えよと書かれているので、.vimrcにコピペする*3

"dein Scripts-----------------------------
if &compatible
  set nocompatible               " Be iMproved
endif

" Required:
set runtimepath^=.vim/repos/github.com/Shougo/dein.vim

" Required:
call dein#begin(expand('.vim'))

" Let dein manage dein
" Required:
call dein#add('Shougo/dein.vim')

" Add or remove your plugins here:
call dein#add('Shougo/neosnippet.vim')
call dein#add('Shougo/neosnippet-snippets')

" You can specify revision/branch/tag.
call dein#add('Shougo/vimshell', { 'rev': '3787e5' })

" Required:
call dein#end()

" Required:
filetype plugin indent on

" If you want to install not installed plugins on startup.
"if dein#check_install()
"  call dein#install()
"endif

"End dein Scripts-------------------------

サンプルで書いてある2つのpluginをお試しで入れてみる。

:call dein#install()

をする。で、しばらく待つと、

[dein] Update started: (2016/04/09 12:21:03)
[dein] Updated plugins:
[dein]   vimshell
[dein]     https://github.com/Shougo/vimshell/compare/...3787e52766812d8b99a93ccdda57517bc2a0bab6
[dein]   neosnippet.vim
[dein]     https://github.com/Shougo/neosnippet.vim/compare/...ce3c3d209c38a6d87bbf1408d293e179f95
e7bb8
[dein]   neosnippet-snippets
[dein]     https://github.com/Shougo/neosnippet-snippets/compare/...1cd353ac0d0e9ad0eba9d57e3eda34
b3abefd7ff
[dein] Runtimepath updated: (2016/04/09 12:21:15)

と出てきたので、どうやら成功したらしい。


あと、これからちょいちょい.vimrcを編集するだけでも突貫的に欲しいキーマップを.vimrcに追記する。

"論理行移動と表示行移動を入れ替える
noremap j gj
noremap k gk
noremap gj j
noremap gk k
"ノーマルモードで:と;を入れ替える
noremap : ;
noremap ; :


僕がvimで編集しそうなファイルタイプの想定は、

とかです。


まずはなにはともあれ、(もっともお世話になっているプラグイン)neocomplete.vimを入れたいと思います。

" Add or remove your plugins here:と書かれているので、そこに入れたいpluginを並べていきます。

call dein#add('Shougo/neocomplete.vim')

そして、:call dein#install() を再び呼ぶと、できましたーみたいなメッセージがでる。
GitHub - Shougo/neocomplete.vim: Next generation completion framework after neocomplcache

configuration examplesをそのままコピペして、.vimrcに加えました。


つづいて、surround.vim(参考:Vim のプラグイン紹介 〜 surround.vim でカッコつける 〜 - Vim のブログ)です。

call dein#add('tpope/vim-surround')


今度は、HTML/CSS/JavaScript関係は、とりあえず、3つ*4
GitHub - othree/html5.vim: HTML5 omnicomplete and syntax
GitHub - hail2u/vim-css3-syntax: Add CSS3 syntax support to vim's built-in `syntax/css.vim`.
GitHub - jelera/vim-javascript-syntax: Enhanced javascript syntax file for Vim

call dein#add('othree/html5.vim')
call dein#add('hail2u/vim-css3-syntax')
call dein#add('jelera/vim-javascript-syntax')

html5.vimのほうはREAEME.mdに書かれているのは、無効にする設定ぐらいでしたが、vim-css3-sytaxは、GitHub - hail2u/vim-css3-syntax: Add CSS3 syntax support to vim's built-in `syntax/css.vim`.に、~/.vim/after/css.vim

setlocal iskeyword+=-

と書いてねと、書いてあったので、ディレクトリとファイルを作って記述。


つづいて、Python関係です。
補完などを有効にしてVimを最高のPython用開発環境に進化させる - タオルケット体操
VimでPython環境をいい感じに整える - Qiita
このあたりを参考にしました。

call dein#add('davidhalter/jedi-vim')
call dein#add('andviro/flake8-vim')

jedi-vimのところに書いてありますが、jedi-vimが入ったら

git submodule update --init in your jedi-vim repository.

とのことなので、jedi-vimディレクトリで、コマンドを実行します。
quickrunを使っていると、jedi-vimでもrがぶつかったりするらしいのですが、僕は使っていないので、デフォルトのままいじらずにそのままで。

Completion
Goto assignments g (typical goto function)
Goto definitions d (follow identifier as far as possible, includes imports and statements)
Show Documentation/Pydoc K (shows a popup with assignments)
Renaming r
Usages n (shows all the usages of a name)
Open module, e.g. :Pyimport os (opens the os module)

らしいので、コマンドを身につけたいと思います。


あと、ちょっといろいろ気になった設定とか。今後やること

  • showmatch
    • set showmatch
    • set showmatchtime=5 #ん?なんだこれ
  • call dein#add('jmcantrell/vim-virtualenv')
  • call dein#add('othree/javascript-libraries-syntax.vim')
  • ハイライト消す便利なキーマップ考える
  • Fortranの設定コピー


で、いまさら気がついたんですが、そもそも、VimLua付きじゃなかった!!!!!!!!!!!!!!(neocomplete動いていない)
今度は、lua付きのvimを入れるを予定しています。


以下、今日までの .vimrcです。

"dein Scripts-----------------------------
if &compatible
  set nocompatible               " Be iMproved
endif

" Required:
set runtimepath^=/home/fijixfiji/.vim/bundle/repos/github.com/Shougo/dein.vim

" Required:
call dein#begin(expand('/home/fijixfiji/.vim/bundle'))

" Let dein manage dein
" Required:
call dein#add('Shougo/dein.vim')

" Add or remove your plugins here:
call dein#add('Shougo/neosnippet.vim')
call dein#add('Shougo/neosnippet-snippets')
call dein#add('Shougo/neocomplete.vim')
call dein#add('tpope/vim-surround')

call dein#add('othree/html5.vim')
call dein#add('hail2u/vim-css3-syntax')
call dein#add('jelera/vim-javascript-syntax')

call dein#add('davidhalter/jedi-vim')
call dein#add('andviro/flake8-vim')
call dein#add('hynek/vim-python-pep8-indent')

" You can specify revision/branch/tag.
call dein#add('Shougo/vimshell', { 'rev': '3787e5' })

" Required:
call dein#end()

" Required:
filetype plugin indent on

" If you want to install not installed plugins on startup.
"if dein#check_install()
"  call dein#install()
"endif

"End dein Scripts-------------------------


"ヘルプの日本語
set helplang=ja

"ステータスラインを2行にして、なにかしら表示している
set laststatus=2                                                                              
set statusline=%<%F\ %r%h%w%y%{'['.(&fenc!=''?&fenc:&enc).']['.&ff.']'}%=%4v(ASCII=%03.3b,HEX=%02.2B)\ %l/%L(%P)%m
"行番号を表示させる
set number
"コマンド(の一部)を画面の最下行に表示するよ                                                   
set showcmd
"カーソルの上下に、指定した行数分余白ができるよ
set scrolloff=5
"カーソルのある行をCursorLineで強調するよ
set cursorline
"複数の窓をつかっているときは、編集中のウィンドウだけにCursorLineを表示する
autocmd WinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline

"backspaceの挙動のオプション設定
set backspace=eol,indent,start
"検索(/と?)における大文字/小文字の区別の無視
set ignorecase
"検索(/と?)における大文字/小文字の区別の改善
set smartcase
" '<'や'>'でインデントする際に'shiftwidth'の倍数に丸める
set shiftround

"論理行移動と表示行移動を入れ替える
noremap j gj
noremap k gk
noremap gj j
noremap gk k
"ノーマルモードで:と;を入れ替える
noremap : ;
noremap ; :

"Helpを簡単に閉じる
autocmd FileType help nnoremap <buffer> q <C-w>c


"neocomplete.vim Scripts-----------------------------
"Note: This option must set it in .vimrc(_vimrc).  NOT IN .gvimrc(_gvimrc)!
" Disable AutoComplPop.
let g:acp_enableAtStartup = 0
" Use neocomplete.
let g:neocomplete#enable_at_startup = 1
" Use smartcase.
let g:neocomplete#enable_smart_case = 1
" Set minimum syntax keyword length.
let g:neocomplete#sources#syntax#min_keyword_length = 3
let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'

" Define dictionary.
let g:neocomplete#sources#dictionary#dictionaries = {
    \ 'default' : '',
    \ 'vimshell' : $HOME.'/.vimshell_hist',
    \ 'scheme' : $HOME.'/.gosh_completions'
        \ }

" Define keyword.
if !exists('g:neocomplete#keyword_patterns')
    let g:neocomplete#keyword_patterns = {}
endif
let g:neocomplete#keyword_patterns['default'] = '\h\w*'

" Plugin key-mappings.
inoremap <expr><C-g>     neocomplete#undo_completion()
inoremap <expr><C-l>     neocomplete#complete_common_string()

" Recommended key-mappings.
" <CR>: close popup and save indent.
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
  return (pumvisible() ? "\<C-y>" : "" ) . "\<CR>"
  " For no inserting <CR> key.
  "return pumvisible() ? "\<C-y>" : "\<CR>"
endfunction
" <TAB>: completion.
inoremap <expr><TAB>  pumvisible() ? "\<C-n>" : "\<TAB>"
" <C-h>, <BS>: close popup and delete backword char.
inoremap <expr><C-h> neocomplete#smart_close_popup()."\<C-h>"
inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"
" Close popup by <Space>.
"inoremap <expr><Space> pumvisible() ? "\<C-y>" : "\<Space>"

" AutoComplPop like behavior.
"let g:neocomplete#enable_auto_select = 1

" Shell like behavior(not recommended).
"set completeopt+=longest
"let g:neocomplete#enable_auto_select = 1
"let g:neocomplete#disable_auto_complete = 1
"inoremap <expr><TAB>  pumvisible() ? "\<Down>" : "\<C-x>\<C-u>"

" Enable omni completion.
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags

" Enable heavy omni completion.
if !exists('g:neocomplete#sources#omni#input_patterns')
  let g:neocomplete#sources#omni#input_patterns = {}
endif
"let g:neocomplete#sources#omni#input_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
"let g:neocomplete#sources#omni#input_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
"let g:neocomplete#sources#omni#input_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'

" For perlomni.vim setting.
" https://github.com/c9s/perlomni.vim
let g:neocomplete#sources#omni#input_patterns.perl = '\h\w*->\h\w*\|\h\w*::'

"End neocomplete.vim Scripts-----------------------------

*1:実はNeoVundle含めて使った経験がない・・・

*2:ちなみに、{specify the installation directory}で、.vimとかやっちゃうと・・・悲しいことになるので注意。「~/.vim」とか完全パスで指定するっぽいです。

*3:ちなみに、vim上でコピペするときは、:set pasteとしてから、コピペするとインデントのおせっかいが入らないらしいです。 もどすときは、:set nopasteとのこと。vimでペーストするときインデントさせない - Qiita

*4:あと、気になったのは、jsのライブラリ用のシンタックスhttps://github.com/othree/javascript-libraries-syntax.vimです。とりあえず後回し