Vimメモ
2021/07/02 に Release された nvim-0.5
で、
LanguageServer
と DebugAdapter
を設定する方法を中心に情報を収集する。
packer
install
luarocks
packer で use_rocks
もしくは rocks
を記述すると、 hererocks
によるがインストールされる。
use_rocks "penlight"
-- もしくは
use {
"some",
rocks = {
{"penlight"},
}
}
場所は、 nvim.fn.stdpath "cache"
下。
~/.cache/nvim/hererocks
%USERPROFILE%/AppData/Local/temp/nvim/hererocks
で Windows では hererocks が失敗するということが分かった。 Linux 版の hererocks の構成は以下の通り。
~/.cache/nvim/hererocks
├── 2.1.0-beta3
│ ├── bin
│ │ ├── activate
│ │ ├── activate.csh
│ │ ├── activate.fish
│ │ ├── activate_posix
│ │ ├── get_deactivated_path.lua
│ │ ├── lua
│ │ ├── luarocks
│ │ └── luarocks-admin
│ ├── etc
│ │ └── luarocks
│ ├── hererocks.manifest
│ ├── include
│ │ ├── lauxlib.h
│ │ ├── lua.h
│ │ ├── lua.hpp
│ │ ├── luaconf.h
│ │ ├── luajit.h
│ │ └── lualib.h
│ ├── lib
│ │ ├── libluajit-5.1.a
│ │ ├── libluajit-5.1.so.2
│ │ ├── lua
│ │ └── luarocks
│ └── share
│ └── lua
└── hererocks.py
%USERPROFILE%/Local/nvim-data/site/pack/packer/start/packer.nvim/lua/pcker/luarocks.lua
が Windows 動くように改造
local function activate_hererocks_cmd(install_path)
local activate_file = 'activate'
local user_shell = os.getenv 'SHELL'
local shell = user_shell:gmatch '([^/]*)$'()
if shell == 'fish' then
activate_file = 'activate.fish'
elseif shell == 'csh' then
activate_file = 'activate.csh'
end
return fmt('source %s', util.join_paths(install_path, 'bin', activate_file))
end
local function hererocks_cmd(install_path, args)
if vim.fn.has('win32') ~= 0 then
-- これで %USERPROFILE%/AppData/Local/temp/nvim/hererocks/2.1.0-beta3/luarocks.bat を呼び出す
return {
os.getenv 'COMSPEC',
'/C',
fmt('luarocks --tree=%s %s', shell_hererocks_dir, args),
}
else
return {
os.getenv 'SHELL',
'-c',
fmt('%s && luarocks --tree=%s %s', activate_hererocks_cmd(install_path), shell_hererocks_dir, args),
}
end
end
local function run_luarocks(args, disp, operation_name)
local cmd =hererocks_cmd(hererocks_install_dir, args)
%USERPROFILE%/AppData/Local/temp/nvim/hererocks
に luarocks を展開する。
neovim
のビルドに使った luarocks をコピーする。
.deps/usr/luarocks
.dpes/usr/lib/luarocks
TODO: パスを調整する
:lua require('packer.luarocks').setup_paths()
LanguageServer(nvim built-in)
neovim-0.5
から組み込みの LSP-Client 機能が実装される。
https://neovim.io/doc/user/lsp.html
各言語ごとの LanguageServer の自動起動などを担うのが lspconfig。
https://github.com/neovim/nvim-lspconfig
- go-to-definition
- find-references
- hover
- completion
- rename
- format
- refactor
nvim-dap
https://github.com/mfussenegger/nvim-dap/blob/master/doc/dap.txt
-
https://medium.com/swlh/neovim-lsp-dap-and-fuzzy-finder-60337ef08060
-
https://alpha2phi.medium.com/neovim-dap-enhanced-ebc730ff498b
-
https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#ccrust-via-lldb-vscode
[[plugins]]
repo = 'mfussenegger/nvim-dap'
[[plugins]]
repo = 'rcarriga/nvim-dap-ui'
[[plugins]]
repo = 'nvim-telescope/telescope-dap.nvim'
adapter installation
log
$APPDATA/../Local/Temp/nvim/dap.log
DAPInstall
https://github.com/Pocco81/DAPInstall.nvim
[[plugins]]
repo = 'Pocco81/DAPInstall.nvim'
nvim-lua
[[plugins]]
repo = 'jbyuki/one-small-step-for-vimkind'
lua
python
LanguageServer
- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md
- NeovimでモダンなPython環境を構築するv2(LSPを添えて)
pylsp
を選択した。型対応があって pyright
が強そうなのだけど。
- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#pylsp
require'lspconfig'.pylsp.setup{}
-
python3 で動く
-
pyls は python2 仕様の print 文があって python3 では動かない
-
completion
-
formatter
DebugAdapter
$ pip install debugpy
local dap = require("dap")
dap.adapters.python = {
type = "executable",
command = "C:/Python38/python.exe",
args = { "-m", "debugpy.adapter" },
}
dap.configurations.python = {
{
type = "python",
request = "launch",
name = "Launch file",
program = "${file}",
pythonPath = function()
return "C:/Python38/python.exe"
end,
},
}
cpp
rust
rust-analyzer
$ git clone https://github.com/rust-analyzer/rust-analyzer.git
$ cd rust-analyzer
$ cargo xtask install --server
$ ~/.cargo/bin/rust-analyser.exe
nvim-lsp
vim-lsp
csharp
nvim
https://github.com/willelz/nvim-lua-guide-ja/blob/master/README.ja.md
init.lua
https://oroques.dev/notes/neovim-init/
https://teukka.tech/vimloop.html
https://github.com/luvit/luv/blob/master/docs.md
telescope
Neovim LSP, DAP and Fuzzy Finder
vim
.gvimrc
set iminsert=0
set imsearch=-1
set lines=40
set columns=80
set guicursor+=a:blinkon0
set guioptions-=r "remove right-hand scroll bar
set guioptions-=L "remove left-hand scroll bar
set guifont=Cica:h14:cANSI:qDRAFT
set renderoptions=type:directx,renmode:5
" メニューの文字化け回避
set encoding=utf-8
source $VIMRUNTIME/delmenu.vim
set langmenu=ja_jp.utf-8
source $VIMRUNTIME/menu.vim
.vimrc
filetype plugin indent on
syntax enable
set belloff=all
set hidden
set noswapfile nobackup noundofile
set laststatus=2
set ts=4 sw=4 sts=4 expandtab
set hlsearch
set clipboard=
set ambiwidth=double
set autochdir
set list
set listchars=tab:»-,trail:-,eol:↲,extends:»,precedes:«,nbsp:%
if has('win32')
set clipboard=unnamed
else
set clipboard=unnamedplus
endif
if has('nvim')
set nopaste
noremap! <S-Insert> <C-R>+
else
set t_Co=256
endif
au ColorScheme * hi MatchParen cterm=bold ctermfg=214 ctermbg=black
set conceallevel=0
set ts=4 sw=4 sts=4 expandtab
set hidden
set list
set listchars=tab:»-,trail:-,extends:»,precedes:«,nbsp:%,eol:↲
set foldmethod=marker
set autochdir
set showmatch
set matchtime=3
set noswapfile nobackup noundofile nowritebackup
set noeb vb t_vb=
set belloff=all
set laststatus=2
set hlsearch
set clipboard+=unnamed
set ambiwidth=double
set ignorecase
set iskeyword+=-
"set virtualedit=all
set background=dark
"if
set termguicolors
"set autoindent
set fileencodings=utf-8,ucs-bom,default,latin1
set fileformats=unix,dos
if (exists('+colorcolumn'))
set colorcolumn=80
highlight ColorColumn ctermbg=9
endif
set previewheight=8
" Shift-K
set keywordprg=:help
source init.vim
set encoding=utf8
let s:nvim_init = expand('~/AppData/Local/nvim/init.vim')
if filereadable(s:nvim_init)
execute 'source ' . s:nvim_init
endif
keymap
" ex mode を無効に
nnoremap Q <Nop>
prefix
nnoremap [prefix] <Nop>
nmap <Space> [prefix]
nmap <silent> [prefix]n :<C-u>e ~/.config/nvim/init.vim<CR>
imap <Nul> <Nop>
inoremap <C-Space> <c-x><c-o>
imap <C-@> <C-Space>
nmap <C-n> :lnext<CR>
nmap <C-p> :lprevious<CR>
nnoremap <C-l> :nohlsearch<CR><C-l>
nnoremap q :close<CR>
memo
<c-@>
に変換されて insert される?
- https://vim.fandom.com/wiki/Avoid_the_escape_key
[vim のkeymapでCtrl-Spaceが設定できなかったので調べてみた http://d.hatena.ne.jp/dgdg/20080109/1199891258]
どうやら
と指定せずに でいけるらしい。
code:.vim
imap
[端末上のvimでctrl+space(ついでにプラグインの上書き回避) http://h-miyako.hatenablog.com/entry/2014/01/20/053327]
[* Leader] vim leader #vim
code:.vim " 先に設定する必要あり let mapleader = "<Space>"
code:.vim
nmap
https://postd.cc/how-to-boost-your-vim-productivity/
<C-r>=XXX()<CR>
=> XXX()の実行結果
に置き換わる
[* 関数呼び出し]
code:.vim
function! s:some()
echo "some"
endfunction
nnoremap
plugins
open-browser.vim
[[plugins]]
repo = 'tyru/open-browser.vim'
gx でカーソル下のURLを開く
dein
init.vim
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^=' . s:dein_repo_dir
endif
if dein#load_state(s:dein_dir)
call dein#begin(s:dein_dir)
let g:rc_dir = expand('~/.config/nvim')
let s:toml = g:rc_dir . '/dein.toml'
call dein#load_toml(s:toml, {'lazy': 0})
let s:lazy_toml = g:rc_dir . '/dein_lazy.toml'
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
git
vim-fugitive
https://github.com/tpope/vim-fugitive
- https://qiita.com/tashua314/items/35521f9bada5fe00cca7
- https://myenigma.hatenablog.com/entry/2016/07/10/084048
- https://blog.yuku-t.com/entry/20110427/1303868482
vim-gitgutter
comment
vim-commentary
[[plugins]]
repo = 'tpope/vim-commentary'
hook_add='''
nmap <C-_> :Commentary<CR>
vmap <C-_> :Commentary<CR>
'''
[NERD Commenterでコメントアウト、アンコメントを楽にする https://qiita.com/pepo/items/09bacf98a36f6a7285ac]
https://github.com/tomtom/tcomment_vim
https://github.com/tpope/vim-commentary
[Ctrl + / (スラッシュ) キーをマップする https://qiita.com/castaneai/items/42e917d1fdf6d83b717c]
https://zenn.dev/yutakatay/articles/vim-fuzzy-finder
denite
https://github.com/Shougo/denite.nvim
設定
dein.toml
[[plugins]]
repo = 'Shougo/denite.nvim'
hook_add = '''
"
" Define mappings
"
autocmd FileType denite call s:denite_my_settings()
function! s:denite_my_settings() abort
nnoremap <silent><buffer><expr> <CR>
\ denite#do_map('do_action')
nnoremap <silent><buffer><expr> d
\ denite#do_map('do_action', 'delete')
nnoremap <silent><buffer><expr> p
\ denite#do_map('do_action', 'preview')
nnoremap <silent><buffer><expr> q
\ denite#do_map('quit')
nnoremap <silent><buffer><expr> i
\ denite#do_map('open_filter_buffer')
nnoremap <silent><buffer><expr> <Space>
\ denite#do_map('toggle_select').'j'
nnoremap <silent><buffer><expr> ..
\ denite#do_map('move_up_path')
nnoremap <silent><buffer><expr> <C-n>
\ denite#do_map('move_to_next_line')
nnoremap <silent><buffer><expr> <C-p>
\ denite#do_map('move_to_previous_line')
endfunction
"
" custom
"
call denite#custom#var('file/rec', 'command',['rg', '--files', '--glob', '!.git'])
call denite#custom#var('grep', 'command', ['rg', '--threads', '1'])
" call denite#custom#kind('directory', 'default_action', 'cd')
"
" start denite
"
nmap <silent> [prefix]<Space> :<C-u>DeniteProjectDir -buffer-name=files file/rec buffer<CR>
nmap <silent> [prefix]b :<C-u>Denite buffer<CR>
nmap <silent> [prefix]g :<C-u>Denite ghq<CR>
'''
- https://secret-garden.hatenablog.com/entry/2021/05/16/152715
floating-window
- (denite.nvimのFloating Windowオプションを使おう)[https://qiita.com/lighttiger2505/items/d4a3371399cfe6dbdd56]
let s:denite_win_width_percent = 0.85
let s:denite_win_height_percent = 0.7
call denite#custom#option('default', {
\ 'split': 'floating',
\ 'winwidth': float2nr(&columns * s:denite_win_width_percent),
\ 'wincol': float2nr((&columns - (&columns * s:denite_win_width_percent)) / 2),
\ 'winheight': float2nr(&lines * s:denite_win_height_percent),
\ 'winrow': float2nr((&lines - (&lines * s:denite_win_height_percent)) / 2),
\ })
概要
source => filter => sort => match => action
source
https://github.com/Shougo/denite.nvim/wiki/External-Sources
-
https://qiita.com/iyuuya/items/8a7e9cc0c9dd6d0e4c32
ghq
bookmark
action
auto-action
- https://zenn.dev/matsui54/articles/2021-03-24-denite-auto-action
preview
- https://zenn.dev/matsui54/articles/f6adb2a6f4c963637949
vim-lsp
https://github.com/prabirshrestha/vim-lsp
[[plugins]]
repo = 'prabirshrestha/vim-lsp'
ale
https://github.com/dense-analysis/ale
vimspector
https://github.com/puremourning/vimspector
VimでIDEのようなデバッグが可能になるvimspectorの紹介
completion
omnifunc
http://vimdoc.sourceforge.net/htmldoc/version7.html#new-omni-completion https://vim.fandom.com/wiki/Omni_completion https://vim.fandom.com/wiki/Omni_completion_popup_menu
インテリセンスみたいな文脈を考慮した補完。素の completion とのインターフェース上の違いは?
code:.vim filetype plugin on set omnifunc=syntaxcomplete#Complete
<C-X><C-O>
while open in Insert mode
[* vim-lsp] https://qiita.com/yami_beta/items/1bb1341113e12bcfb1b8
[* 補完関数の実装] [Vim の complete-functions でハマった http://d.hatena.ne.jp/osyo-manga/20140806/1407291600]
[* 補完の呼び出し] vimに以下の種類の挿入モード補完がある Whole lines |i_CTRL-X_CTRL-L| keywords in the current file |i_CTRL-X_CTRL-N| keywords in 'dictionary' |i_CTRL-X_CTRL-K| keywords in 'thesaurus', thesaurus-style |i_CTRL-X_CTRL-T| keywords in the current and included files |i_CTRL-X_CTRL-I| tags |i_CTRL-X_CTRL-]| file names |i_CTRL-X_CTRL-F| definitions or macros |i_CTRL-X_CTRL-D| Vim command-line |i_CTRL-X_CTRL-V| User defined completion |i_CTRL-X_CTRL-U| omni completion |i_CTRL-X_CTRL-O| Spelling suggestions |i_CTRL-X_s| keywords in 'complete' |i_CTRL-N| |i_CTRL-P| これしか使ってなかった
https://www.xmisao.com/2014/05/04/vim-completefunc.html https://github.com/neoclide/coc.nvim
[* 起動方法で異なる補完が出る]
File completion:
どの補完を使うか考えずに使いたい
deoplete 複数のソースを統合する。強い
一方で十分な量のバッファが開かれていればの `C-n` `C-p` で十分強い。むしろこれより弱くしたくない。
[* complete]
set complete=.,w,b,u,t
[* completeopt]
set completeopt+=menu,preview
[* pumvisible]
pumvisible()
pop up menu のことらしい
code:.vim
inoremap
[* keyword]
C-N
, C-P
help i^n, i^p
[* 対象を自動で振り分ける例] https://vim.fandom.com/wiki/Smart_mapping_for_tab_completion
code:.vim function! Smart_TabComplete() let line = getline('.') " current line
let substr = strpart(line, -1, col('.')+1) " from the start of the current " line to one character right " of the cursor let substr = matchstr(substr, "1*$") " word till cursor if (strlen(substr)==0) " nothing to match on empty string return "<tab>" endif let has_period = match(substr, '.') != -1 " position of period, if any let has_slash = match(substr, '/') != -1 " position of slash, if any if (!has_period && !has_slash) return "<C-X><C-P>" " existing text matching elseif ( has_slash ) return "<C-X><C-F>" " file matching else return "<C-X><C-O>" " plugin matching endif endfunction
inoremap <tab> <c-r>=Smart_TabComplete()<CR>
filetypes
python
[[plugins]]
repo = "davidhalter/jedi-vim"
on_ft = ['python']
powershell
[[plugins]]
repo = 'PProvost/vim-ps1'
on_ft = ['ps1']
markdown
- syntax
- formatter
- doctoc
terminal
colorschema
対応する括弧のハイライト
hi MatchParen ctermbg=239
- https://thinca.hatenablog.com/entry/I_expect_to_colorscheme
- [カラースキームを作ってみよう https://thinca.hatenablog.com/entry/20130410/1365530054]
- [Vim のカラースキームが微妙に気に食わないときの対処法 http://cohama.hateblo.jp/entry/2013/08/11/020849]
buffer
-
https://vim.fandom.com/wiki/Vim_buffer_FAQ
vim < tab < window < buffer
quickfix
autocmd QuickfixCmdPost make,grep,grepadd,vimgrep if len(getqflist()) != 0 | copen | endif
https://www.soum.co.jp/misc/vim-no-susume/7/
locationlistとの違い
Quickfix utility for Vim quickfix は Vim プロセスに対してグローバル location list は 1 つのウィンドウに対してローカル
errorformat
autocmd
fold
https://wonderwall.hatenablog.com/entry/2016/03/26/211710 左の方
https://vim-jp.org/vimdoc-ja/sign.html
[* colorscheme]
:highlight SignColumn guibg=darkgrey
[* define] code:.vim :sign define piet text=>> texthl=Search
[* place] code:.vim :exe ":sign place 2 line=23 name=piet file=" . expand("%:p")
[* place] code:.vim :sign unplace 2
env
let $PATH = "c:\\Python38;".$PATH