" Don't set scriptencoding before 'encoding' option is set! " scriptencoding utf-8 " vim:set et fen fdm=marker: " See also: ~/.vimrc or ~/_vimrc let s:is_win = has('win32') let s:is_wsl = has('unix') && isdirectory('/mnt/c/') if s:is_win let $MYVIMDIR = expand('~/vimfiles') else let $MYVIMDIR = expand('~/.vim') endif " Use plain vim when vim was invoked by 'sudo' command. if exists('$SUDO_USER') finish endif if !exists('$VIMRC_USE_VIMPROC') " 0: vimproc disabled " 1: vimproc enabled " 2: each plugin default(auto) let $VIMRC_USE_VIMPROC = 1 endif if !exists('$VIMRC_FORCE_LANG_C') let $VIMRC_FORCE_LANG_C = 0 endif if !exists('$VIMRC_LOAD_MENU') let $VIMRC_LOAD_MENU = 0 endif " Macros {{{1 let s:macros = [] " :BulkMap {{{2 let s:macros += ['BulkMap'] command! -nargs=* BulkMap call s:cmd_map() function! s:cmd_map(args) abort let m = matchlist(a:args, '^\(.*\)\[\([nvxsoiclt]\+\)\]\(.*\)$') if empty(m) throw 'BulkMap: invalid arguments: ' . a:args endif let [l, modes, r] = m[1:3] let l = substitute(l, '', '', 'g') let nore = l is# m[1] ? '' : 'nore' let l = trim(l, " \t") let r = trim(r, " \t") for m in split(modes, '\zs') let cmd = printf('%s%smap %s %s', m, nore, l, r) " echom cmd execute cmd endfor endfunction " :Lazy {{{2 let s:macros += ['Lazy'] if has('vim_starting') command! -nargs=* Lazy autocmd vimrc VimEnter * else command! -nargs=* Lazy endif " Basic {{{1 " Reset all options let save_rtp = &rtp set all& let &rtp = save_rtp " Reset auto-commands augroup vimrc autocmd! augroup END if $VIMRC_FORCE_LANG_C language messages C language time C endif if !$VIMRC_LOAD_MENU set guioptions+=M let g:did_install_default_menus = 1 let g:did_install_syntax_menu = 1 endif filetype off filetype plugin indent on if filereadable(expand('$MYVIMDIR/vimrc.local')) execute 'source' expand('$MYVIMDIR/vimrc.local') endif " Encoding {{{1 let s:enc = 'utf-8' let &enc = s:enc let &fenc = s:enc let s:fencs = [s:enc] + split(&fileencodings, ',') + ['iso-2022-jp', 'iso-2022-jp-3', 'cp932'] let &fileencodings = join(filter(s:fencs, 'count(s:fencs, v:val) == 1'), ',') unlet s:fencs unlet s:enc scriptencoding utf-8 set fileformats=unix,dos,mac if exists('&ambiwidth') set ambiwidth=double endif " Options {{{1 set autoindent set backspace=indent,eol,start set browsedir=current set concealcursor=nvic set copyindent set diffopt+=vertical set display=lastline set expandtab set formatoptions+=j set formatoptions=mMcroqnl2 set history=1000 set hlsearch set ignorecase set incsearch set keywordprg= set list set matchpairs+=<:> set nofixeol set noshowcmd set notimeout set ttimeout set ttimeoutlen=100 set nrformats-=octal set number set preserveindent set pumheight=20 set scrolloff=5 set sessionoptions-=options set shiftround set shiftwidth=2 set shortmess+=aI set shortmess-=S set showtabline=2 set smartcase set softtabstop=-1 set t_Co=256 set tabstop=8 set textwidth=80 set whichwrap=b,s set wildmenu set wildmode=longest,list,full if has('path_extra') set tags+=.; set tags+=tags; set path+=.; endif " Assumption: Trailing spaces are already highlighted and noticeable. " set listchars=tab:>.,extends:>,precedes:<,trail:-,eol:$ set listchars=tab:>.,extends:>,precedes:<,trail:- " Swapfile if 1 " Use swapfile. set swapfile set directory=$MYVIMDIR/info/swap// silent! call mkdir(substitute(&directory, '//$', '', ''), 'p') " Open a file as read-only if swap exists " autocmd vimrc SwapExists * let v:swapchoice = 'o' else " No swapfile. set noswapfile set updatecount=0 endif " Backup set backup set backupdir=$MYVIMDIR/info/backup// silent! call mkdir(substitute(&backupdir, '//$', '', ''), 'p') " Title set title let &titlestring = '%{getcwd()}' " guitablabel {{{ let &guitablabel = '%{MyTabLabel(v:lnum)}' function! MyTabLabel(tabnr) let buflist = tabpagebuflist(a:tabnr) let bufname = '' let modified = 0 if type(buflist) ==# 3 let bufname = bufname(buflist[tabpagewinnr(a:tabnr) - 1]) let bufname = fnamemodify(bufname, ':t') " let bufname = pathshorten(bufname) for bufnr in buflist if getbufvar(bufnr, '&modified') let modified = 1 break endif endfor endif if bufname ==# '' let label = '[No Name]' else let label = bufname endif return label . (modified ? '[+]' : '') endfunction " }}} " statusline {{{ set laststatus=2 let &statusline = \ '%f%( [%M%R%H%W]%)%( [%{&ft}]%) %{&fenc}/%{&ff}' \ . '%( %{line(".")}/%{line("$")}%)' " }}} " Unofficial patches {{{ " https://rbtnn.github.io/vim/ " disable when running as git commit editor if has('tabsidebar') && !exists('$GIT_EXEC_PATH') set showtabline=0 set showtabsidebar=2 set tabsidebarcolumns=20 set tabsidebarwrap endif " http://h-east.github.io/vim/ if has('clpum') set wildmode=longest,popup set wildmenu set clpumheight=40 set clcompleteopt-=noinsert endif " }}} " 'guioptions' flags are set on FocusGained " because "cmd.exe start /min" doesn't work. " (always start up as foreground) augroup vimrc-guioptions autocmd! augroup END if has('vim_starting') command! -nargs=* FocusGained autocmd FocusGained vimrc-guioptions * command! -nargs=* FocusGainedEnd autocmd FocusGained vimrc-guioptions * autocmd! vimrc-guioptions else command! -nargs=* FocusGained command! -nargs=* FocusGainedEnd : endif " Must be set in .vimrc " set guioptions+=p FocusGained set guioptions-=a FocusGained set guioptions+=A " Include 'e': tabline " Otherwise : guitablabel FocusGained set guioptions-=e FocusGained set guioptions+=h FocusGained set guioptions+=m FocusGained set guioptions-=L FocusGained set guioptions-=T FocusGainedEnd delcommand FocusGained delcommand FocusGainedEnd " convert "\\" to "/" on win32 like environment if exists('+shellslash') set shellslash endif " Visual bell set novisualbell set t_vb= " Restore screen set norestorescreen set t_ti= set t_te= " Undo persistence if has('persistent_undo') set undofile set undodir=$MYVIMDIR/info/undo silent! call mkdir(&undodir, 'p') endif " jvgrep if executable('jvgrep') set grepprg=jvgrep endif " Font {{{2 if has('gui_running') if s:is_win if exists('+renderoptions') " If 'renderoptions' option exists, set renderoptions=type:directx,renmode:5 " ... and if "Ricty_Diminished" font is installed, " enable DirectWrite. try set guifont=Ricty_Diminished_Discord:h14:cSHIFTJIS catch | endtry endif elseif has('mac') " Mac set guifont=Osaka-等幅:h14 set printfont=Osaka-等幅:h14 else " *nix OS try set guifont=Monospace\ 12 set printfont=Monospace\ 12 set linespace=0 catch set guifont=Monospace\ 12 set printfont=Monospace\ 12 set linespace=4 endtry endif endif " ColorScheme {{{1 try colorscheme spring-night " https://github.com/rhysd/vim-color-spring-night/issues/7 Lazy hi SignColumn term=NONE guibg=#ffffff ctermbg=255 " for diff Lazy hi FoldColumn term=NONE guibg=#ffffff ctermbg=255 catch /E185/ colorscheme desert endtry " too annoying " highlight ColorColumn ctermfg=12 guifg=Red ctermbg=NONE guibg=NONE " Mappings, Abbreviations {{{1 " General prefix keys {{{2 BulkMap [nxo] (vimrc:prefix:excmd) " fallback BulkMap [nxo] (vimrc:prefix:excmd) let g:mapleader = '\' let g:maplocalleader = '\' nnoremap nnoremap " Operators {{{2 " Do not destroy noname register. BulkMap [nxo] x "_x " Text-objects {{{2 onoremap gv :normal! gv " Motions {{{2 " Go to the next/previous line whose first character is not space. BulkMap [nxo] [k (go-prev-first-non-blank) BulkMap [nxo] ]k (go-next-first-non-blank) BulkMap [nx] (go-prev-first-non-blank) first_non_blank('Wbn') BulkMap [o] (go-prev-first-non-blank) 'V' . first_non_blank('Wbn') BulkMap [nx] (go-next-first-non-blank) first_non_blank('Wn') BulkMap [o] (go-next-first-non-blank) 'V' . first_non_blank('Wn') function! s:first_non_blank(flags) abort let lnum = search('^\S', a:flags) return lnum > 0 ? lnum . 'G' : '' endfunction BulkMap [nxo] gp % " }}} " Do not scroll over the last line " http://itchyny.hatenablog.com/entry/2016/02/02/210000 BulkMap [nxo] max([winheight(0) - 2, 1]) . "\" . (line('.') > line('$') - winheight(0) ? 'L' : 'H') " At the first/last screen row, scroll also lines not screen view BulkMap [nxo] line('w0') <= 1 ? 'k' : "\" BulkMap [nxo] line('w$') >= line('$') ? 'j' : "\" " Fold {{{2 nmap z (vimrc:prefix:fold) xmap z (vimrc:prefix:fold) omap z (vimrc:prefix:fold) " fallback nnoremap (vimrc:prefix:fold) z xnoremap (vimrc:prefix:fold) z onoremap (vimrc:prefix:fold) z " Open only current line's fold. nnoremap (vimrc:prefix:fold) zMzvzz " GUI: Save current file with {{{2 if has('gui_running') inoremap