set encoding=utf-8 scriptencoding utf-8 " _ _ _ _ " (_) (_) | (_) " _ _ __ _| |___ ___ _ __ ___ " | | '_ \| | __\ \ / / | '_ ` _ \ " | | | | | | |_ \ V /| | | | | | | " |_|_| |_|_|\__(_)_/ |_|_| |_| |_| " @kawarimidoll " https://twitter.com/kawarimidoll " https://github.com/kawarimidoll let $CACHE = expand('~/.cache') if !isdirectory(expand($CACHE)) call mkdir(expand($CACHE), 'p') endif " load secrets if filereadable(expand('~/.secret_vimrc')) execute 'source' expand('~/.secret_vimrc') endif "----------------- " dein scripts "----------------- if &compatible set nocompatible endif set runtimepath+=~/.cache/dein/repos/github.com/Shougo/dein.vim if dein#load_state('$CACHE/dein') call dein#begin('$CACHE/dein') call dein#load_toml('~/.config/nvim/dein.toml') call dein#end() call dein#save_state() endif filetype plugin indent on syntax enable " Install not installed plugins on startup automatically if dein#check_install() call dein#install() endif "----------------- " Options "----------------- set ambiwidth=single set autoindent set autoread set autowrite set background=dark set backspace=indent,eol,start set clipboard=unnamed set cmdheight=2 set completeopt=longest,menu set cursorline set display=lastline set expandtab set fenc=utf-8 set fileencoding=utf-8 set fileencodings=utf-8 set fileformats=unix,dos,mac set formatoptions=tcqmMj1 set helplang=ja set hidden set history=200 set hlsearch set ignorecase set incsearch set infercase set laststatus=2 set lazyredraw set linebreak set list set listchars=tab:^-,trail:~,extends:»,precedes:«,nbsp:% set matchtime=1 set nobackup set nomodeline set noshowmode set noswapfile set nowritebackup set nrformats= set number set ruler set scrolloff=5 set shiftround set shiftwidth=2 set showcmd set showmatch set showtabline=2 set shortmess+=c set signcolumn=yes set smartcase set smartindent set softtabstop=2 set splitbelow set splitright set switchbuf=usetab set t_Co=256 set tabstop=2 set textwidth=0 set title set ttyfast set updatetime=300 set whichwrap=b,s,h,l,<,>,[,],~ set wildmenu set wildmode=list:longest,full set wrap set wrapscan "----------------- " Commands and Functions "----------------- command! Rcedit edit $MYVIMRC command! Rcreload write | source $MYVIMRC | nohlsearch | redraw | echo 'init.vim is reloaded.' command! Deinedit edit ~/.config/nvim/dein.toml command! Deinupdate call dein#check_update(v:true) " command! LazyGit tab terminal lazygit " command! Lg LazyGit " command! FmtTabTrail retab | FixWhitespace " command! DenoFmt echo system("deno fmt --quiet ".expand("%:p")) | edit | echo 'deno fmt current file' command! CopyFullPath let @*=expand('%:p') | echo 'copy full path' command! CopyDirName let @*=expand('%:h') | echo 'copy dir name' command! CopyFileName let @*=expand('%:t') | echo 'copy file name' command! -nargs=* T split | wincmd j | resize 12 | terminal " [Vimの生産性を高める12の方法 | POSTD](https://postd.cc/how-to-boost-your-vim-productivity/) function! s:VisualPaste() let clipboard_options = split(&clipboard, ",") let restore_reg = index(clipboard_options, "unnamed") >= 0 ? @* : @" function! RestoreRegister() closure if index(clipboard_options, "unnamed") >= 0 let @* = restore_reg if index(clipboard_options, "unnamedplus") >= 0 let @+ = restore_reg endif else let @" = restore_reg endif return '' endfunction return "p@=RestoreRegister()\" endfunction " " [vimのマーク機能をできるだけ活用してみる - Make 鮫 noise](http://saihoooooooo.hatenablog.com/entry/2013/04/30/001908) " let g:mark_chars = ['h', 'j', 'k', 'l'] " function! s:AutoMark() abort " let b:mark_pos = exists('b:mark_pos') ? (b:mark_pos + 1) % len(g:mark_chars) : 0 " execute 'normal! m' . g:mark_chars[b:mark_pos] " echo 'auto-marked' g:mark_chars[b:mark_pos] " endfunction " function! s:AutoJump() abort " if !exists('b:mark_pos') " echo 'not auto-marked yet.' " return " endif " execute 'normal! `' . g:mark_chars[b:mark_pos] " echo 'jumped to mark' g:mark_chars[b:mark_pos] " endfunction " " " [neovim terminal](https://gist.github.com/pocari/fd0622fb5ec6946a368e8ee0603979ae) " " terminalの終了時にバッファを消すフック " function! s:onTermExit(job_id, code, event) dict " " Process Exitが表示されたその後cr打つとバッファが無くなるので " " それと同じようにする " call feedkeys("\") " endfun " function! s:DenoRepl() abort " only | echo 'deno repl' | split | wincmd j | resize 12 | execute 'terminal deno' " endfun " command! -bang DenoRepl call s:DenoRepl() function! s:DenoTerm() abort let l:filename = expand('%:p') let l:cmd = l:filename =~ '\(\.\|_\)\?test\.\(ts\|tsx\|js\|mjs\|jsx\)$' \ ? 'test' : 'run' only | echo '' | split | wincmd j | resize 12 | \ execute 'terminal deno ' . l:cmd . \ ' -A --no-check --unstable --watch ' . l:filename | \ stopinsert | execute 'normal! G' | \ set bufhidden=wipe | wincmd k endfun command! -bang DenoRun call s:DenoTerm() " braces motion " (count)+braces+action " [ to effect prev, ] to effect next " m to move, t to copy, o to add blank line " use capital to fix cursor position " nnoremap [m ':move-' . (v:count1 + 1) . '=l' " nnoremap ]m ':move+' . v:count1 . '=l' " nnoremap [M ':move-' . (v:count1 + 1) . '=l' . v:count1 . 'j' " nnoremap ]M ':move+' . v:count1 . '=l' . v:count1 . 'k' " nnoremap [t ':copy-' . v:count1 . '=l' " nnoremap ]t ':copy+' . (v:count1 - 1) . '=l' " nnoremap [T 'mz:copy-' . v:count1 . '=l`z:delmarks z' " nnoremap ]T 'mz:copy+' . (v:count1 - 1) . '=l`z:delmarks z' " nnoremap [o '' . v:count1 . 'O' . (v:count ? v:count - 1 . 'k' : '') " nnoremap ]o '' . v:count1 . 'o' " nnoremap [O 'mz' . v:count1 . 'O`z:delmarks z' " nnoremap ]O 'mz' . v:count1 . 'o`z:delmarks z' " xnoremap [m :move'<-2gv=gv " xnoremap ]m :move'>+1gv=gv " xnoremap [M :move'<-2gv=gvj " xnoremap ]M :move'>+1gv=gvk " xnoremap [t :copy'<-2gv=gv " xnoremap ]t :copy'>+1gv=gv " xnoremap [T :copy'<-2gv=gvj " xnoremap ]T :copy'>+1gv=gvk "----------------- " Key mappings " :map ノーマル、ビジュアル、選択、オペレータ待機 " :nmap ノーマル " :vmap ビジュアル、選択 " :smap 選択 " :xmap ビジュアル " :omap オペレータ待機 " :map! 挿入、コマンドライン " :imap 挿入 " :lmap 挿入、コマンドライン、Lang-Arg " :cmap コマンドライン " :tmap 端末ジョブ "----------------- " global noremap j gj noremap k gk noremap gj j noremap gk k noremap gV `[v`] noremap H ^ noremap L $ noremap [b :bprevious noremap ]b :bnext noremap [B :bfirst noremap ]B :blast noremap [q :cprevious noremap ]q :cnext noremap [Q :cfirst noremap ]Q :clast " map n (anzu-n)zz " map N (anzu-N)zz map M % " " z*はssにマッピングするが通常のsの動作を潰すため1個の場合も登録しておく " map s (asterisk-z*)(anzu-update-search-status)zz " map ss (asterisk-z*)(anzu-update-search-status)zz " map sg (asterisk-gz*)(anzu-update-search-status)zz " map ef (easymotion-bd-f) " map el (easymotion-bd-jk) " map ew (easymotion-bd-w) " for sandwich " TODO: s to visual search nmap s xmap s " normal " nnoremap mm :call AutoMark() " nnoremap m, :call AutoJump() " nnoremap S :%s/\V///g " [Vim で q を prefix キーにする - 永遠に未完成](https://thinca.hatenablog.com/entry/q-as-prefix-key-in-vim) " nnoremap