" set encoding=utf-8 scriptencoding utf-8 " ↑1行目は読み込み時の文字コードの設定 " ↑2行目はVim Script内でマルチバイトを使う場合の設定 " Vim scritptにvimrcも含まれるので、日本語でコメントを書く場合は先頭にこの設定が必要になる set autowrite " 自動保存モード let mapleader = "," "リーダーキーマップ noremap \ , "---------------------------------------------------------- " 文字 "---------------------------------------------------------- set fileencoding=utf-8 " 保存時の文字コード set fileencodings=ucs-boms,utf-8,euc-jp,cp932 " 読み込み時の文字コードの自動判別. 左側が優先される set fileformats=unix,dos,mac " 改行コードの自動判別. 左側が優先される set ambiwidth=double " □や○文字が崩れる問題を解決 "---------------------------------------------------------- " ステータスライン "---------------------------------------------------------- set laststatus=2 " ステータスラインを常に表示 set showmode " 現在のモードを表示 set showcmd " 打ったコマンドをステータスラインの下に表示 set ruler " ステータスラインの右側にカーソルの位置を表示する "---------------------------------------------------------- " コマンドモード "---------------------------------------------------------- set wildmenu " コマンドモードの補完 set history=5000 " 保存するコマンド履歴の数 "---------------------------------------------------------- " タブ・インデント "---------------------------------------------------------- set expandtab " タブ入力を複数の空白入力に置き換える set tabstop=2 " 画面上でタブ文字が占める幅 set softtabstop=2 " 連続した空白に対してタブキーやバックスペースキーでカーソルが動く幅 set autoindent " 改行時に前の行のインデントを継続する set smartindent " 改行時に前の行の構文をチェックし次の行のインデントを増減する set shiftwidth=2 " smartindentで増減する幅 "---------------------------------------------------------- " 文字列検索 "---------------------------------------------------------- set incsearch " インクリメンタルサーチ. 1文字入力毎に検索を行う set ignorecase " 検索パターンに大文字小文字を区別しない set smartcase " 検索パターンに大文字を含んでいたら大文字小文字を区別する set hlsearch " 検索結果をハイライト " ESCキー2度押しでハイライトの切り替え nnoremap :set nohlsearch! "---------------------------------------------------------- " カーソル "---------------------------------------------------------- set whichwrap=b,s,h,l,<,>,[,],~ " カーソルの左右移動で行末から次の行の行頭への移動が可能になる set number " 行番号を表示 set cursorline " カーソルラインをハイライト " 行が折り返し表示されていた場合、行単位ではなく表示行単位でカーソルを移動する nnoremap j gj nnoremap k gk nnoremap gj nnoremap gk " バックスペースキーの有効化 set backspace=indent,eol,start " 入力モード時のカーソル移動 noremap! noremap! noremap! noremap! " 入力モードでカーソルの形状を変える let &t_ti.="\e[1 q" let &t_SI.="\e[5 q" let &t_EI.="\e[1 q" let &t_te.="\e[0 q" "---------------------------------------------------------- " バッファリスト "---------------------------------------------------------- nnoremap [b :bprevious nnoremap ]b :bnext nnoremap [B :bfirst nnoremap ]B :blast "---------------------------------------------------------- " カッコ・タグの対応 "---------------------------------------------------------- set showmatch " 括弧の対応関係を一瞬表示する source $VIMRUNTIME/macros/matchit.vim " Vimの「%」を拡張する "---------------------------------------------------------- " マウスでカーソル移動とスクロール "---------------------------------------------------------- if has('mouse') set mouse=a if has('mouse_sgr') set ttymouse=sgr elseif v:version > 703 || v:version is 703 && has('patch632') "set ttymouse=sgr else set ttymouse=xterm2 endif endif "---------------------------------------------------------- " クリップボードからのペースト "---------------------------------------------------------- " 挿入モードでクリップボードからペーストする時に自動でインデントさせないようにする if &term =~ "xterm" let &t_SI .= "\e[?2004h" let &t_EI .= "\e[?2004l" let &pastetoggle = "\e[201~" function XTermPasteBegin(ret) set paste return a:ret endfunction inoremap [200~ XTermPasteBegin("") endif "---------------------------------------------------------- " ファイル保存 "---------------------------------------------------------- nnoremap :w inoremap :w "---------------------------------------------------------- " パッケージマネージャ "---------------------------------------------------------- let $CACHE = expand('~/.cache') if !isdirectory($CACHE) call mkdir($CACHE, 'p') endif if &runtimepath !~# '/dein.vim' let s:dein_dir = fnamemodify('dein.vim', ':p') if !isdirectory(s:dein_dir) let s:dein_dir = $CACHE .. '/dein/repos/github.com/Shougo/dein.vim' if !isdirectory(s:dein_dir) execute '!git clone https://github.com/Shougo/dein.vim' s:dein_dir endif endif let s:dein_path = substitute(fnamemodify(s:dein_dir, ':p'), '[/\\]$', '', '') execute 'set runtimepath^=' . s:dein_path endif if &compatible set nocompatible endif let s:dein_dir = expand('~/.cache/dein') let s:dein_repo_dir = s:dein_dir . '/repos/github.com/Shougo/dein.vim' " dein.vimが存在していない場合はgithubからclone 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) call dein#add('Shougo/dein.vim') " カラースキーム call dein#add('tomasr/molokai') call dein#add('raphamorim/lucario') call dein#add('jacoborus/tender.vim') " ステータスライン表示 call dein#add('vim-airline/vim-airline') call dein#add('vim-airline/vim-airline-themes') call dein#add('itchyny/lightline.vim') " インデントの可視化 call dein#add('Yggdroot/indentLine') " 末尾の全角半角空白文字を赤くハイライト call dein#add('bronson/vim-trailing-whitespace') " 構文エラーチェック call dein#add('scrooloose/syntastic') " 多機能セレクタ call dein#add('ctrlpvim/ctrlp.vim') call dein#add('tacahiroy/ctrlp-funky') call dein#add('suy/vim-ctrlp-commandline') call dein#add('rking/ag.vim') call dein#add('mattn/ctrlp-matchfuzzy') " ファイルツリー call dein#add('preservim/nerdtree') " 開発 call dein#add('airblade/vim-gitgutter') call dein#add('tpope/vim-fugitive') call dein#add('neoclide/coc.nvim', {'merged': 0, 'rev': 'release'}) call dein#add('fatih/vim-go') call dein#add('AndrewRadev/splitjoin.vim') call dein#add('puremourning/vimspector') call dein#add('vim-test/vim-test') call dein#add('tpope/vim-dispatch') call dein#add('github/copilot.vim') call dein#add('rust-lang/rust.vim') call dein#add('OmniSharp/omnisharp-vim') call dein#add('OrangeT/vim-csharp') call dein#add('ionide/ionide-vim') call dein#add('uiiaoo/java-syntax.vim') call dein#add('neovimhaskell/haskell-vim') call dein#add('vim-ruby/vim-ruby') call dein#add('stanangeloff/php.vim') call dein#add('phpactor/phpactor', {'on_ft': 'php'}) call dein#add('Olical/conjure') call dein#add('clojure-vim/clojure.vim') call dein#add('tpope/vim-fireplace', {'on_ft': 'clojure'}) call dein#add('elixir-editors/vim-elixir') call dein#add('derekwyatt/vim-scala') call dein#add('ludovicchabant/vim-gutentags') call dein#end() call dein#save_state() endif filetype plugin indent on syntax enable " If you want to install not installed plugins on startup. if dein#check_install() call dein#install() endif "---------------------------------------------------------- " カラースキーム "---------------------------------------------------------- colorscheme lucario " カラースキームにlucarioを設定する set t_Co=256 " iTerm2など既に256色環境なら無くても良い syntax enable " 構文に色を付ける "---------------------------------------------------------- " ステータスライン表示 "---------------------------------------------------------- set showtabline=2 let g:airline_powerline_fonts = 1 let g:airline_theme = 'luna' let g:airline#extensions#tabline#enabled = 1 let g:airline#extensions#tabline#buffer_idx_mode = 1 "---------------------------------------------------------- " 構文エラーチェック "---------------------------------------------------------- " 構文エラー行に「>>」を表示 let g:syntastic_enable_signs = 1 " 他のVimプラグインと競合するのを防ぐ let g:syntastic_always_populate_loc_list = 1 " 構文エラーリストを非表示 let g:syntastic_auto_loc_list = 0 " ファイルを開いた時に構文エラーチェックを実行する let g:syntastic_check_on_open = 1 " 「:wq」で終了する時も構文エラーチェックする let g:syntastic_check_on_wq = 1 " Javascript用. 構文エラーチェックにESLintを使用 let g:syntastic_javascript_checkers=['eslint'] " Javascript以外は構文エラーチェックをしない let g:syntastic_mode_map = { 'mode': 'passive', \ 'active_filetypes': ['javascript'], \ 'passive_filetypes': [] } "---------------------------------------------------------- " 多機能セレクタ "---------------------------------------------------------- let g:ctrlp_match_window = 'order:ttb,min:20,max:20,results:100' " マッチウインドウの設定. 「下部に表示, 大きさ20行で固定, 検索結果100件」 let g:ctrlp_show_hidden = 1 " .(ドット)から始まるファイルも検索対象にする let g:ctrlp_types = ['fil'] "ファイル検索のみ使用 let g:ctrlp_extensions = ['funky', 'commandline'] " CtrlPの拡張として「funky」と「commandline」を使用 " NERDTreeの設定 let g:NERDTreeShowHidden = 1 nnoremap e :NERDTreeToggle nnoremap ef :NERDTreeFind " gutentagsの設定 let g:gutentags_enabled = 1 let g:gutentags_generate_on_missing = 1 set tags=./tags;,tags " CtrlPCommandLineの有効化 command! CtrlPCommandLine call ctrlp#init(ctrlp#commandline#id()) " CtrlPFunkyの絞り込み検索設定 let g:ctrlp_funky_matchtype = 'path' if executable('ag') let g:ctrlp_use_caching=0 " CtrlPのキャッシュを使わない let g:ctrlp_user_command='ag %s -i --hidden -g ""' " 「ag」の検索設定 endif "---------------------------------------------------------- " 開発 "---------------------------------------------------------- "vim-fugitive nnoremap ga :Git add %:p nnoremap gc :Git commit nnoremap gs :Git nnoremap gp :Git push nnoremap gd :Gdiffsplit nnoremap gl :Gclog nnoremap gb :Git blame "coc-nvim " May need for Vim (not Neovim) since coc.nvim calculates byte offset by count " utf-8 byte sequence set encoding=utf-8 " Some servers have issues with backup files, see #649 set nobackup set nowritebackup " Having longer updatetime (default is 4000 ms = 4s) leads to noticeable " delays and poor user experience set updatetime=300 " Always show the signcolumn, otherwise it would shift the text each time " diagnostics appear/become resolved set signcolumn=yes " Use tab for trigger completion with characters ahead and navigate " NOTE: There's always complete item selected by default, you may want to enable " no select by `"suggest.noselect": true` in your configuration file " NOTE: Use command ':verbose imap ' to make sure tab is not mapped by " other plugin before putting this into your config inoremap \ coc#pum#visible() ? coc#pum#next(1) : \ CheckBackspace() ? "\" : \ coc#refresh() inoremap coc#pum#visible() ? coc#pum#prev(1) : "\" " Make to accept selected completion item or notify coc.nvim to format " u breaks current undo, please make your own choice inoremap coc#pum#visible() ? coc#pum#confirm() \: "\u\\=coc#on_enter()\" function! CheckBackspace() abort let col = col('.') - 1 return !col || getline('.')[col - 1] =~# '\s' endfunction " Use to trigger completion if has('nvim') inoremap coc#refresh() else inoremap coc#refresh() endif " Use `[g` and `]g` to navigate diagnostics " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list nmap [g (coc-diagnostic-prev) nmap ]g (coc-diagnostic-next) " GoTo code navigation nmap gd (coc-definition) nmap gy (coc-type-definition) nmap gi (coc-implementation) nmap gr (coc-references) " Use K to show documentation in preview window nnoremap K :call ShowDocumentation() function! ShowDocumentation() if exists('*CocAction') && CocAction('hasProvider', 'hover') call CocActionAsync('doHover') else call feedkeys('K', 'in') endif endfunction " Highlight the symbol and its references when holding the cursor autocmd CursorHold * if exists('*CocActionAsync') | silent call CocActionAsync('highlight') | endif " Symbol renaming nmap rn (coc-rename) " Formatting selected code xmap f (coc-format-selected) nmap f (coc-format-selected) augroup mygroup autocmd! " Setup formatexpr specified filetype(s) autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') " Update signature help on jump placeholder autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') augroup end " Applying code actions to the selected code block " Example: `aap` for current paragraph xmap a (coc-codeaction-selected) nmap a (coc-codeaction-selected) " Remap keys for applying code actions at the cursor position nmap ac (coc-codeaction-cursor) " Remap keys for apply code actions affect whole buffer nmap as (coc-codeaction-source) " Apply the most preferred quickfix action to fix diagnostic on the current line nmap qf (coc-fix-current) " Remap keys for applying refactor code actions nmap re (coc-codeaction-refactor) xmap r (coc-codeaction-refactor-selected) nmap r (coc-codeaction-refactor-selected) " Run the Code Lens action on the current line nmap cl (coc-codelens-action) " Map function and class text objects " NOTE: Requires 'textDocument.documentSymbol' support from the language server xmap if (coc-funcobj-i) omap if (coc-funcobj-i) xmap af (coc-funcobj-a) omap af (coc-funcobj-a) xmap ic (coc-classobj-i) omap ic (coc-classobj-i) xmap ac (coc-classobj-a) omap ac (coc-classobj-a) " Remap and to scroll float windows/popups if has('nvim-0.4.0') || has('patch-8.2.0750') nnoremap coc#float#has_scroll() ? coc#float#scroll(1) : "\" nnoremap coc#float#has_scroll() ? coc#float#scroll(0) : "\" inoremap coc#float#has_scroll() ? "\=coc#float#scroll(1)\" : "\" inoremap coc#float#has_scroll() ? "\=coc#float#scroll(0)\" : "\" vnoremap coc#float#has_scroll() ? coc#float#scroll(1) : "\" vnoremap coc#float#has_scroll() ? coc#float#scroll(0) : "\" endif " Use CTRL-R for selections ranges " Requires 'textDocument/selectionRange' support of language server nmap (coc-range-select) xmap (coc-range-select) " Add `:Format` command to format current buffer command! -nargs=0 Format :call CocActionAsync('format') " Add `:Fold` command to fold current buffer command! -nargs=? Fold :call CocAction('fold', ) " Add `:OR` command for organize imports of the current buffer command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport') " Add (Neo)Vim's native statusline support " NOTE: Please see `:h coc-status` for integrations with external plugins that " provide custom statusline: lightline.vim, vim-airline set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} " Mappings for CoCList " Show all diagnostics nnoremap a :CocList diagnostics " Manage extensions nnoremap e :CocList extensions " Show commands nnoremap c :CocList commands " Find symbol of current document nnoremap o :CocList outline " Search workspace symbols nnoremap s :CocList -I symbols " Do default action for next item nnoremap j :CocNext " Do default action for previous item nnoremap k :CocPrev " Resume latest coc list nnoremap p :CocListResume "vim-go map :cnext map :cprevious nnoremap a :cclose function! s:build_go_files() let l:file = expand('%') if l:file =~# '^\f\+_test\.go$' call go#test#Test(0, 1) elseif l:file =~# '^\f\+\.go$' call go#cmd#Build(0) endif endfunction autocmd FileType go nmap b :call build_go_files() autocmd FileType go nmap r (go-run) let g:go_list_type = "quickfix" autocmd FileType go nmap t (go-test) autocmd FileType go nmap T (go-test-func) autocmd FileType go nmap c (go-coverage-toggle) let g:go_highlight_types = 1 let g:go_highlight_fields = 1 let g:go_highlight_functions = 1 let g:go_highlight_function_calls = 1 autocmd Filetype go command! -bang A call go#alternate#Switch(0, 'edit') autocmd Filetype go command! -bang AV call go#alternate#Switch(0, 'vsplit') autocmd Filetype go command! -bang AS call go#alternate#Switch(0, 'split') autocmd Filetype go command! -bang AT call go#alternate#Switch(0, 'tabe') let g:go_def_mode = 'godef' let g:go_decls_includes = "func,type" let g:go_auto_sameids = 1 let g:go_debug_windows = { \ 'vars': '60vnew', \ 'stack': '10new', \ } "vimspector nnoremap dd :call vimspector#Launch() nnoremap de :call vimspector#Reset() nnoremap dc :call vimspector#Continue() nnoremap dt :call vimspector#ToggleBreakpoint() nnoremap dT :call vimspector#ClearBreakpoints() nmap dk VimspectorRestart nmap dh VimspectorStepOut nmap dl VimspectorStepInto nmap dj VimspectorStepOver "vim-test nmap t :TestNearest nmap T :TestFile nmap a :TestSuite nmap l :TestLast nmap g :TestVisit let g:test#strategy = 'dispatch' "---------------------------------------------------------- " 言語別設定 "---------------------------------------------------------- " Rust let g:rustfmt_autosave = 1 " .NET (OmniSharp) let g:OmniSharp_server_use_mono = 0 let g:OmniSharp_selector_ui = 'ctrlp' let g:OmniSharp_highlight_types = 3 " Java " uiiaoo/java-syntax.vim はデフォルトで有効 " Haskell let g:haskell_enable_quantification = 1 " enable highlighting of `forall` let g:haskell_enable_recursivedo = 1 " enable highlighting of `mdo` and `rec` let g:haskell_enable_arrowsyntax = 1 " enable highlighting of `proc` let g:haskell_enable_pattern_synonyms = 1 " enable highlighting of `pattern` let g:haskell_enable_typeroles = 1 " enable highlighting of type roles let g:haskell_enable_static_pointers = 1 " enable highlighting of `static` let g:haskell_backpack = 1 " enable highlighting of backpack keywords " Ruby autocmd FileType ruby setlocal expandtab shiftwidth=2 tabstop=2 " PHP autocmd FileType php setlocal expandtab shiftwidth=4 tabstop=4 " Elixir autocmd FileType elixir setlocal expandtab shiftwidth=2 tabstop=2 " Scala autocmd FileType scala setlocal expandtab shiftwidth=2 tabstop=2 " F# autocmd FileType fsharp setlocal expandtab shiftwidth=4 tabstop=4