LoginSignup
38
38

More than 3 years have passed since last update.

はじめてのNeoVim(初期設定編)

Last updated at Posted at 2019-07-31

概要

NeoVimを使ってみたので、何回かに分けて設定を残そうと思います!
今回はプラグイン管理のdein.vimを入れるところまでで。

本体のインストール

Macでのインストール

tarminal
$ brew update
$ brew install neovim

インストール後に確認

tarminal
i$ nvim -version
NVIM v0.3.8
Build type: Release
LuaJIT 2.0.5

init.vim を作成する

tarminal
mkdir -p ~/.config/nvim
touch ~/.config/nvim/init.vim

init.vimを編集

init.vimを設定していって使いやすくしていく

tarminal
$ nvim ~/.config/nvim/init.vim

まずは初回のキーバインド設定。
都度都度パス指定してinit.vimを開くのが面倒、それを読み込むのも面倒なのでキーバインドでさくっと出来るように。
あと、InsertModeは移動とmode抜けたら保存したいので以下の設定。

init.vim
" ------------------------------------------------------------
"  key bind
" ------------------------------------------------------------
" Normal Mode
cnoremap init :<C-u>edit $MYVIMRC<CR>                           " init.vim呼び出し
noremap <Space>s :source $MYVIMRC<CR>                           " init.vim読み込み
noremap <Space>w :<C-u>w<CR>                                    " ファイル保存

" Insert Mode
inoremap <silent> jj <ESC>:<C-u>w<CR>:" InsertMode抜けて保存
" Insert mode movekey bind
inoremap <C-d> <BS>
inoremap <C-h> <Left>                                                                                                                 
inoremap <C-l> <Right>
inoremap <C-k> <Up>                          
inoremap <C-j> <Down>

これでInsertModeでsetを入力して、jjコマンドでNormalModeに戻るたびにinit.vimが保存されて、再読み込みされます。
ここからは細かい初期設定

init.vim
" encode setting                                                                                                                                 
set encoding=utf-8
" edita setting
set number                                                      " 行番号表示
set splitbelow                                                  " 水平分割時に下に表示
set splitright                                                  " 縦分割時を右に表示
set noequalalways                                               " 分割時に自動調整を無効化
set wildmenu                                                    " コマンドモードの補完
" cursorl setting
set ruler                                                       " カーソルの位置表示
set cursorline                                                  " カーソルハイライト
" tab setting
set expandtab                                                   " tabを複数のspaceに置き換え
set tabstop=2                                                   " tabは半角2文字
set shiftwidth=2                                                " tabの幅

プラグイン管理

事前準備

tarminal
$ brew install python3
$ pip3 install -U neovim

dein.vimのインストール

プラグイン管理のdein.vimをインストール

tarminal
mkdir ~/.vim/dein
touch ~/.config/nvim/dein.toml
touch ~/.config/nvim/lazy.toml
cd ~/.vim/dein
curl https://raw.githubusercontent.com/Shougo/dein.vim/master/bin/installer.sh > installer.sh
sh ./installer.sh ~/.vim/dein

インストール完了時にinit.vimに追記する以下のコードが表示されるので追記する。
表示されるコードはフルパスなので、以下のコードはフルパスにっているところを~/に置き換えています。

init.vim
" ------------------------------------------------------------
" dein.vim set up
" ------------------------------------------------------------
if &compatible
  set nocompatible               " Be iMproved
endif

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

" Required:
if dein#load_state('~/.vim/dein')
  call dein#begin('~/.vim/dein')

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

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

  " Required:
  call dein#end()
  call dein#save_state()
endif

" Required:
filetype plugin indent on
syntax enable

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

今回はプラグインは別のファイルで管理するので、少し書き換えます。

init.vim
if &compatible    
  set nocompatible               " Be iMproved    
endif    

" Pluginディレクトリのパス    
let s:dein_dir = expand('~/.vim/dein')    
" dein.vimのパス    
let s:dein_repo_dir = s:dein_dir .  '/repos/github.com/Shougo/dein.vim'    
" tomlのディレクトリへのパス    
let s:toml_dir = expand('~/.config/nvim')    

" Required:    
execute 'set runtimepath^=' . s:dein_repo_dir    

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

  " 起動時に読み込むプラグイン群のtoml    
  call dein#load_toml(s:toml_dir . '/dein.toml', {'lazy': 0})

  " 利用時に読み込むプラグインのtoml
  call dein#load_toml(s:toml_dir . '/lazy.toml', {'lazy': 1})

  " Required:               
  call dein#end()           
  call dein#save_state()    
endif                        

" Required:                  
filetype plugin indent on                                   

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

次にdein.tomlに追加するプラグインを記入していきます。
今回は全体のColorSchemeをtenderにするため都度読み込みへ、tomlのSyntaxカラーを利用時読み込みで書いときます。

dein.toml
[[plugins]]                                    
repo = 'Shougo/dein.vim'                                          

# ------------------------------------                                    
# colorscheme tender setting                                    
# ------------------------------------
[[plugins]]                                                                                                                                                                                                                                             
repo = 'jacoborus/tender.vim'                                    
hook_add = '''                                              
    colorscheme tender                                      
    set background=dark                                     
    syntax on                                               
    set t_Co=256                                            
    let $NVIM_TUI_ENABLE_TRUE_COLOR=1                                    
'''
lazy.toml
# ------------------------------------ 
# toml syntax                          
# ------------------------------------           
[[plugins]]                                                                                                                                                                                                                                                                           
repo = 'cespare/vim-toml'                                    
on_ft = 'toml'                                         

まとめ

今回はここまで。
まずはNeoVimの基本設定の一部と、ColorSchemeだけ設定しました。
次回はStatusLineのColorScheme設定をしていきます!

38
38
0

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