884 lines
31 KiB
Plaintext
884 lines
31 KiB
Plaintext
" (jump to the topic)
|
|
"
|
|
" PLUGIN_INSTALL
|
|
" UTILITIES
|
|
" PLUGIN_CONFIGURATION
|
|
" THEME_CONFIGURATION
|
|
" KEY_MAPS
|
|
" OTHER_CONFIGS
|
|
|
|
" PLUGIN_INSTALL
|
|
" {
|
|
" Plugin environment
|
|
let g:mydotfiles_directory = expand('~/.dotfiles/')
|
|
let s:plugin_dir = expand('~/.vim/plugged/')
|
|
|
|
call plug#begin(s:plugin_dir)
|
|
|
|
" https://github.com/junegunn/vim-plug/wiki/tips
|
|
function! Cond(cond, ...)
|
|
let opts = get(a:000, 0, {})
|
|
return a:cond ? opts : extend(opts, { 'on': [], 'for': [] })
|
|
endfunction
|
|
|
|
Plug 'gelguy/wilder.nvim', Cond(!exists('g:vscode'))
|
|
" To use Python remote plugin features in Vim for wilder, can be skipped
|
|
" Plug 'roxma/nvim-yarp', Cond(g:vim_type == 'vim')
|
|
" Plug 'roxma/vim-hug-neovim-rpc', Cond(g:vim_type == 'vim')
|
|
|
|
Plug 'dstein64/vim-startuptime', Cond(!exists('g:vscode'))
|
|
Plug 'simeji/winresizer', Cond(!exists('g:vscode'))
|
|
Plug 'rust-lang/rust.vim', { 'for': ['rust'] }
|
|
|
|
Plug 'machakann/vim-sandwich'
|
|
Plug 'rhysd/conflict-marker.vim'
|
|
|
|
Plug 'jiangmiao/auto-pairs'
|
|
" Plug 'mg979/vim-visual-multi'
|
|
Plug 'RRethy/vim-illuminate', Cond(!exists('g:vscode'))
|
|
|
|
"Plug 'easymotion/vim-easymotion'
|
|
Plug 'vim-scripts/restore_view.vim'
|
|
Plug 'mhinz/vim-startify', Cond(!exists('g:vscode'))
|
|
|
|
Plug 'christoomey/vim-tmux-navigator', Cond(!exists('g:vscode'))
|
|
Plug 'NLKNguyen/papercolor-theme', Cond(!exists('g:vscode'))
|
|
Plug 'airblade/vim-rooter'
|
|
Plug 'roxma/vim-tmux-clipboard', Cond(executable('tmux'))
|
|
|
|
" Comment stuff out
|
|
Plug 'tpope/vim-commentary'
|
|
|
|
Plug 'ludovicchabant/vim-gutentags', Cond(!exists('g:vscode'), { 'for': ['c', 'cpp'] })
|
|
" Plug 'lambdalisue/readablefold.vim'
|
|
|
|
Plug 'liuchengxu/vista.vim'
|
|
" only work with vim
|
|
if g:vim_type == 'vim'
|
|
set encoding=UTF-8
|
|
|
|
if executable('fzf')
|
|
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
|
|
Plug 'junegunn/fzf.vim'
|
|
Plug 'antoinemadec/coc-fzf'
|
|
endif
|
|
|
|
Plug 'scrooloose/nerdtree', { 'on' : ['NERDTreeToggle', 'NERDTreeFind'] }
|
|
Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
|
|
Plug 'vim-airline/vim-airline'
|
|
Plug 'vim-airline/vim-airline-themes'
|
|
" The bottom buffer display
|
|
Plug 'Donaldttt/vim-bufferline'
|
|
Plug 'ryanoasis/vim-devicons'
|
|
Plug 'sainnhe/everforest'
|
|
endif
|
|
|
|
if executable('node')
|
|
Plug 'neoclide/coc.nvim', Cond(!exists('g:vscode'), {'branch': 'release'})
|
|
endif
|
|
|
|
if g:vim_type == 'nvim'
|
|
if g:vim_version >= 0.5
|
|
Plug 'xiyaowong/nvim-transparent', Cond(!exists('g:vscode'))
|
|
Plug 'lukas-reineke/indent-blankline.nvim', Cond(!exists('g:vscode'))
|
|
Plug 'EdenEast/nightfox.nvim', Cond(!exists('g:vscode'))
|
|
Plug 'projekt0n/github-nvim-theme', Cond(!exists('g:vscode'), { 'tag': 'v0.0.7' })
|
|
|
|
Plug 'nvim-lualine/lualine.nvim', Cond(!exists('g:vscode'))
|
|
|
|
endif
|
|
if g:vim_version >= 0.7
|
|
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
|
|
|
|
" for telescope
|
|
Plug 'nvim-lua/plenary.nvim', Cond(!exists('g:vscode'))
|
|
Plug 'nvim-telescope/telescope.nvim', Cond(!exists('g:vscode'), { 'tag': '0.1.x' })
|
|
if executable('make')
|
|
" c plugin for telescope to make it faster
|
|
Plug 'nvim-telescope/telescope-fzf-native.nvim', Cond(!exists('g:vscode'), { 'do': 'make' })
|
|
endif
|
|
|
|
" comment out this plugin if the machine doesn't have required
|
|
" font install
|
|
Plug 'nvim-tree/nvim-web-devicons', Cond(!exists('g:vscode'))
|
|
endif
|
|
if g:vim_version >= 0.8
|
|
Plug 'nvim-tree/nvim-tree.lua', Cond(!exists('g:vscode'))
|
|
endif
|
|
if g:vim_version < 0.8
|
|
Plug 'scrooloose/nerdtree', Cond(!exists('g:vscode'))
|
|
endif
|
|
endif
|
|
|
|
call plug#end()
|
|
|
|
" Automatically install missing plugins at startup
|
|
autocmd VimEnter *
|
|
\ if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
|
|
\| PlugInstall --sync | q
|
|
\| endif
|
|
" }
|
|
|
|
" UTILITIES
|
|
" {
|
|
function! HasPlug(plug_name, ...)
|
|
let plug_dir_name = get(a:, 1, a:plug_name) " optional argument for the name of plug's folder
|
|
if has_key(g:plugs, a:plug_name) && isdirectory(s:plugin_dir . "/" . plug_dir_name)
|
|
if has_key(g:plugs[a:plug_name], 'for') || has_key(g:plugs[a:plug_name], 'on')
|
|
if (has_key(g:plugs[a:plug_name], 'for') && len(g:plugs[a:plug_name]['for']) == 0) ||
|
|
\ (has_key(g:plugs[a:plug_name], 'on') && len(g:plugs[a:plug_name]['on']) == 0)
|
|
return v:false
|
|
endif
|
|
endif
|
|
return v:true
|
|
endif
|
|
return v:false
|
|
endfunction
|
|
|
|
" display the name of the buffers which are displaied on screen
|
|
" like command :ls! a
|
|
function! GetActiveBuffers()
|
|
" let l:blist = getbufinfo({'bufloaded': 1, 'buflisted': 1})
|
|
let l:blist = getbufinfo({'bufloaded': 1})
|
|
let l:result = []
|
|
for l:item in l:blist
|
|
"skip unnamed buffers; also skip hidden buffers?
|
|
if empty(l:item.name) || l:item.hidden
|
|
continue
|
|
endif
|
|
" call add(l:result, { 'name' : shellescape(l:item.name), 'bufnr' : l:item.bufnr })
|
|
call add(l:result, l:item.bufnr )
|
|
endfor
|
|
return l:result
|
|
endfunction
|
|
|
|
" }
|
|
|
|
" PLUGIN_CONFIGURATION
|
|
" {
|
|
|
|
if HasPlug('vista.vim')
|
|
let g:vista_default_executive = 'coc'
|
|
nnoremap <silent> <leader>v :Vista!!<CR>
|
|
let g:vista_cursor_delay = 0
|
|
let g:vista_echo_cursor = 0
|
|
let g:vista_echo_cursor_strategy = 'floating_win'
|
|
let g:vista_close_on_jump = 0
|
|
let g:vista_floating_delay = 0
|
|
let g:vista_ignore_kinds = ['Variable', 'Field', 'EnumMember',
|
|
\ 'String', 'Object', 'Array', 'Constant', 'Package', 'Boolean', 'Number'
|
|
\ ]
|
|
let g:vista_floating_border = 'rounded'
|
|
let g:vista_disable_statusline = 1
|
|
" let g:vista_keep_fzf_colors = 1
|
|
let g:vista_update_on_text_changed_delay = 0
|
|
let g:vista_update_on_text_changed = 1
|
|
let g:vista#renderer#enable_kind = 1
|
|
let g:vista#renderer#enable_icon = 1
|
|
|
|
let g:vista_last_raw = v:null
|
|
function VistaCursorJump()
|
|
" let found = vista#util#BinarySearch(g:vista.raw, line('.'), 'line', '')
|
|
let found = g:vista_last_raw
|
|
if empty(found)
|
|
return
|
|
endif
|
|
let vlnum = get(found, 'vlnum', v:null)
|
|
call cursor(vlnum, 3)
|
|
endfunction
|
|
|
|
function VistaH2()
|
|
if exists('*vista#util#BinarySearch')
|
|
let bufs = map(filter(copy(getbufinfo()), 'v:val.listed'), 'v:val.bufnr')
|
|
if index(bufs, bufnr('%')) > 0
|
|
return
|
|
endif
|
|
let found = vista#util#BinarySearch(g:vista.raw, line('.'), 'line', '')
|
|
if empty(found)
|
|
return
|
|
endif
|
|
let g:vista_last_raw = found
|
|
endif
|
|
endfunction
|
|
|
|
autocmd BufLeave * call VistaH2()
|
|
autocmd FileType vista call VistaCursorJump()
|
|
|
|
function VistaHelper()
|
|
if winnr('$') == 1 && bufname() == "__vista__"
|
|
let bufs = map(filter(copy(getbufinfo()), 'v:val.listed'), 'v:val.bufnr')
|
|
if len(bufs) > 1
|
|
execute("normal! :bw\<CR>")
|
|
else
|
|
execute "normal! :q!\<CR>"
|
|
endif
|
|
endif
|
|
endfunction
|
|
|
|
" close vista when it is the last window
|
|
" autocmd BufEnter * if winnr('$') == 1 && bufname() == "__vista__" | execute "normal! :q!\<CR>" | endif
|
|
" autocmd BufEnter * call VistaHelper()
|
|
|
|
endif
|
|
|
|
if HasPlug('indentLine')
|
|
let g:indentLine_fileTypeExclude = ['startify']
|
|
endif
|
|
|
|
if HasPlug('vim-illuminate') && g:vim_type == 'vim'
|
|
let g:Illuminate_ftHighlightGroups = {
|
|
\ 'vim': ['vimVar', 'vimString', 'vimFuncName',
|
|
\ 'vimFunction', 'vimUserFunc', 'vimFunc'],
|
|
\ 'java:blacklist' : [ 'javaType', 'javaScopeDecl', 'javaMethodDecl',
|
|
\ 'javaComment', 'javaStorageClass', 'javaClassDecl', 'javaExternal',
|
|
\ 'javaTypedef', 'javaLineComment', 'javaStatement', 'javaCommentTitle', 'javaDocComment' ]
|
|
\ }
|
|
let g:Illuminate_ftwhitelist = ['vim', 'sh', 'python', 'rust', 'java', 'c', 'cpp', 'javascript', 'typescript', 'lua']
|
|
|
|
augroup illuminate_augroup
|
|
autocmd!
|
|
" autocmd VimEnter * hi link illuminatedWord CursorLine
|
|
autocmd VimEnter * hi illuminatedWord cterm=underline gui=underline
|
|
autocmd ColorScheme * hi illuminatedWord cterm=underline gui=underline
|
|
augroup END
|
|
endif
|
|
|
|
if HasPlug('wilder.nvim')
|
|
|
|
call wilder#setup({
|
|
\ 'modes': [':'],
|
|
\ 'next_key': '<tab>',
|
|
\ 'enable_cmdline_enter': 0,
|
|
\ })
|
|
|
|
call wilder#set_option('pipeline', [
|
|
\ wilder#debounce(10),
|
|
\ wilder#branch(
|
|
\ wilder#cmdline_pipeline({'language': has('nvim') ? 'python' : 'vim'}),
|
|
\ ),
|
|
\ ])
|
|
call wilder#set_option('renderer', wilder#popupmenu_renderer())
|
|
endif
|
|
|
|
if HasPlug('vim-tmux-navigator')
|
|
let g:tmux_navigator_no_mappings = 1
|
|
|
|
noremap <silent> <c-h> :<C-U>TmuxNavigateLeft<cr>
|
|
noremap <silent> <c-j> :<C-U>TmuxNavigateDown<cr>
|
|
noremap <silent> <c-k> :<C-U>TmuxNavigateUp<cr>
|
|
noremap <silent> <c-l> :<C-U>TmuxNavigateRight<cr>
|
|
" noremap <silent> {Previous-Mapping} :<C-U>TmuxNavigatePrevious<cr>
|
|
endif
|
|
|
|
" mhinz/vim-startify {
|
|
if HasPlug("vim-startify")
|
|
if g:vim_type == 'nvim'
|
|
let buffer_str_len = (&columns - 60) / 2
|
|
let buf_str = repeat(' ', buffer_str_len)
|
|
let g:startify_custom_header = [
|
|
\ buf_str . ' __ __ ________ ______ __ __ ______ __ __ ',
|
|
\ buf_str . '| \ | \| \ / \ | \ | \| \| \ / \',
|
|
\ buf_str . '| $$\ | $$| $$$$$$$$| $$$$$$\| $$ | $$ \$$$$$$| $$\ / $$',
|
|
\ buf_str . '| $$$\| $$| $$__ | $$ | $$| $$ | $$ | $$ | $$$\ / $$$',
|
|
\ buf_str . '| $$$$\ $$| $$ \ | $$ | $$ \$$\ / $$ | $$ | $$$$\ $$$$',
|
|
\ buf_str . '| $$\$$ $$| $$$$$ | $$ | $$ \$$\ $$ | $$ | $$\$$ $$ $$',
|
|
\ buf_str . '| $$ \$$$$| $$_____ | $$__/ $$ \$$ $$ _| $$_ | $$ \$$$| $$',
|
|
\ buf_str . '| $$ \$$$| $$ \ \$$ $$ \$$$ | $$ \| $$ \$ | $$',
|
|
\ buf_str . ' \$$ \$$ \$$$$$$$$ \$$$$$$ \$ \$$$$$$ \$$ \$$',
|
|
\]
|
|
else
|
|
let buffer_str_len = (&columns - 30) / 2
|
|
let buf_str = repeat(' ', buffer_str_len)
|
|
let g:startify_custom_header = [
|
|
\ buf_str . ' __ __ ______ __ __ ',
|
|
\ buf_str . '| \ | \| \| \ / \',
|
|
\ buf_str . '| $$ | $$ \$$$$$$| $$\ / $$',
|
|
\ buf_str . '| $$ | $$ | $$ | $$$\ / $$$',
|
|
\ buf_str . ' \$$\ / $$ | $$ | $$$$\ $$$$',
|
|
\ buf_str . ' \$$\ $$ | $$ | $$\$$ $$ $$',
|
|
\ buf_str . ' \$$ $$ _| $$_ | $$ \$$$| $$',
|
|
\ buf_str . ' \$$$ | $$ \| $$ \$ | $$',
|
|
\ buf_str . ' \$ \$$$$$$ \$$ \$$',
|
|
\]
|
|
endif
|
|
|
|
let g:startify_lists = [
|
|
\ { 'header': [' RECENT'], 'type': 'files' },
|
|
\ { 'header': [' SESSIONS'], 'type': 'sessions' },
|
|
\ ]
|
|
|
|
" session related KeyBinding. These KeyBinding uses function from startify
|
|
nnoremap <silent> <leader><leader>s :SSave!<CR>
|
|
nnoremap <silent> <leader><leader>l :SLoad<CR>
|
|
nnoremap <silent> <leader><leader>d :SDelete!<CR>
|
|
nnoremap <silent> <leader><leader>c :SClose<CR>
|
|
|
|
endif
|
|
" }
|
|
"
|
|
" ryanoasis/vim-devicons {
|
|
if HasPlug("vim-devicons")
|
|
let g:webdevicons_enable_airline_statusline = 0
|
|
endif
|
|
" }
|
|
"
|
|
" simeji/winresizer {
|
|
if HasPlug("winresizer")
|
|
let g:winresizer_vert_resize = 2
|
|
let g:winresizer_horiz_resize = 2
|
|
nnoremap <C-w>r :WinResizerStartResize<CR>
|
|
endif
|
|
" }
|
|
|
|
" ludovicchabant/vim-gutentags {
|
|
if HasPlug("vim-gutentags")
|
|
if exists("*gutentags#statusline()")
|
|
set statusline+=%{gutentags#statusline()}
|
|
endif
|
|
let g:gutentags_cache_dir=g:vim_dir . '/.vimtags/'
|
|
let g:gutentags_project_root=['.git', '.hg', '.svn', '.bzr', '_darcs', '_FOSSIL_', '.fslckout', 'src']
|
|
endif
|
|
" }
|
|
|
|
" easymotion/vim-easymotion {
|
|
if HasPlug("vim-easymotion")
|
|
" <Leader>f{char} to move to {char}
|
|
map <Leader>f <Plug>(easymotion-bd-f)
|
|
nmap <Leader>f <Plug>(easymotion-overwin-f)
|
|
|
|
" s{char}{char} to move to {char}{char}
|
|
nmap s <Plug>(easymotion-overwin-f2)
|
|
|
|
" Move to line
|
|
map <Leader>L <Plug>(easymotion-bd-jk)
|
|
nmap <Leader>L <Plug>(easymotion-overwin-line)
|
|
|
|
" Move to word
|
|
map <Leader>w <Plug>(easymotion-bd-w)
|
|
nmap <Leader>w <Plug>(easymotion-overwin-w)
|
|
endif
|
|
|
|
" }
|
|
|
|
" antoinemadec/coc-fzf {
|
|
if HasPlug("coc-fzf")
|
|
" nnoremap <silent> <space><space> :<C-u>CocFzfList<CR>
|
|
" nnoremap <leader>o :<C-u>CocFzfList outline<CR>
|
|
endif
|
|
" }
|
|
|
|
" bling/vim-bufferline {
|
|
if HasPlug("vim-bufferline") && HasPlug("vim-airline")
|
|
let g:bufferline_echo = 0
|
|
let g:bufferline_modified = '+'
|
|
|
|
" scrolling with fixed current buffer position
|
|
|
|
let g:bufferline_active_buffer_left = ''
|
|
let g:bufferline_active_buffer_right = ''
|
|
" let g:bufferline_inactive_highlight = 'StatusLineNC'
|
|
" let g:bufferline_active_highlight = 'StatusLine'
|
|
endif
|
|
|
|
" }
|
|
|
|
" mbbill/undotree {
|
|
if HasPlug("undotree")
|
|
nnoremap <leader>ut :UndotreeToggle<CR>
|
|
endif
|
|
" }
|
|
|
|
" airblade/vim-rooter {
|
|
if HasPlug("vim-rooter")
|
|
let g:rooter_patterns = ['.vscode', '.git', '*.sln', 'src']
|
|
let g:rooter_change_directory_for_non_project_files = 'current'
|
|
let g:rooter_silent_chdir = 1
|
|
endif
|
|
" }
|
|
|
|
" NerdTree {
|
|
if (g:vim_type == 'vim' || g:vim_version < 0.8) && HasPlug('nerdtree')
|
|
if HasPlug('vim-nerdtree-syntax-highlight')
|
|
let g:NERDTreeLimitedSyntax = 1
|
|
endif
|
|
let g:NERDShutUp=1
|
|
|
|
" work around for nerdtree bug: https://github.com/preservim/nerdtree/issues/1321
|
|
let g:NERDTreeMinimalMenu = v:true
|
|
let g:NERDTreeMinimalUI = v:true
|
|
|
|
"nnoremap <C-e> :NERDTreeToggle<CR>
|
|
function! NERDTreeFindToggle()
|
|
let my_filetype = &filetype
|
|
let specical_fts = ['nerdtree', 'startify']
|
|
if my_filetype == '' || index(specical_fts, my_filetype) >= 0
|
|
:NERDTreeToggle
|
|
else
|
|
:NERDTreeFind
|
|
endif
|
|
endfunction
|
|
nnoremap <silent> <leader>e :call NERDTreeFindToggle()<CR>
|
|
|
|
"let NERDTreeShowBookmarks=1
|
|
"let NERDTreeIgnore=['\.py[cd]$', '\~$', '\.swo$', '\.swp$', '^\.git$', '^\.hg$', '^\.svn$', '\.bzr$']
|
|
let NERDTreeChDirMode = 0
|
|
let NERDTreeQuitOnOpen = 1
|
|
let NERDTreeMouseMode = 2
|
|
let NERDTreeShowHidden = 1
|
|
|
|
if HasPlug('vim-devicons') || HasPlug('nerdfont.vim')
|
|
let NERDTreeDirArrowCollapsible = ''
|
|
let NERDTreeDirArrowExpandable = ''
|
|
else
|
|
" let NERDTreeDirArrowCollapsible = ''
|
|
" let NERDTreeDirArrowExpandable = ''
|
|
endif
|
|
" Exit Vim if NERDTree is the only window remaining in the only tab.
|
|
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
|
|
endif
|
|
" }
|
|
|
|
" nvim-tree.lua {
|
|
if g:vim_type == 'nvim' && HasPlug("nvim-tree.lua")
|
|
endif
|
|
" }
|
|
|
|
" vim-airline {
|
|
if HasPlug("vim-airline")
|
|
" Set configuration options for the statusline plugin vim-airline.
|
|
" Use the powerline theme and optionally enable powerline symbols.
|
|
|
|
" This must using my fork version of bufferline
|
|
"
|
|
let g:bufferline_max_length = &columns - 22
|
|
function! BufferNumber()
|
|
return len(g:index_to_buffer)
|
|
endfunction
|
|
call airline#parts#define_function('bufnum', 'BufferNumber')
|
|
|
|
let g:airline_extensions = ['bufferline']
|
|
let g:airline_section_x = airline#section#create(['bufnum'])
|
|
let g:airline_section_y = ''
|
|
let g:airline_section_z = airline#section#create(['filetype'])
|
|
let g:airline_skip_empty_sections = 1
|
|
let g:airline_exclude_filetypes = ['vista']
|
|
" see source for current list
|
|
let g:airline#extensions#nerdtree_statusline = 0
|
|
|
|
" without this airline will overwrite some setting like bufferline_active_buffer_left, etc.
|
|
let g:airline#extensions#bufferline#overwrite_variables = 0
|
|
let g:airline_mode_map = {
|
|
\ '__' : '-',
|
|
\ 'c' : 'C',
|
|
\ 'i' : 'I',
|
|
\ 'ic' : 'I',
|
|
\ 'ix' : 'I',
|
|
\ 'n' : 'N',
|
|
\ 'multi' : 'M',
|
|
\ 'ni' : 'N',
|
|
\ 'no' : 'N',
|
|
\ 'R' : 'R',
|
|
\ 'Rv' : 'R',
|
|
\ 's' : 'S',
|
|
\ 'S' : 'S',
|
|
\ '' : 'S',
|
|
\ 't' : 'T',
|
|
\ 'v' : 'V',
|
|
\ 'V' : 'V',
|
|
\ '' : 'V',
|
|
\ }
|
|
|
|
if HasPlug("vim-airline-themes/")
|
|
"let g:airline_theme = 'solarized'
|
|
endif
|
|
endif
|
|
" }
|
|
"endif
|
|
|
|
" junegunn/fzf {
|
|
if HasPlug("fzf") && HasPlug("fzf.vim")
|
|
" [Buffers] Jump to the existing window if possible
|
|
let g:fzf_buffers_jump = 1
|
|
|
|
"let $FZF_DEFAULT_COMMAND='find . \( -name node_modules -o -name .git \) -prune -o -print'
|
|
|
|
" - Preview window on the right with 50% width
|
|
" - CTRL-/ will toggle preview window.
|
|
if g:os == 'Windows'
|
|
let g:fzf_preview_window = []
|
|
else
|
|
let g:fzf_preview_window = ['right:50%', 'ctrl-/']
|
|
end
|
|
|
|
" check if ripgrep is installed
|
|
if ! executable('rg')
|
|
command! -bang -nargs=* Rg
|
|
\ call fzf#vim#grep(
|
|
\ 'grep -R --line-number --exclude-dir=".git;.svn" --color=always -- '.shellescape(<q-args>), 1,
|
|
\ fzf#vim#with_preview(), <bang>0)
|
|
endif
|
|
noremap <leader><leader>r :Rg<CR>
|
|
noremap <leader><leader>f :Files<CR>
|
|
endif
|
|
" }
|
|
|
|
" neoclide/coc.nvim {
|
|
if HasPlug("coc.nvim") && executable('node')
|
|
" coc-clangd: c/c++, may need to install clangd seperatly
|
|
|
|
if filereadable(g:mydotfiles_directory . "/coc-nvim-config.vim")
|
|
exec "source " . g:mydotfiles_directory . "/coc-nvim-config.vim"
|
|
endif
|
|
" warning that coc work best for vim >= 8.3
|
|
let g:coc_disable_startup_warning = 1
|
|
endif
|
|
|
|
" }
|
|
" }
|
|
|
|
" THEME_CONFIGURATION
|
|
" {
|
|
"
|
|
" debug function print out highlight group of cursor position
|
|
function! SynStack()
|
|
if !exists("*synstack")
|
|
return
|
|
endif
|
|
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
|
|
|
|
:echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
|
|
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
|
|
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"
|
|
|
|
endfunc
|
|
|
|
nmap <Leader>db :call SynStack()<CR>
|
|
|
|
" search and filter highlight group
|
|
" :call Sh('airline')
|
|
function! Sh(pattern)
|
|
execute("filter /" . a:pattern . "/ highlight")
|
|
endfunc
|
|
|
|
" dark or light
|
|
if filereadable(g:vim_dir . '.light_theme.signal')
|
|
let g:dark_or_light_theme = 'light'
|
|
else
|
|
let g:dark_or_light_theme = 'dark'
|
|
endif
|
|
|
|
" what to use for dark theme
|
|
let g:dark_theme = 'default'
|
|
" let g:airline_dark_theme = "violet"
|
|
let g:airline_dark_theme = "angr"
|
|
|
|
" what to use for light theme
|
|
let g:light_theme = 'default'
|
|
let g:airline_light_theme = "silver"
|
|
|
|
" delete signal file if exist
|
|
function! DeleteSignalFile(name)
|
|
if filereadable(g:vim_dir . a:name)
|
|
call delete(g:vim_dir . a:name)
|
|
endif
|
|
endfunction
|
|
|
|
" Create signal file if not exist
|
|
function! CreateSignalFile(name)
|
|
call system("touch " . g:vim_dir . a:name)
|
|
endfunction
|
|
|
|
function! SignalFileExists(filename)
|
|
if filereadable(g:vim_dir . a:filename)
|
|
return v:true
|
|
endif
|
|
return v:false
|
|
endfunction
|
|
|
|
" transparent backgroud for supported terminal emulator
|
|
" check if transparent_dark_theme.signl or transparent_light_theme.signl
|
|
" exist and set respect variable
|
|
let g:transparent_dark_theme = v:false
|
|
let g:transparent_light_theme = v:false
|
|
if SignalFileExists('.transparent_dark_theme.signal')
|
|
let g:transparent_dark_theme = v:true
|
|
endif
|
|
if SignalFileExists('.transparent_light_theme.signal')
|
|
let g:transparent_light_theme = v:true
|
|
endif
|
|
|
|
function! SetDarkTheme()
|
|
set background=dark
|
|
hi clear
|
|
execute("colorscheme " . g:dark_theme)
|
|
let g:dark_or_light_theme = 'dark'
|
|
endfunction
|
|
|
|
function! SetLightTheme()
|
|
set background=light
|
|
hi clear
|
|
execute("colorscheme " . g:light_theme)
|
|
let g:dark_or_light_theme = 'light'
|
|
endfunction
|
|
|
|
" Change bottom airline/lualine theme
|
|
function! SetStatusLineTheme(theme)
|
|
if g:vim_type == 'nvim' && g:vim_version >= 0.5
|
|
" lualine will change theme automatically
|
|
else
|
|
if HasPlug('vim-airline') && HasPlug('vim-airline-themes')
|
|
execute('AirlineTheme ' . a:theme)
|
|
endif
|
|
endif
|
|
endfunction
|
|
|
|
" Fix colorscheme not working correctly under transparent background
|
|
function! TransparentBackgroundFix()
|
|
if !has('nvim') || g:vim_version < 0.5
|
|
endif
|
|
endfunction
|
|
|
|
let g:custom_transparent_function_enable = ''
|
|
let g:custom_transparent_function_disable = ''
|
|
function! EnableTransparent()
|
|
if g:custom_transparent_function_enable != ''
|
|
execute('call ' . g:custom_transparent_function_enable)
|
|
return
|
|
endif
|
|
if g:vim_type == 'nvim' && g:vim_version > 0.5
|
|
:TransparentEnable
|
|
else
|
|
if g:dark_or_light_theme == 'dark'
|
|
let g:PaperColor_Theme_Options = {
|
|
\ 'theme': {
|
|
\ 'default.dark': {
|
|
\ 'transparent_background': 1
|
|
\ }
|
|
\ }
|
|
\ }
|
|
execute("colorscheme " . g:dark_theme)
|
|
elseif g:dark_or_light_theme == 'light'
|
|
let g:PaperColor_Theme_Options = {
|
|
\ 'theme': {
|
|
\ 'default.light': {
|
|
\ 'transparent_background': 1
|
|
\ }
|
|
\ }
|
|
\ }
|
|
execute("colorscheme " . g:light_theme)
|
|
endif
|
|
endif
|
|
endfunction
|
|
|
|
function! DisableTransparent()
|
|
if g:custom_transparent_function_disable != ''
|
|
execute('call ' . g:custom_transparent_function_disable)
|
|
return
|
|
endif
|
|
if g:vim_type == 'nvim' && g:vim_version > 0.5
|
|
:TransparentDisable
|
|
else
|
|
if g:dark_or_light_theme == 'dark'
|
|
let g:PaperColor_Theme_Options = {
|
|
\ 'theme': {
|
|
\ 'default.dark': {
|
|
\ 'transparent_background': 0
|
|
\ }
|
|
\ }
|
|
\ }
|
|
execute("colorscheme " . g:dark_theme)
|
|
elseif g:dark_or_light_theme == 'light'
|
|
let g:PaperColor_Theme_Options = {
|
|
\ 'theme': {
|
|
\ 'default.light': {
|
|
\ 'transparent_background': 0
|
|
\ }
|
|
\ }
|
|
\ }
|
|
execute("colorscheme " . g:light_theme)
|
|
endif
|
|
endif
|
|
endfunction
|
|
|
|
" ToggleTransparent background
|
|
" only works in dark theme
|
|
function! ToggleTransparent()
|
|
if g:transparent_dark_theme && g:dark_or_light_theme == 'dark'
|
|
call DisableTransparent()
|
|
let g:transparent_dark_theme = v:false
|
|
call DeleteSignalFile('.transparent_dark_theme.signal')
|
|
elseif g:transparent_light_theme && g:dark_or_light_theme == 'light'
|
|
call DisableTransparent()
|
|
let g:transparent_light_theme = v:false
|
|
call DeleteSignalFile('.transparent_light_theme.signal')
|
|
else
|
|
call EnableTransparent()
|
|
if g:dark_or_light_theme == 'dark'
|
|
let g:transparent_dark_theme = v:true
|
|
call CreateSignalFile('.transparent_dark_theme.signal')
|
|
else
|
|
let g:transparent_light_theme = v:true
|
|
call CreateSignalFile('.transparent_light_theme.signal')
|
|
endif
|
|
endif
|
|
endfunction
|
|
|
|
|
|
" vim theme
|
|
if g:vim_type == 'vim'
|
|
set t_Co=256
|
|
if HasPlug("papercolor-theme")
|
|
" improve coc color in this theme
|
|
let g:light_theme = 'PaperColor'
|
|
let g:dark_theme = 'PaperColor'
|
|
endif
|
|
if HasPlug("everforest")
|
|
if has('termguicolors')
|
|
set termguicolors
|
|
endif
|
|
let g:light_theme = 'everforest'
|
|
let g:dark_theme = 'everforest'
|
|
let g:airline_dark_theme = "everforest"
|
|
let g:airline_light_theme = "everforest"
|
|
let g:everforest_better_performance = 1
|
|
let g:everforest_background = 'hard'
|
|
" let g:everforest_enable_italic = 1
|
|
|
|
function! Everforest_trans_enable()
|
|
let g:everforest_transparent_background = 2
|
|
colorscheme everforest
|
|
if exists(':AirlineTheme')
|
|
execute('AirlineTheme everforest')
|
|
endif
|
|
" hack to fix caret characters appearing in the statusline when StatusLine
|
|
" and StatusLineNC has same highlight(https://vi.stackexchange.com/questions/15873/carets-in-status-line)
|
|
hi StatusLine guifg=#d3c6aa ctermfg=223
|
|
endfunction
|
|
function! Everforest_trans_disable()
|
|
let g:everforest_transparent_background = 0
|
|
colorscheme everforest
|
|
if exists(':AirlineTheme')
|
|
execute('AirlineTheme everforest')
|
|
endif
|
|
endfunction
|
|
let g:custom_transparent_function_enable = 'Everforest_trans_enable()'
|
|
let g:custom_transparent_function_disable = 'Everforest_trans_disable()'
|
|
endif
|
|
endif
|
|
|
|
" nvim only theme
|
|
if g:vim_type == 'nvim'
|
|
if g:vim_version >= 0.8 && HasPlug("nightfox.nvim")
|
|
let g:light_theme = 'dawnfox'
|
|
"let g:dark_theme = 'nightfox'
|
|
end
|
|
|
|
if g:vim_version >= 0.5 && HasPlug("github-nvim-theme")
|
|
let g:dark_theme = 'github_dark'
|
|
" let g:dark_theme = 'github_dark_default'
|
|
" let g:dark_theme = 'github_dimmed'
|
|
let g:airline_dark_theme = "hybrid"
|
|
end
|
|
endif
|
|
|
|
|
|
if g:dark_or_light_theme == 'dark'
|
|
let g:airline_theme=g:airline_dark_theme
|
|
call SetDarkTheme()
|
|
else
|
|
let g:airline_theme=g:airline_light_theme
|
|
call SetLightTheme()
|
|
endif
|
|
|
|
" Since in .vimrc we cannot call plugin function as they
|
|
" are not loaded (:help startup)
|
|
if (g:transparent_dark_theme && g:dark_or_light_theme == 'dark') || (g:transparent_light_theme && g:dark_or_light_theme == 'light')
|
|
if g:vim_type == 'nvim' && g:vim_version > 0.5
|
|
let g:transparent_enabled = v:true
|
|
else
|
|
call EnableTransparent()
|
|
endif
|
|
" call TransparentBackgroundFix()
|
|
else
|
|
if g:vim_type == 'nvim' && g:vim_version > 0.5
|
|
let g:transparent_enabled = v:false
|
|
else
|
|
call DisableTransparent()
|
|
endif
|
|
endif
|
|
|
|
" Allow to trigger background
|
|
function! ToggleBG()
|
|
" Inversion
|
|
if g:dark_or_light_theme == "dark"
|
|
call SetLightTheme()
|
|
call SetStatusLineTheme(g:airline_light_theme)
|
|
call CreateSignalFile('.light_theme.signal')
|
|
else
|
|
call SetDarkTheme()
|
|
call SetStatusLineTheme(g:airline_dark_theme)
|
|
" for saving theme state
|
|
call DeleteSignalFile('.light_theme.signal')
|
|
endif
|
|
|
|
if (g:transparent_dark_theme && g:dark_or_light_theme == 'dark') || (g:transparent_light_theme && g:dark_or_light_theme == 'light')
|
|
call EnableTransparent()
|
|
else
|
|
call DisableTransparent()
|
|
endif
|
|
endfunction
|
|
|
|
" }
|
|
|
|
" KEY_MAPS
|
|
" (This doesn't include plugin specific mapping.
|
|
" For them please check plugin Preferences)
|
|
" {
|
|
|
|
" Toggle dark/light theme
|
|
noremap <silent> <leader>bg :call ToggleBG()<CR>
|
|
|
|
" Toggle transparent background
|
|
noremap <silent> <leader>tb :call ToggleTransparent()<CR>
|
|
|
|
" Buffer navigation
|
|
nnoremap <silent> <space>q :bprevious<CR>
|
|
nnoremap <silent> <space>e :bnext<CR>
|
|
|
|
" leader s change all occurence
|
|
nnoremap <Leader>s :%s/\<<C-r><C-w>\>/<C-r><C-w>
|
|
|
|
" leader num change tab
|
|
" only for vim or nvim without lualine
|
|
if g:vim_type == 'vim' || (g:vim_type == 'nvim' && g:vim_version < 0.5)
|
|
for i in range(1, 9)
|
|
execute "nnoremap <silent> <nowait> <leader>" . i .
|
|
\ " :call bufferline#jump(" . i . ")<CR>"
|
|
endfor
|
|
for i in range(10, 20)
|
|
execute "nnoremap <silent> <nowait> <space>" . i .
|
|
\ " :call bufferline#jump(" . i . ")<CR>"
|
|
endfor
|
|
end
|
|
|
|
" split window comform with other window management shortcuts
|
|
nnoremap <silent> <C-w>% :vsplit<CR>
|
|
nnoremap <silent> <C-w>" :split<CR>
|
|
|
|
" }
|
|
"
|
|
" Lua configuration
|
|
if g:vim_type == 'nvim' && filereadable(g:mydotfiles_directory . '.vimrc.lua')
|
|
execute('source ' . g:mydotfiles_directory . '/.vimrc.lua')
|
|
endif
|
|
"
|
|
" OTHER_CONFIGS
|
|
" {
|
|
" show mapping info
|
|
" :verbose map ,cf
|
|
" }
|
|
|
|
if filereadable(g:mydotfiles_directory . "/config/theme.vim")
|
|
" exec "source " . g:mydotfiles_directory . "/config/theme.vim"
|
|
endif
|