Vimを設定を見直してみる
最近はもっぱらVSCodeばかりになってしまったが、新しいMacを購入したのでVimやらShellを見直してみることに。
Shellをfishに変えてみた
今までzshを使っていましたが、fishがよさそうなので変更してみます。
まずはfishとパッケージマネージャfisherをインストール。Powerlineフォントが必要らしいのでそれもインストール。フォントは、Roboto Mono for Powerlineを選択。とりあえず、fisherでzプラグインのみインストール。
こちらのサイトを参考にさせてもらいました。
https://zenn.dev/sawao/articles/0b40e80d151d6a
brew install fish
chsh -s /opt/homebrew/bin/fish
curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish
fisher install oh-my-fish/theme-bobthefish
git clone https://github.com/powerline/fonts.git
cd fonts
./install.sh
rm -rf ./fonts
brew install z
fisher install jethrokuan/z
カラーテーマは、fish_configを実行するとWebの設定画面が開いて選べるようで便利。fishの設定は、~/.config/fish/config.fishでおこなうらしい。少し気になる右側の日時を消して、Homebrewの環境変数設定を追加。
if status is-interactive
end
set -g theme_display_date no
eval "$(/opt/homebrew/bin/brew shellenv)"
tmuxの設定
今まで使っていた設定で特に変更せずにそのまま…。
set-option -g prefix C-t
set-option -g history-limit 10000
set-window-option -g mode-keys vi
set-window-option -g window-status-current-style bg=black,fg=green
set -g status-style bg=black,fg=white
set -g status-left '#[fg=blue,bold][#S]#[default]'
set -g status-right '#[fg=green,bold][%Y/%m/%d(%a)%H:%M]#[default]'
set -g message-style bold,fg=white,bg=red
bind-key C-n next-window
bind-key C-p previous-window
bind -r C-h resize-pane -L 5
bind -r C-j resize-pane -D 5
bind -r C-k resize-pane -U 5
bind -r C-l resize-pane -R 5
Vimの設定
neocomplcacheを使っていましたが、開いたファイルと同じディレクトリにkeyword_patternsとsyntax_cacheディレクトリが作られるようになってしまった。原因がよくわからない…。
開発が終わってddc.vimを使うほうが推奨されているようなので、移行してみることに。ついでにNeoVimにしようかと思ったが別の機会にする。
こちらの記事を参考にさせてもらいました。
https://qiita.com/maachan_9692/items/9b507fd043424013abde
https://zenn.dev/ara_ta3/articles/vim-dcc-getting-started
DenoというJS/TSランタイムを使うようなのでまずはそれをインストール。Homebrewで入れてもよさそう。
curl -fsSL https://deno.land/install.sh | sh
echo 'set -gx DENO_INSTALL "$HOME/.deno"' >> ~/.config/fish/config.fish
echo 'set -gx PATH "$DENO_INSTALL/bin" $PATH' >> ~/.config/fish/config.fish
あとはdein.vimを使ってプラグインを入れていく。他に最低限使っているプラグインなども適当に追加。
[[plugins]]
repo = 'Shougo/dein.vim'
[[plugins]]
repo = 'altercation/vim-colors-solarized'
[[plugins]]
repo = 'itchyny/lightline.vim'
[[plugins]]
repo = 'kana/vim-fakeclip'
[[plugins]]
repo = 'tpope/vim-surround'
[[plugins]]
repo = 'sakuraiyuta/commentout.vim'
[[plugins]]
repo = 'vim-denops/denops.vim'
[[plugins]]
repo = 'Shougo/ddc.vim'
[[plugins]]
repo = 'Shougo/ddc-ui-native'
[[plugins]]
repo = 'Shougo/ddc-source-around'
[[plugins]]
repo = 'Shougo/ddc-filter-matcher_head'
[[plugins]]
repo = 'Shougo/ddc-filter-sorter_rank'
[[plugins]]
repo = 'Shougo/ddc-converter_remove_overlap'
[[plugins]]
repo = 'Shougo/ddc-around'
[[plugins]]
repo = 'LumaKernel/ddc-source-file'
[[plugins]]
repo = 'shun/ddc-vim-lsp'
[[plugins]]
repo = 'prabirshrestha/vim-lsp'
[[plugins]]
repo = 'mattn/vim-lsp-settings'
[[plugins]]
repo = 'shun/ddc-source-vim-lsp'
[[plugins]]
repo = 'Shougo/ddc-source-lsp'
ddc.vimの設定は別ファイルにまとめる。このあたりの設定も色々カスタマイズしていきたいところ。
call ddc#custom#patch_global('ui', 'native')
call ddc#custom#patch_global('sources', [
\ 'around',
\ 'vim-lsp',
\ 'file',
\ ])
call ddc#custom#patch_global('sourceOptions', {
\ '_': {
\ 'matchers': ['matcher_head'],
\ 'sorters': ['sorter_rank'],
\ 'converters': ['converter_remove_overlap'],
\ },
\ 'around': {'mark': 'A'},
\ 'vim-lsp': {
\ 'mark': 'lsp',
\ 'matchers': ['matcher_head'],
\ 'forceCompletionPattern': '\.\w*|:\w*|->\w*',
\ },
\ 'file': {
\ 'mark': 'file',
\ 'isVolatile': v:true,
\ 'forceCompletionPattern': '\S/\S*'
\ }})
call ddc#enable()
" <TAB>: completion.
inoremap <expr> <TAB>
\ pumvisible() ? '<C-n>' :
\ (col('.') <= 1 <Bar><Bar> getline('.')[col('.') - 2] =~# '\s') ?
\ '<TAB>' : ddc#map#manual_complete()
" <S-TAB>: completion back.
inoremap <expr> <S-TAB> pumvisible() ? '<C-p>' : '<C-h>'
vimの設定ファイル。denoのパスは自分の環境合わせてフルパスで書くようだ。
"
" dein.vim
"
let g:denops#deno = '/Users/xxx/.deno/bin/deno'
let s:dein_dir = expand('~/.cache/dein')
let s:dein_repo_dir = s:dein_dir . '/repos/github.com/Shougo/dein.vim'
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)
let g:rc_dir = expand('~/.vim/rc')
let s:toml = g:rc_dir . '/dein.toml'
let s:lazy_toml = g:rc_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
if dein#check_install()
call dein#install()
endif
source ~/.vim/ddc.vimrc
"
" Common
"
set backupdir=~/tmp/vim
set directory=~/tmp/vim
set undodir=~/tmp/vim
set encoding=utf-8
set fileencodings=utf-8,sjis,cp932,euc-jp,iso-2022-jp
set list
set listchars=tab:»-,trail:-,extends:»,precedes:«,nbsp:%
set wildmenu
set wildmode=list:longest,full
set completeopt=menuone
set visualbell t_vb=
set number
set expandtab
set shiftwidth=2
set softtabstop=2
set tabstop=2
set laststatus=2
set backspace=indent,eol,start
set hlsearch
set autoindent
set undofile
set re=0
set clipboard=unnamed,autoselect
syntax enable
set background=dark
colorscheme solarized
filetype plugin indent on
"
" Key Maps
"
if (exists(":tab"))
nmap <C-N> :tabn<CR>
nmap <C-P> :tabprev<CR>
else
nmap <C-N> :bn<CR>
nmap <C-P> :bp<CR>
endif
試しにJSファイルやTSファイルを開いて、:LspInstallServerを実行するとファイル形式にあわせたLanguageServerを自動的にインストールしてくれる。
typescript-language-serverがインストールされるが、上手く補完してくれない。
:LspStatusを使ってLanguageServerが立ち上がってるか確認してみると、not runningとなる…。
編集してるJSファイルと同じディレクトリにnode_modulesディレクトリを作ると上手く動くようだ…。
vim-lsp-settings公式GitHubに書いてあった下記の設定を追加しところ、とりあえず補完が効くようになったが、typescript-language-server使わずにDenoでの補完として動いているのかな?
let g:lsp_settings_filetype_typescript = ['typescript-language-server', 'eslint-language-server', 'deno']
let g:lsp_settings_filetype_javascript = ['typescript-language-server', 'eslint-language-server', 'deno']
最低限の設定はできたのでぼちぼち必要な設定を追加していこう。