0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【環境構築】neovim

Last updated at Posted at 2021-09-16

【確認環境】

ブラウザ種別/Ver
macOS Big Sur/バージョン11.5.2
Google Chrome/バージョン: 93.0.4577.63(Official Build) (x86_64)

【導入】

$ brew update
$ brew install neovim
$ nvim -version
$ mkdir -p ~/.config/nvim
$ touch ~/.config/nvim/init.vim
$ nvim ~/.config/nvim/init.vim
$  
$ pip3 install -U neovim

【起動方法】

$ nvim

編集

$ vim ~/.config/nvim/init.vim
~/.config/nvim/init.vim
""""""""""""""""""""""""""""""
" エンコーディングとファイル設定
""""""""""""""""""""""""""""""
set encoding=utf-8
scriptencoding utf-8
set fileencoding=utf-8 " 保存時の文字コード
set fileencodings=ucs-boms,utf-8,euc-jp,cp932 " 読み込み時の文字コードの自動判別
set fileformats=unix,dos,mac " 改行コードの自動判別
set ambiwidth=double " □や○文字が崩れる問題を解決

""""""""""""""""""""""""""""""
" バックアップとファイル設定
""""""""""""""""""""""""""""""
set noswapfile " スワップファイルは使わない
set nobackup " バックアップファイル出力無効
set noundofile " undoファイルは作成しない
set backup " バックアップする
set writebackup " 書き込み時のバックアップを有効にする
set hidden " 保存されていないファイルがあるときでも別のファイルを開けるようにする

""""""""""""""""""""""""""""""
" UI設定
""""""""""""""""""""""""""""""
set ruler " カーソル位置を表示
set cmdheight=2 " コマンドラインの高さを2行に
set laststatus=2 " 常時ステータスラインを表示
set statusline=%<%f\ %m%r%h%w%{'['.(&fenc!=''?&fenc:&enc).']['.&ff.']'}%=%l,%c%V%8P " ステータスラインの情報
set title " ウインドウのタイトルバーにファイルのパス情報等を表示
set wildmenu " コマンドラインモードで<Tab>キーによるファイル名補完を有効にする
set showcmd " 入力中のコマンドを表示
set list " 不可視文字を表示
set listchars=tab:>\ ,extends:< " タブと行の続きを可視化する
set number " 行番号を表示
set showmatch " 対応する括弧やブレースを表示
set matchtime=1
source $VIMRUNTIME/macros/matchit.vim " Vimの「%」を拡張
set visualbell " ビープ音を視覚表示

""""""""""""""""""""""""""""""
" 検索設定
""""""""""""""""""""""""""""""
set smartcase " 小文字のみで検索したときに大文字小文字を無視
set hlsearch " 検索結果をハイライト表示
set incsearch " 検索ワードの最初の文字を入力した時点で検索を開始
nnoremap <silent><Esc><Esc> :<C-u>set nohlsearch!<CR> " ESCキー2度押しでハイライトの切り替え

""""""""""""""""""""""""""""""
" インデントとタブ設定
""""""""""""""""""""""""""""""
set expandtab " タブ入力を複数の空白入力に置き換える
set autoindent " 改行時に前の行のインデントを継続
set smartindent " 改行時にインデントを増減
set tabstop=2 " タブ文字の表示幅
set shiftwidth=2 " 挿入するインデントの幅
set smarttab " 行頭の余白内でTabを打ち込むとインデントする

""""""""""""""""""""""""""""""
" その他の設定
""""""""""""""""""""""""""""""
set tags=~/.tags " タグファイルの指定
set backspace=indent,eol,start " バックスペースを有効化
set synmaxcol=200 " クラッシュ防止
set whichwrap=b,s,h,l,<,>,[,]" カーソルを行頭、行末で止まらないようにする
syntax on " 構文毎に文字色を変化

""""""""""""""""""""""""""""""
" キーマッピング
""""""""""""""""""""""""""""""
nnoremap j gj
nnoremap k gk
nnoremap <down> gj
nnoremap <up> gk

~/.config/nvim/init.lua
-- エンコーディングとファイル設定
vim.opt.encoding = 'utf-8'
vim.scriptencoding = 'utf-8'
vim.opt.fileencoding = 'utf-8'
vim.opt.fileencodings = 'ucs-bom,utf-8,euc-jp,cp932'
vim.opt.fileformats = 'unix,dos,mac'
vim.opt.ambiwidth = 'double'

-- バックアップとファイル設定
vim.opt.swapfile = false
vim.opt.backup = false
vim.opt.undofile = false
vim.opt.writebackup = true
vim.opt.hidden = true

-- UI設定
vim.opt.ruler = true
vim.opt.cmdheight = 2
vim.opt.laststatus = 2
vim.opt.statusline = '%<%f %m%r%h%w%{\'[\'.(&fenc!=\'\'?&fenc:&enc).\'][\'.&ff.\']\'}%=%l,%c%V%8P'
vim.opt.title = true
vim.opt.wildmenu = true
vim.opt.showcmd = true
vim.opt.list = true
vim.opt.listchars = { tab = '>-', extends = '<' }
vim.opt.number = true
vim.opt.showmatch = true
vim.opt.matchtime = 1
vim.cmd('source $VIMRUNTIME/macros/matchit.vim')
vim.opt.visualbell = true

-- 検索設定
vim.opt.smartcase = true
vim.opt.hlsearch = true
vim.opt.incsearch = true
vim.api.nvim_set_keymap('n', '<Esc><Esc>', ':<C-u>set nohlsearch!<CR>', { noremap = true, silent = true })

-- インデントとタブ設定
vim.opt.expandtab = true
vim.opt.autoindent = true
vim.opt.smartindent = true
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
vim.opt.smarttab = true

-- その他の設定
vim.opt.tags = { '~/.tags' }
vim.opt.backspace = 'indent,eol,start'
vim.opt.synmaxcol = 200
vim.opt.whichwrap = 'b,s,h,l,<,>,[,]'
vim.cmd('syntax on')

-- キーマッピング
vim.api.nvim_set_keymap('n', 'j', 'gj', { noremap = true })
vim.api.nvim_set_keymap('n', 'k', 'gk', { noremap = true })
vim.api.nvim_set_keymap('n', '<down>', 'gj', { noremap = true })
vim.api.nvim_set_keymap('n', '<up>', 'gk', { noremap = true })
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?