NeoVimの導入

カテゴリー:  Tech タグ:  editor sublime text vim

先日、Sublime Textから MacVimに戻した ばかりですが、安定していそうなのでNeoVimに移行してみました。

Pythonの導入

(2017-03-27追記)

Python3系を必要とするプラグインがあるので、導入しておきます。

Python2との切り替えが面倒なので、Pyenvを経由でPythonを導入します。

$ brew install pyenv

.bash_profile に以下の設定を行います。

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

次にインストール可能なPythonのバージョンを確認します。

$ pyenv install --list
Available versions:
  2.1.3
  2.2.3
  2.3.7
  2.4
  ...

この時点で最新の3系は3.6.1だったのでこれを導入します。

$ pyenv install 3.6.1
Downloading Python-3.6.1.tar.xz...
-> https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
Installing Python-3.6.1...

そして、3.6.1.を有効にします。

$ pyenv global 3.6.1
$ python --version
Python 3.6.1

mac OSへのインストール

Homebrewが導入されていれば、以下のコマンドでNeoVimを導入することができます。

$ brew install neovim/neovim/neovim

NeoVimの設定

今まではVimでは .vimrc に設定ファイルを置いていましたが、NeoVimでは XDG Base Directory Specificationというディレクトリ構造の標準規格に則った 仕様変更がされており、 $XDG_CONFIG_HOME/nvim 以下に設定ファイルを 置く仕様に変更になりました。

そのための環境変数を .bash_profile などにセットします。

export XDG_CONFIG_HOME=~/.config

とりあえず現時点の設定です。

NeoBundleがDeinに移行したり、UniteがDeniteに移行したりプラグインは入れ 替え途中です。

ソースは最後にGistから貼り付けました。

プラグイン設定

NeoVimに移行に伴い、プラグインマネージャーもNeoBundleからdeinに移行しま した。

deinではTOMLファイルで読み込むプラグインを設定します。初期読み込み用と 遅延読み込み用に分けています。

唯一の課題

NeoVim自体動作も安定していて、新しいプラグインも動作するので使っていて 不安な要素はあまりなさそうです。

サイズの大きなファイルを読み込んだ時の動作は、MacVimより高速で快適に作業 できます。

唯一の課題は日本語入力の制御の問題です。MacVimのパッチで実現していたような 日本語入力の制御ができないため、ノーマルモードに移動した時日本語入力モード になっているといちいち手動で英語モードにしなければならず結構イライライしま す。

( 2018-01-03 追記 )

Karabiner LementsComplex Modifications として以下のようなルールをサポートしているので、現在はこれらのルールを利用しています。

  • esc キーを押した時に、英数キーも送信する(vim用)

  • Ctrl-[ を押した時に、英数キーも送信する(vim用)

設定ファイル

設定ファイルです。

# dein.toml by yostos
# Last Change:2017-12-12 18:50:00.
# dein本体
[[plugins]]
repo = 'Shougo/dein.vim'
[[plugins]]
repo = 'Shougo/vimproc.vim'
build = 'make'
# --------------------------------------------
# Setting for lightline
# ステータスラインの表示変更
# --------------------------------------------
[[plugins]]
repo = 'itchyny/lightline.vim'
hook_add = '''
let g:lightline = {
\ 'colorscheme' : 'gotham',
\}
'''
# --------------------------------------------
# setting for molokai
# カラーテーマ
# --------------------------------------------
[[plugins]]
repo = 'whatyouhide/vim-gotham'
hook_add = '''
colorscheme gotham
'''
# --------------------------------------------
# Setting for NERDTree
# ファイラー
# --------------------------------------------
[[plugins]]
repo = 'scrooloose/nerdtree'
hook_add = '''
nnoremap <silent><C-n> :NERDTreeToggle<CR>
" ブックマークを初期表示
let g:NERDTreeShowBookmarks=1
" autocmd vimenter * NERDTree
" Vim起動時にNERDTreeを表示
'''
# --------------------------------------------
# setting for sonictemplate
# --------------------------------------------
[[plugins]]
repo = 'mattn/sonictemplate-vim'
hook_add = '''
let g:sonictemplate_vim_template_dir = '$HOME/vimfiles/templates'
'''
# --------------------------------------------
# setting for JpFormat.vim
# --------------------------------------------
[[plugins]]
repo = 'fuenor/JpFormat.vim'
# --------------------------------------------
# Setting for TextObj
# --------------------------------------------
[[plugins]]
repo = 'kana/vim-textobj-user'
# ae,ie
[[plugins]]
repo = 'kana/vim-textobj-entire'
# ai,ii
[[plugins]]
repo = 'kana/vim-textobj-indent'
# al,il
[[plugins]]
repo = 'kana/vim-textobj-line'
# ada : textobj-datetime-auto
# add : textobj-datetime-date
# adf : textobj-datetime-full
# adt : textobj-datetime-time
# adz : textobj-datetime-tz
# ida : textobj-datetime-auto
# idd : textobj-datetime-date
# idf : textobj-datetime-full
# idt : textobj-datetime-time
# idz : textobj-datetime-tz
[[plugins]]
repo = 'kana/vim-textobj-datetime'
# textobj-syntax provides |text-objects| to select one or
# more items which are syntax highlighted.
# ay,iy
[[plugins]]
repo = 'kana/vim-textobj-syntax'
## ac,ic
[[plugins]]
repo = 'thinca/vim-textobj-comment'
# --------------------------------------------
# Setting for vim-fugitive
# Git の支援プラグイン
# --------------------------------------------
[[plugins]]
repo = 'tpope/vim-fugitive'
# --------------------------------------------
# Setting for Agit
# ---------------------------------------------
[[plugins]]
repo = 'cohama/agit.vim'
# --------------------------------------------
# Setting for Merginal
# ---------------------------------------------
[[plugins]]
repo = 'idanarye/vim-merginal'
# --------------------------------------------
# indentLine
# インデントを可視化する
# --------------------------------------------
[[plugins]]
repo = 'Yggdroot/indentLine'
hook_add = '''
let g:indentLine_color_item = 111
let g:indentLine_colro_gui = '#708090'
" use ,¦ ┆ or │
let g:indentLine_char = '¦'
let g:indentLine_faster = 0
'''
# --------------------------------------------
# Setting for Lexima
# 括弧をいい感じで補完してくれる
# --------------------------------------------
[[plugins]]
repo = 'cohama/lexima.vim'
# --------------------------------------------
# Setting for Surround
# Git の支援プラグイン
# --------------------------------------------
[[plugins]]
repo = 'tpope/vim-surround'
# --------------------------------------------
# MRU
# --------------------------------------------
[[plugins]]
repo = 'Shougo/neomru.vim'
# --------------------------------------------
# Web API
# --------------------------------------------
[[plugins]]
repo = 'mattn/webapi-vim'
# --------------------------------------------
# Snipetts
# --------------------------------------------
[[plugins]]
repo = 'Shougo/neosnippet-snippets'
# --------------------------------------------
# コメント化
# キーバインド: gc
# --------------------------------------------
[[plugins]]
repo = 'tomtom/tcomment_vim'
# --------------------------------------------
# Slack Memo
# --------------------------------------------
[[plugins]]
repo = 'tsuyoshiwada/slack-memo-vim'
depends = 'mattn/webapi-vim'
# --------------------------------------------
# Denite
# アウトラインを表示してくれる
# --------------------------------------------
[[plugins]]
repo = 'Shougo/denite.nvim'
hook_add = '''
nmap <silent> ,ut :,Denite filetype<CR>
nmap <silent> ,ub :,Denite buffer<CR>
nmap <silent> ,uf :,Denite file_rec<CR>
nmap <silent> ,uj :,Denite line<CR>
nmap <silent> ,ug :,Denite grep<CR>
nmap <silent> ,u] :,DeniteCursorWord grep<CR>
nmap <silent> ,uc :,Denite colorscheme<CR>
nmap <silent> ,um :,Denite file_mru<CR>
nmap <silent> ,uy :,Denite neoyank<CR>
nmap <silent> ,ur :,Denite -resume<CR>
nmap <silent> ,u; :,Denite -resume -immediately -select=+1<CR>
nmap <silent> ,u- :,Denite -resume -immediately -select=-1<CR>
nmap <silent> ,ud :,call denite#start([{'name': 'file_rec', 'args': ['~/dotfiles']}])<CR>
nnoremap ml :,call denite#start([{'name': 'file_rec', 'args': [g:memolist_path]}])<CR>
'''
view raw dein.toml hosted with ❤ by GitHub
# dein_lazy.toml by yostos
# Last Change:2017-11-06 20:37:29.
# deinの遅延読み込みの際の条件指定
# on_ft ファイルタイプがマッチしたとき。String or List
# on_path パスが一致した時
# on_func 呼び出し機能が一致した時
# on_source プラグインがロードされたとき
# on_cmd コマンドが一致した時
# on_map キーが一致した時
# on_i on_event が奨励
# on_event eventが発生したら
# http://vim-jp.org/vimdoc-ja/autocmd.html#autocmd-events
# --------------------------------------------
# PythonのインデントをPEP8の定義に
# --------------------------------------------
[[plugins]]
repo = 'Vimjas/vim-python-pep8-indent'
on_ft = 'python'
# --------------------------------------------
# ReStructure Text 編集用プラグイン
# --------------------------------------------
[[plugins]]
repo = 'Rykka/clickable.vim'
on_ft = 'rst'
[[plugins]]
repo = 'Rykka/riv.vim'
on_ft = 'rst'
# --------------------------------------------
# 整形
# --------------------------------------------
[[plugins]]
repo = 'junegunn/vim-easy-align'
on_event = 'BufReadPodst'
# --------------------------------------------
# 括弧の補完
# --------------------------------------------
#[[plugins]]
#repo = 'jiangmiao/auto-pairs'
#on_i = 1
# --------------------------------------------
# NeoYank
# --------------------------------------------
[[plugins]]
repo = 'Shougo/neoyank.vim'
on_path = '.*'
on_event = 'BufEnter'
# --------------------------------------------
# Neoplete
# 補完してくれるプラグイン
# --------------------------------------------
[[plugins]]
repo = 'Shougo/deoplete.nvim'
if = 'has("nvim")'
on_event = 'InsertEnter'
hook_source = '''
let g:deoplete#enable_at_startup =1
inoremap <expr><tab> pumvisible() ? "\<C-n>" :
\ neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)" : "\<tab>"
'''
on_i = 1
# --------------------------------------------
# NeoSnippet
# --------------------------------------------
[[plugins]]
repo = 'Shougo/neosnippet'
hook_source = '''
imap <C-k> <Plug>(neosnippet_expand_or_jump)
smap <C-k> <Plug>(neosnippet_expand_or_jump)
xmap <C-k> <Plug>(neosnippet_expand_target)
if has('conceal')
set conceallevel=2 concealcursor=niv
endif
let g:neosnippet#snippets_directory = '~/.config/nvim/snippets/'
'''
on_i = 1
on_ft = ['snippet']
depends = ['neosnippet-snippets']
# --------------------------------------------
# Setting for Autodate
# 更新日を追加してくれるプラグイン
# タイムスタンプのフォーマット 出力例
# %Y/%m/%d 2004/09/27
# %H:%M:%S 13:06:32
# %y%m%d-%H%M 040927-1308
# %d-%3m-%Y 27-Sep-2004
# %Y/%m/%d %H:%M:%S 2004/09/27 13:06:32
# %c Sun Apr 27 11:49:23 1997
# %Y %b %d %X 1997 Apr 27 11:53:25
# %y%m%d %T 970427 11:53:55i
# --------------------------------------------
[[plugins]]
repo = 'vim-scripts/autodate.vim'
on_event = ['BufWritePre']
hook_add = '''
let g:autodate_format = '%Y-%m-%d %H:%M:%S'
'''
# --------------------------------------------
# VOom
# アウトラインを表示してくれる
# --------------------------------------------
[[plugins]]
repo = 'vim-voom/VOom'
on_event = ['BufReadPost','BufNewFile']
# --------------------------------------------
# Vim Comment Pluging
# --------------------------------------------
[[plugins]]
repo = 'tyru/caw.vim'
o
view raw dein_lazy.toml hosted with ❤ by GitHub
" --------------------------------------------
" init.vim
" Last Change:2017-12-26 21:45:58.
" --------------------------------------------
" --------------------------------------------
" Setting for dein
" --------------------------------------------
function! s:InitDein()
" Prepare .config/nvim
let s:config_dir = $XDG_CONFIG_HOME . "/nvim"
" Prepare .nvim dir
let s:vimdir = $HOME . "/.nvim"
if has("vim_starting")
if ! isdirectory(s:vimdir)
call system("mkdir " . s:vimdir)
endif
endif
" dein
" Set dein paths
let s:dein_dir = s:vimdir . '/dein'
let s:dein_github = s:dein_dir . '/repos/github.com'
let s:dein_repo_name = "Shougo/dein.vim"
let s:dein_repo_dir = s:dein_github . '/' . s:dein_repo_name
" Check dein has been installed or not
if !isdirectory(s:dein_repo_dir)
echo "dein is not installed, install now "
let s:dein_repo = "https://github.com/" . s:dein_repo_name
echo "git clone " . s:dein_repo . " " . s:dein_repo_dir
call system("git clone " . s:dein_repo . " " . s:dein_repo_dir)
endif
let &runtimepath = &runtimepath . ',' . s:dein_repo_dir
"Begin plugin part {{{
"Check cache
if dein#load_state(s:dein_dir)
call dein#begin(s:dein_dir)
" 管理するプラグインを記述したファイル
let s:toml = s:config_dir . '/dein.toml'
let s:lazy_toml = s:config_dir . '/dein_lazy.toml'
call dein#load_toml(s:toml, {'lazy': 0})
call dein#load_toml(s:lazy_toml, {'lazy': 1})
:
call dein#end()
call dein#save_state()
endif " dein#load
if dein#check_install()
call dein#install()
endif
filetype indent plugin on
syntax on
endfunction
call s:InitDein()
" --------------------------------------------
" Bacis Setting for Vim
" --------------------------------------------
" backup
set backup
set backupdir=$HOME/.vim-backup
let &directory = &backupdir
autocmd BufWritePre,FileWritePre,FileAppendPre * call UpdateBackupFile()
function! UpdateBackupFile()
let basedir = "$HOME/.vim-backup"
let dir=strftime(basedir."/%Y-%m/%d", localtime())
if !isdirectory(dir)
let retval = system("mkdir -p ".dir)
" 以下のユーザー名とグループは環境に合わせて設定
" id -p で自分のユーザー名とグループ名は調べられる
let retval = system("chown yostos:staff ".dir)
endif
exe "set backupdir=".dir
let time = strftime("%H_%M_%S", localtime())
exe "set backupext=".time
endfunction
set directory=$HOME/.vim-backup "スワップ用のディレクトリを指定
" ---------------
" 基本的な設定
" ---------------
let mapleader = ","
let maplocalleader = "."
" Common Option
if !&compatible
set nocompatible "vi互換でなくVimデフォルト設定にする
endif
if has('patch-7.4.1778')
"set guicolors
endif
if has('termguicolors')
set termguicolors
endif
if has('nvim')
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
endif
syntax enable "シンタックスハイライト
set iminsert=0
set imsearch=0
set list "不可視文字を表示
set listchars=tab:»-,trail:-,extends:»,precedes:«,nbsp:%,eol:↲
if has('kaoriya')
highlight CursorIM guibg=Purple guifg=NONE
inoremap <silent> <ESC> <ESC>:set iminsert=0<CR>
set iminsert=0 imsearch=2
endif
set imdisable " 元は noimdisable
set ruler "右下に行・列番号を表示
set cmdheight=2 "コマンドラインに使われる行数
set showcmd "入力中のコマンドをステータスに表示する
set title "タイトルをウィンドウ枠に表示する
set scrolloff=2 "スクロールするとき下が見えるように
set laststatus=2 "エディタウィンドウに2行目にステータスラインを常時表示
set showtabline=2
" Tab
set tabstop=4 "タブは4スペース
set shiftwidth=4 "自動インデントのスペース指定
set smarttab "新しい行を作った時高度なインデントを行う
set expandtab "タブのかわりに空白を使う
set softtabstop=4
set autoindent "新しい行のインデントを現在行と同じにする
" Edit
set smartindent
set showmatch "閉じカッコが入力時対応するカッコを強調
set matchtime=3 "対応括弧表示を3秒に
set backspace=indent,eol,start "バックスペースで各種消せるよう
set virtualedit+=block "文字がない行末にも移動することができる
set modeline "モードラインをオンにする
set modelines=5 "5行までモードラインを検索する
" Search
set ignorecase "検索時大文字小文字を区別しない
set smartcase "大文字を含めた検索はその通りに検索する
set incsearch "インクリメンタルサーチを行う
set wrapscan "循環検索オン
set infercase "補完の際大文字小文字を区別しない
nnoremap <silent> <ESC> <ESC>:noh<CR>
set hlsearch "検索結果をハイライト表示する
"現在の日時を入力
imap <silent> <C-d><C-d> <C-r>=strftime("%Y-%m-%d %H:%M")<CR>
nmap <silent> <C-d><C-d> <ESC>i<C-r>=strftime("%Y-%m-%d %H:%M")<CR><CR><ESC>
"
"バックスラッシュやクエッションを状況に応じて自動的にエスケープする
" http://lambdalisue.hatenablog.com/entry/2013/06/23/071344
cnoremap <expr> / getcmdtype() == '/' ? '\/' : '/'
cnoremap <expr> ? getcmdtype() =- '?' ? '\?' : '?'
" Other
set wildmenu "ナビゲーションバーを有効に
set wildmode=list:full
set wildignore=*.o,*.obj,*.pyc,*.so
let g:python_highlight_all=1
set tw=0 "自動改行オフ
set whichwrap=b,s,h,l,<,>,[,] "カーソル行を行頭、行末で止まらないように
set cursorline "カーソル行をハイライト
set clipboard=unnamed "クリップボードをWindowsと連携する
set hidden "変更中のでも保存せずで他のファイルを表示
set number "行番号を表示する
set switchbuf=useopen "新しく開く代りイに既に開いているバッファを
set vb t_vb= "ビープ音を消す
set novisualbell
set nostartofline "移動コマンドを使った時行頭に移動しない
set matchpairs& matchpairs+=<:> "<>を対応括弧ペアに
set shiftround "インデントをshiftwidthの倍数に
set wrap "ウィンドウより長い行は折り畳む
set colorcolumn=80 " 80文字目にラインを入れる
set textwidth=0 "テキストの最大幅を無効に
set history=10000 "コマンド、検索の履歴を1万個まで
set mouse=a "マウスモード有効
inoremap jj <ESC> "入力モード中に素早くjjと入力した時はESC
" 検索後にジャンプした際に検索単語を画面中央に持ってくる
nnoremap n nzz
nnoremap N Nzz
nnoremap * *zz
nnoremap # #zz
nnoremap g* g*zz
nnoremap g# g#zz
" set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
" grep検索を設定する
set grepformat=%f:%l::%m,%f:%l%m,%f\ \ %l%m,%f
set grepprg=grep\ -hn
" Vim を立ち上げたと時に、自動的にvim-indent-guidesをオンにする
let g:indent_guides_enable_on_vim_startup = 1
" --------------------------------------------
" 拡張子の設定
" --------------------------------------------
" md as markdown, instead of modula2
au BufRead,BufNewFile *.md set filetype=markdown
" --------------------------------------------
" Vimball
" --------------------------------------------
set runtimepath+=~/.config/nvim/vimball
" --------------------------------------------
" Align
" --------------------------------------------
let g:Align_xstrlen = 3 "日本語用の設定
" --------------------------------------------
" QFixHowm
" --------------------------------------------
set runtimepath+=~/.config/nvim/qfixhowm-master
" なぜかNeoVimでは画面が崩れてしまうので
let QFixHowm_MenuPreview = 0
let QFixHowm_MenuPreviewEnable = 0
let QFixHowm_Key = 'g'
let howm_dir='~/Documents/howm'
let howm_filename = '%Y/%m/%Y-%m-%d-%H%M%S.howm'
let QFixHowm_DiaryFile = 'diary/%Y/%m/%Y-%m-%d.howm'
let QFixHowm_QuickMemoFile = 'Qmem-00-0000-00-00-000000.howm'
let howm_fileencoding = 'utf-8'
let howm_fileformat = 'unix'
" キーコードやマッピングされたキー列が完了するのを待つ時間(ミリ秒)
set timeout timeoutlen=3000 ttimeoutlen=100
" QuickFixウィンドウでもプレビューや絞り込みを有効
"let QFixWin_EnableMode=1
" QuickHowm/QuickGrepの結果表示にロケーションリストを使用する/しない
let QFix_UseLocationList=0
let QFixHowm_SaveTime = 1 "保存時にタイムスタンプを更新
"MarkdownをHowmファイルとして利用する
let QFixHowm_FileType='markdown.howm_memo'
let QFixHowm_Title='#'
let QFixHowm_HolidayFile='~/Documents/howm/Sche-Hd-0000-00-00-000000.howm'
let QFixHowm_ST= -9
let QFix_CopenCmd = 'botright'
au FileType markdown setlocal textwidth=0 "テキストを折り返さないための設定
let QFixHowm_UserSwActionLock = ['[ ]',' [:org]','[:tririga]'] "カテゴリタグ
\ 'args' : '/Applications/Marked\ 2.app',
\ 'exec' : '%c %o %a %s',
\ }
cmap qr QuickRun
" --------------------------------------------
" Setting for JpFormat
" --------------------------------------------
" 日本語の行の連結時には空白を入力しない。(jオプションはvim 7.4以降のみ有効)
set formatoptions+=mMj
"au BufRead,BufNewFile *.howm JpSetAutoFormat
"au BufRead,BufNewFile *.howm let b:JpFormatExclude = '^[-+.*=|>";/[[:space:]]'
" 現在行を整形
nnoremap <silent> gl :JpFormat<CR>
vnoremap <silent> gl :JpFormat<CR>
" 自動整形のON/OFF切替
" 30gC の様にカウント指定すると、現バッファのみ折り返し文字数を指定されたカウントに変更します。
nnoremap <silent> gC :JpFormatToggle<CR>
" 現バッファを整形
nnoremap <silent> g,rJ :JpFormatAll<CR>
" 原稿枚数カウント
nnoremap <silent> g,rc :JpCountPages!<CR>
" カーソル位置の分割行をまとめてヤンク
nnoremap <silent> gY :JpYank<CR>
vnoremap <silent> gY :JpYank<CR>
" カーソル位置の分割行をまとめて連結
nnoremap <silent> gJ :JpJoin<CR>
vnoremap <silent> gJ :JpJoin<CR>
" -------------------------------------------------------------------------
" End of init.vim
" -------------------------------------------------------------------------
"
set printoptions=number:y,header:2,syntax:y,left:5pt,right:5,top:10pt,bottom:10pt
set printfont=MyricaM_M:h12
set printmbfont=r:MyricaM_M:h12,a:yes
view raw init.vim hosted with ❤ by GitHub

コメント