"" My |vimrc|
" A |'textwidth'| of 79 is used throughout.
""" Comments
" Comments are written in Vim's help |notation|, see |help-writing|, which can
" be highlighted with
" https://git.rcrnstn.net/rcrnstn/vim-unobtrusive-vimcomments.
" Section headings are not written in |notation|, but are instead indicated
" with multiple comment characters, which can form folds with
" https://git.rcrnstn.net/rcrnstn/vim-unobtrusive-folds.
""" Compatibility
" This vimrc should work with all configurations of Vim. Manually tested with:
" - Features: tiny, huge (Debian `apt-get install vim-{tiny,gtk3}`)
" - Encodings/Locales: C, UTF-8 (`LC_ALL=C{,.UFT-8}`)
" - Colors: 1, 2, 8, 16, 256, termguicolors (`--cmd "set t_Co=$colors"`)
" - Terminals: GUI, VTE, Linux, tmux with the correct `Ss` terminal-override
" for the outer terminal
" - Platforms: Linux
""" Features
" |:version| says "tiny" features are always present and are therefore used in
" favor of more advanced features whenever possible. These include:
" - |+multi_byte|
" - |+mouse|
" - |+tag_binary|
" - |+user_commands|
" - |+autocmd|
" - |+localmap|
" Important features that are only present in "normal":
" - |+eval|
" |<Leader>| is hard-coded to <Space> so that mappings work without |+eval|.
" Note that trying to set unsupported options is silently ignored, and so can
" be done without checking for support first (which is good, since that
" requires |+eval|). Everything between |:if| and |:endif| is also silently
" ignored if |+eval| is not available.
""" Encoding
" |'encoding'| is hard-coded to `utf-8`. However, only characters present in
" Code Page 437 should be used in the interface, to ensure font support on most
" terminals (in particular, the Linux console). See
" - https://en.wikipedia.org/wiki/Code_page_347
" - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/tty/vt/cp437.uni
" - `man showconsolefont`
""" Auto commands
" At the time of writing, |augroup| messes up the highlighting of |autocmd|s
" within it, so the `vimrc` group name is added to every |autocmd| instead (the
" addition of the group of course makes the highlighting misinterpret it as the
" `vimAutoEventList` and the events instead get the erroneous
" `VimAutoCmdSfxList`... file a bug?). Don't forget!
"" Options
""" Reset
" set all&
""" Encoding
" Force Vim's internal encoding to a Unicode encoding.
set encoding=utf-8
""" Buffers
" Allow switching away from unsaved buffers.
set hidden
""" Clipboard
" Integrate with any graphical environment's clipboard.
set clipboard^=unnamedplus
""" Editing
set backspace=indent,eol,start
set virtualedit=block
""" Windows
" Put newly opened windows below and to the right.
set splitbelow
set splitright
""" Interface clutter
set noruler
set showcmd
set shortmess+=I
set guioptions=cf
""" Interface characters
" If |'t_Co'| is empty (or set to 1) the default behavior of |'fillchars'|
" `stl`/`stlnc` (`=`/`^`) will be used regardless of its setting. Other good
" choices for |'listchars'| `tab` is: `→ `, `――>`, `├──`, `──┤`, `├─┤`.
set list
set linebreak
set breakindent
set breakindentopt=sbr,shift:2
set fillchars=stl:_,stlnc:_,vert:│,fold:─,diff:\ |
set listchars=tab:├\ ┤,trail:•,extends:›,precedes:‹,nbsp:·
set showbreak=»\ |
""" Colors
if has('gui_running')
set t_Co=16777216
endif
if &t_Co > 16
set t_Co=16
endif
""" Title
set title
set titlestring=vim:%{fnamemodify(getcwd(),':~:t:s?^$?/?')}%(:%<%{pathshorten(expand('%:~:.'))}%)
""" Tabs
set expandtab
set shiftround
set shiftwidth=4
set softtabstop=-1
""" Mouse
set mouse=a
""" Command-line
set wildmenu
set wildmode=longest:full,full
set wildignore=.git,_*,node_modules
""" Search
set incsearch
set shortmess-=S
""" Timing
set lazyredraw
set notimeout
set ttimeout
set ttimeoutlen=100
""" Diffs
set diffopt+=vertical
set diffopt+=foldcolumn:0
""" Formatting
" See |auto-format|, |format-comments|, and |fo-table|.
set textwidth=79
" set colorcolumn=+1
set autoindent
set nojoinspaces
set formatoptions-=t
set formatoptions-=r
set formatoptions+=j
set formatoptions+=n
set nowrap
""" Folds
set foldlevelstart=999
set foldtext=substitute(getline(v:foldstart),'\\t',repeat('\ ',&ts),'g').'\ '
""" Spelling
set spell
set spelllang=en_us " May my ancestors forgive me.
if has('eval')
" Files downloaded from URL documented in |'thesaurus'|:
" https://github.com/vim/vim/issues/629#issuecomment-443293282.
let &thesaurus = split(&runtimepath, ',')[0] . '/thesaurus/en_us.txt'
endif
""" Views
set viewoptions-=folds
set viewoptions-=options
set viewoptions-=curdir
set viewoptions+=slash
set viewoptions+=unix
"" Mappings
""" Escape
" Overwrites the default |i_CTRL-C|, |v_CTRL-C|. See
" https://vim.fandom.com/wiki/Avoid_the_escape_key.
inoremap <C-C> <Esc>
xnoremap <C-C> <Esc>
""" Windows
nnoremap <C-H> <C-W>h
nnoremap <C-J> <C-W>j
nnoremap <C-K> <C-W>k
nnoremap <C-L> <C-W>l
tnoremap <C-H> <C-W>h
tnoremap <C-J> <C-W>j
tnoremap <C-K> <C-W>k
tnoremap <C-L> <C-W>l
""" `$MYVIMRC`
nnoremap <silent> <Space>ve :edit $MYVIMRC<CR>
nnoremap <silent> <Space>vs :source $MYVIMRC<CR>
""" Run command
nnoremap <Space>! :new \| .!
""" Run file
nnoremap <silent> <Space>% :!%:p:S<CR>
nnoremap <silent> <Space># :!#:p:S<CR>
""" Run `diff`
nnoremap <silent> <Space>d :w !diff --color -u %:S -<CR>
""" Run `make`
" TODO: |dispatch| provides default mappings, try to emulate them?
nnoremap <Space>m% :!make %:r:S<CR>
nnoremap <Space>m# :!make #:r:S<CR>
nnoremap <Space>mm :!make<CR>
nnoremap <Space>ma :!make all<CR>
nnoremap <Space>mt :!make test<CR>
nnoremap <Space>md :!make debug<CR>
if has('quickfix')
nnoremap <Space>m% :silent make! %:r:S \| redraw!<CR>
nnoremap <Space>m# :silent make! #:r:S \| redraw!<CR>
nnoremap <Space>mm :silent make! \| redraw!<CR>
nnoremap <Space>ma :silent make! all \| redraw!<CR>
nnoremap <Space>mt :silent make! test \| redraw!<CR>
endif
if has('terminal')
nnoremap <Space>md :terminal make debug<CR>
endif
""" Improve default mappings
"""" Disable unconditional quit from Normal mode
" As warned about in |zz| these may be typed accidentally when Caps Lock is
" enabled and lose data. Redefining them is a bit hostile towards other users,
" but deemed worth it.
nnoremap <silent> ZZ :quit<CR>
nnoremap <silent> ZQ :quit<CR>
"""" Easier access to black hole register with U
" This overrides the built-in "undo all on line". It is weird, counts as a
" change, and nobody uses it anyway.
nnoremap U "_
""""" Yank to end of line, not entire line
" As suggested in |Y|. This is analogous with |D| does `d$` and |C| does `c$`.
nnoremap Y y$
"""" Don't include newline in Visual mode `$`.
xnoremap $ $h
"""" Visual mode paste doesn't clobber unnamed register
xnoremap p pgvy
"""" Visually select last pasted text
" This is analogous with how |gv| visually selects last visually selected
" text. Default to always using ordinary Visual mode. Linewise and blockwise
" with |+eval| support.
nnoremap gp `[v`]
if has('eval')
nnoremap <expr> gp '`[' . getregtype()[0] . '`]'
endif
"""" Restrict Visual mode substitutions to the selected text
xnoremap <Space>s :s/\%V
""" Mouse
" As suggested in |scroll-mouse-wheel|, scroll only one line.
noremap <MouseUp> <C-E>
noremap <MouseDown> <C-Y>
""" Command-line
" Take already written text into account when searching history.
cnoremap <C-P> <Up>
cnoremap <C-N> <Down>
""" Macros
" Repeat the macro in register `q` on current line, lines covered by visual
" selection, or line covered by text object.
nnoremap QQ @q
xnoremap <silent> Q :normal! @q<CR>
nnoremap <silent> Q :set operatorfunc=<SID>Q<CR>g@
if has('eval')
function! s:Q(...) abort
'[,']normal! @q
endfunction
endif
""" Formatting
" Format comment (only). NOTE that this requires a `gc` comment text object
" plugin.
nmap gQ gqgc
nmap gW gwgc
""" Folds
" Focus current fold.
nnoremap zV zMzv
" Focus next/previous fold. Overwrites default move to start/end of
" next/previous fold.
nnoremap zj zvm<zjzvm>gvzc'>zv
nnoremap zk zvzcVoVgkzvgkzvzcVoVzv
" Open/close nested folds recursively. Overwrites default open/close fold under
" cursor recursively.
nnoremap <silent> zO zvzczO
nnoremap <silent> zC zvzcV:foldclose!<CR>zvzc
""" Spelling
" Correct last misspelled word with first suggestion without moving the cursor.
" See also |compl-spelling|.
nnoremap z? [s1z=<C-O>
inoremap <C-L> <C-G>u<Esc>[s1z=`]a<C-G>u
""" Visual mode operators
" Allows for visual selection of text objects that share a name with an
" operator.
nnoremap <silent> <Space>v :set operatorfunc=<SID>v<CR>g@
nnoremap <silent> <Space>V :set operatorfunc=<SID>V<CR>g@
nnoremap <silent> <Space><C-V> :set operatorfunc=<SID>CV<CR>g@
if has('eval')
function! s:v(...) abort
execute 'normal!' '`[v`]'
endfunction
function! s:V(...) abort
execute 'normal!' '`[V`]'
endfunction
function! s:CV(...) abort
execute 'normal!' "`[\<C-V>`]"
endfunction
endif
"" Auto command group
" Make sure to not define any |autocmd|s before this!
augroup vimrc
autocmd!
augroup END
"" Auto commands
""" Open the quickfix/location list window automatically.
" See
" - https://github.com/tpope/vim-dispatch/issues/145
" - https://github.com/tpope/vim-dispatch/issues/254
" - https://github.com/tpope/vim-dispatch/issues/310
" autocmd QuickFixCmdPost *{make,{,vim}grep}* nested botright cwindow
" autocmd QuickFixCmdPost *l{make,{,vim}grep}* nested botright lwindow
""" Highlight searches
" |'incsearch'| only highlights the first match.
autocmd vimrc CmdlineEnter /,\? set hlsearch
autocmd vimrc CmdlineLeave /,\? set nohlsearch
""" Save/load view
" As suggested in |:loadview|, load auto-saved view when opening buffer. Better
" than |last-position-jump|, |restore-cursor|.
autocmd BufWinEnter *
\ if !empty(expand('<afile>')) && empty(&buftype) |
\ loadview |
\ endif |
autocmd BufWinLeave *
\ if !empty(expand('<afile>')) && empty(&buftype) |
\ mkview |
\ endif |
"" Colors
" See |cterm-colors|, |gui-colors|. The greyscale hex values used for the GUI
" are CIELCHuv lightness 20, 60 and 80.
""" Defaults
" See |:hi-normal|, |:hi-normal-cterm|.
"""" Dark background and light foreground.
set background=dark
highlight! Normal guibg=#303030 guifg=#c6c6c6 ctermfg=White
""" Overrides
"""" Transparency
" Greyscale interface, dark red errors/warnings, light red spelling errors,
" bold white todos.
if !has('gui_running')
autocmd vimrc VimEnter,ColorScheme,OptionSet *
\ highlight! Normal guibg=NONE |
endif
" TODO: Look at all in |'highlight'|.
autocmd vimrc VimEnter,ColorScheme,OptionSet *
\ highlight! Normal term=NONE cterm=NONE gui=NONE ctermbg=NONE |
\ highlight! LineNr term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=Grey guifg=Grey |
\ highlight! FoldColumn term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=Grey guifg=Grey |
\ highlight! SignColumn term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=Grey guifg=Grey |
\ highlight! VertSplit term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=Grey guifg=Grey |
\ highlight! StatusLine term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=White guifg=White |
\ highlight! StatusLineNC term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=Grey guifg=Grey |
\ highlight! StatusLineTerm term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=White guifg=White |
\ highlight! StatusLineTermNC term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=Grey guifg=Grey |
\ highlight! TabLine term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=Grey guifg=Grey |
\ highlight! TabLineFill term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=Grey guifg=Grey |
\ highlight! TabLineSel term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=White guifg=White |
\ highlight! EndOfBuffer term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=Black guifg=Black |
\ highlight! Error term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=DarkRed guifg=Red |
\ highlight! ErrorMsg term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=DarkRed guifg=Red |
\ highlight! WarningMsg term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=DarkRed guifg=Red |
\ highlight! SpellBad term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=LightRed guifg=LightRed |
\ highlight! SpellLocal term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=LightRed guifg=LightRed |
\ highlight! SpellRare term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=LightRed guifg=LightRed |
\ highlight! SpellCap term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=LightRed guifg=LightRed |
\ highlight! Todo term=bold cterm=bold gui=NONE ctermbg=NONE guibg=NONE ctermfg=White guifg=White |
"""" Comments
autocmd vimrc VimEnter,ColorScheme,OptionSet *
\ highlight! Comment guifg=#919191 ctermfg=Grey
"""" Diffs
autocmd vimrc VimEnter,ColorScheme,OptionSet *
\ highlight! DiffAdd term=NONE cterm=NONE gui=NONE ctermfg=Black guifg=Black ctermbg=DarkGreen guibg=Green |
\ highlight! DiffDelete term=NONE cterm=NONE gui=NONE ctermfg=Black guifg=Black ctermbg=DarkRed guibg=Red |
\ highlight! DiffChange term=NONE cterm=NONE gui=NONE ctermfg=Black guifg=Black ctermbg=DarkBlue guibg=Blue |
\ highlight! DiffText term=NONE cterm=NONE gui=NONE ctermfg=Black guifg=Black ctermbg=DarkYellow guibg=Yellow |
\ highlight! diffAdded term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=DarkGreen guifg=Green |
\ highlight! diffRemoved term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=DarkRed guifg=Red |
"""" Folds
autocmd vimrc VimEnter,ColorScheme,OptionSet *
\ highlight! link Folded Comment |
"""" |'listchars'|
autocmd vimrc VimEnter,ColorScheme,OptionSet *
\ highlight! link SpecialKey Special |
\ highlight! link NonText Special |
"""" Vim comments
autocmd vimrc VimEnter,ColorScheme,OptionSet *
\ highlight! link vimCommentString vimComment |
\ highlight! link vimCommentTitle vimComment |
"" Plugins
if has('eval')
"" Package manager
" Make sure to not enable file type detection (|:syntax|, |:filetype|) until
" after all calls to `PackAdd` have been issued! See |:packadd|.
command! -bar -bang -nargs=1 PackAdd call s:PackAdd(<q-bang>, <f-args>)
function! s:PackAdd(bang, url) abort
let name = split(a:url, '/')[-1]
let dir = split(&packpath, ',')[0] . '/pack/add/opt/' . name
if !isdirectory(dir)
silent execute '!git clone --recurse-submodules' a:url dir
if isdirectory(dir . '/doc')
execute 'helptags' dir . '/doc'
endif
endif
if empty(a:bang)
execute 'packadd!' . name
endif
endfunction
"" File type
""" Built-in `vim`
let g:vim_indent_cont = 0
""" Built-in `man`
let g:ft_man_folding_enable = 1
runtime ftplugin/man.vim
set keywordprg=:Man
""" Built-in `markdown`
let g:vim_markdown_no_default_key_mappings = 1
""" `sheerun/vim-polyglot`
PackAdd https://github.com/sheerun/vim-polyglot
let g:polyglot_disabled = [
\ 'sensible',
\ 'autoindent',
\ ]
""" `tpope/vim-sleuth`
PackAdd https://github.com/tpope/vim-sleuth
""" `tpope/vim-apathy`
PackAdd https://github.com/tpope/vim-apathy
""" `tpope/vim-scriptease`
PackAdd https://github.com/tpope/vim-scriptease
""" `vimwiki/vimwiki`
" PackAdd https://github.com/vimwiki/vimwiki
" let g:vimwiki_list = [{
" \ 'path': '~/notes/',
" \ 'syntax': 'markdown',
" \ 'ext': '.md',
" \ }]
"" Normal mode
""" Built-in `matchit`
packadd! matchit
""" `tpope/vim-unimpaired`
PackAdd https://github.com/tpope/vim-unimpaired
""" `tpope/vim-repeat`
PackAdd https://github.com/tpope/vim-repeat
""" `tpope/vim-characterize`
PackAdd https://github.com/tpope/vim-characterize
""" `haya14busa/vim-asterisk`
PackAdd https://github.com/haya14busa/vim-asterisk
" As suggested by |asterisk-key-mappings|, except the mappings that don't
" move the cursor set |'hlsearch'|.
map * <Plug>(asterisk-*)
map # <Plug>(asterisk-#)
map g* <Plug>(asterisk-g*)
map g# <Plug>(asterisk-g#)
map <silent> z* <Plug>(asterisk-z*): set hlsearch<CR>
map <silent> z# <Plug>(asterisk-z#): set hlsearch<CR>
map <silent> zg* <Plug>(asterisk-gz*):set hlsearch<CR>
map <silent> zg# <Plug>(asterisk-gz#):set hlsearch<CR>
"" Insert mode
""" `tpope/vim-endwise`
PackAdd https://github.com/tpope/vim-endwise
"" Command-line mode
""" `tpope/vim-rsi`
PackAdd https://github.com/tpope/vim-rsi
""" `tpope/vim-abolish`
PackAdd https://github.com/tpope/vim-abolish
"" Operators
""" `tpope/vim-surround`
PackAdd https://github.com/tpope/vim-surround
""" `tpope/vim-commentary`
PackAdd https://github.com/tpope/vim-commentary
""" `tommcdo/vim-lion`
PackAdd https://github.com/tommcdo/vim-lion
"" Motions / text objects
""" `wellle/targets.vim`
PackAdd https://github.com/wellle/targets.vim
""" `qstrahl/vim-dentures`
PackAdd https://github.com/qstrahl/vim-dentures
""" `kana/vim-textobj-user`
PackAdd https://github.com/kana/vim-textobj-user
""" `kana/vim-textobj-line`
PackAdd https://github.com/kana/vim-textobj-line
""" `kana/vim-textobj-fold`
PackAdd https://github.com/kana/vim-textobj-fold
""" `idbrii/textobj-word-column.vim`
PackAdd https://github.com/idbrii/textobj-word-column.vim
""" `bkad/CamelCaseMotion`
PackAdd https://github.com/bkad/CamelCaseMotion
let g:camelcasemotion_key = '<Space>'
""" `tommcdo/vim-exchange`
PackAdd https://github.com/tommcdo/vim-exchange
"" Colors
""" `gruvbox-community/gruvbox`
PackAdd https://github.com/gruvbox-community/gruvbox
let g:gruvbox_contrast_dark = 'hard'
let g:gruvbox_invert_selection = 0
" Earlier settings indicate whether we want a color scheme not based on
" terminal colors. '|termguicolors|' is reset further down if not supported.
if &t_Co >= 256
set termguicolors
colorscheme gruvbox
endif
"" Windows
""" `moll/vim-bbye`
PackAdd https://github.com/moll/vim-bbye
"" Folds
""" `rcrnstn/vim-unobtrusive-foldexpr`
PackAdd https://git.rcrnstn.net/rcrnstn/vim-foldexpr-unobtrusive
" autocmd vimrc VimEnter * set commentstring=
" autocmd vimrc FileType * call foldexpr_unobtrusive#commentstring(&commentstring)
" autocmd vimrc FileType markdown call foldexpr_unobtrusive#char('#')
"" QuickFix
""" Built-in `cfilter`
packadd! cfilter
"" Operating system interaction
""" `ctrlpvim/ctrlp.vim`
PackAdd https://github.com/ctrlpvim/ctrlp.vim
let g:ctrlp_use_caching = 0
let g:ctrlp_working_path_mode = 'a'
let g:ctrlp_follow_symlinks = 1
let g:ctrlp_status_func = ''
let g:ctrlp_line_prefix = ''
if has('unix')
let g:ctrlp_user_command = 'find -L %s' .
\ ' \( -false' .
\ join(map(split(&wildignore, ','), '" -o -name " . shellescape(v:val)')) .
\ ' \) -prune' .
\ ' -o -type f -exec grep -Il . {} +'
endif
""" `tpope/vim-fugitive`
PackAdd https://github.com/tpope/vim-fugitive
""" `tpope/vim-dispatch`
PackAdd https://github.com/tpope/vim-dispatch
nnoremap <Space>m% :Make %:r:S<CR>
nnoremap <Space>m# :Make #:r:S<CR>
nnoremap <Space>mm :Make<CR>
nnoremap <Space>ma :Make all<CR>
nnoremap <Space>mt :Make test<CR>
""" `tpope/vim-eunuch`
PackAdd https://github.com/tpope/vim-eunuch
"" Debugging
""" `puremourning/vimspector`
" PackAdd https://github.com/puremourning/vimspector
" Debug Adapter Protocol (DAP) client. See
" https://microsoft.github.io/debug-adapter-protocol/.
""" `vim-vdebug/vdebug`
" PackAdd https://github.com/vim-vdebug/vdebug
" Common DeBugGer Protocol (DBGP) client. See
" https://en.wikipedia.org/wiki/DBGp.
endif " has('eval')
"" Syntax
if has('eval')
syntax enable
filetype plugin indent on
endif
"" File type overrides
" As suggested in |ft-syntax-omni|, use syntax completion if no other
" completion has been defined.
autocmd vimrc FileType *
\ if &omnifunc == '' |
\ setlocal omnifunc=syntaxcomplete#Complete |
\ endif |
autocmd vimrc FileType vim
\ setlocal formatoptions-=r
autocmd vimrc FileType man
\ setlocal nolist
autocmd vimrc FileType c,cpp
\ setlocal commentstring=//\ %s
"" Terminal overrides
" See |terminal-options|.
""" Cursor
" See |termcap-cursor-shape|, `:helpgrep t_SH`, and "Parameterized Strings" in
" `terminfo(5)`.
if has('cursorshape')
set noshowmode
let &t_vi = ''
let &t_ve = "\<Esc>[?25h"
" if $TERM =~? '^xterm\(-\|$\)'
" See
" - https://vt100.net/docs/vt510-rm/DECSCUSR
" - http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
let &t_EI = "\<Esc>[1 q"
let &t_SI = "\<Esc>[5 q"
let &t_SR = "\<Esc>[3 q"
let &t_SH = "\<Esc>[%p1%d q"
" endif
if $TERM =~? '^linux\(-\|$\)'
" See
" - https://www.kernel.org/doc/Documentation/admin-guide/vga-softcursor.rst
let &t_EI = "\<Esc>[?8c"
let &t_SI = "\<Esc>[?2c"
let &t_SR = "\<Esc>[?2c"
let &t_SH = "\<Esc>[?%?%p1%{3}%<%t%{8}%e%{2}%;%dc"
endif
endif
""" True-color
" See |xterm-true-color|.
if has('termguicolors')
" See https://github.com/termstandard/colors#truecolor-detection.
if empty($COLORTERM) && !has('vcon')
set notermguicolors
endif
" These are the defaults if `$TERM` is `xterm`.
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
" Terminal window does not have transparent background when 'termguicolors'
" is used. See http://ftp.vim.org/pub/vim/patches/8.2/8.2.3516.
if !has('patch-8.2.3516')
let s:termguicolors = &termguicolors
autocmd vimrc TerminalOpen,WinEnter *
\ let s:newtermguicolors =
\ s:termguicolors &&
\ empty(filter(range(1, bufnr('$')),
\ 'getbufvar(v:val, "&buftype") ==# "terminal"'
\ )) |
\ if s:newtermguicolors != &termguicolors |
\ execute 'set' (s:newtermguicolors ? '' : 'no') . 'termguicolors' |
\ endif |
endif
endif