1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00
jdhao-nvim-config/core/plugins.vim

570 lines
18 KiB
VimL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

scriptencoding utf-8
" Plugin installation
lua require 'plugins'
"{ Plugin settings
"{{ Vim-plug settings
" Use shortnames for common vim-plug command to reduce typing.
" To use these shortcut: first activate command line with `:`, then input the
" short alias, e.g., `pi`, then press <space>, the alias will be expanded
" to the full command automatically
call utils#Cabbrev('pi', 'PackerInstall')
call utils#Cabbrev('pud', 'PackerUpdate')
call utils#Cabbrev('pc', 'PackerClean')
call utils#Cabbrev('ps', 'PackerSync')
"}}
"{{ Auto-completion related
lua require('entrance')
"""""""""""""""""""""""""UltiSnips settings"""""""""""""""""""
" Trigger configuration. Do not use <tab> if you use YouCompleteMe
let g:UltiSnipsExpandTrigger='<c-j>'
" Do not look for SnipMate snippets
let g:UltiSnipsEnableSnipMate = 0
" Shortcut to jump forward and backward in tabstop positions
let g:UltiSnipsJumpForwardTrigger='<c-j>'
let g:UltiSnipsJumpBackwardTrigger='<c-k>'
" Configuration for custom snippets directory, see
" https://jdhao.github.io/2019/04/17/neovim_snippet_s1/ for details.
let g:UltiSnipsSnippetDirectories=['UltiSnips', 'my_snippets']
"}}
"{{ Language specific plugin
"""""""""""""""""""""""""" semshi settings """""""""""""""""""""""""""""""
" Do not highlight for all occurances of variable under cursor
let g:semshi#mark_selected_nodes=0
" Do not show error sign since linting plugin is specicialized for that
let g:semshi#error_sign=v:false
"""""""""""""""""""""""""" vlime settings """"""""""""""""""""""""""""""""
command! -nargs=0 StartVlime call jobstart(printf("sbcl --load %s/vlime/lisp/start-vlime.lisp", g:plug_home))
"}}
"{{ Search related
"""""""""""""""""""""""""""""vim-sneak settings"""""""""""""""""""""""
" Use sneak label mode
let g:sneak#label = 1
nmap f <Plug>Sneak_s
xmap f <Plug>Sneak_s
onoremap <silent> f :call sneak#wrap(v:operator, 2, 0, 1, 1)<CR>
nmap F <Plug>Sneak_S
xmap F <Plug>Sneak_S
onoremap <silent> F :call sneak#wrap(v:operator, 2, 1, 1, 1)<CR>
" Immediately after entering sneak mode, you can press f and F to go to next
" or previous match
let g:sneak#s_next = 1
"""""""""""""""""""""""""""""vim-anzu settings"""""""""""""""""""""""
nmap n <Plug>(anzu-n-with-echo)zzzv
nmap N <Plug>(anzu-N-with-echo)zzzv
" Maximum number of words to search
let g:anzu_search_limit = 500000
" Message to show for search pattern
let g:anzu_status_format = '/%p [%i/%l]'
"""""""""""""""""""""""""""""vim-asterisk settings"""""""""""""""""""""
nmap * <Plug>(asterisk-z*)
nmap # <Plug>(asterisk-z#)
xmap * <Plug>(asterisk-z*)
xmap # <Plug>(asterisk-z#)
"""""""""""""""""""""""""""""LeaderF settings"""""""""""""""""""""
" Do not use cache file
let g:Lf_UseCache = 0
" Refresh each time we call leaderf
let g:Lf_UseMemoryCache = 0
" Ignore certain files and directories when searching files
let g:Lf_WildIgnore = {
\ 'dir': ['.git', '__pycache__', '.DS_Store'],
\ 'file': ['*.exe', '*.dll', '*.so', '*.o', '*.pyc', '*.jpg', '*.png',
\ '*.gif', '*.svg', '*.ico', '*.db', '*.tgz', '*.tar.gz', '*.gz',
\ '*.zip', '*.bin', '*.pptx', '*.xlsx', '*.docx', '*.pdf', '*.tmp',
\ '*.wmv', '*.mkv', '*.mp4', '*.rmvb', '*.ttf', '*.ttc', '*.otf',
\ '*.mp3', '*.aac']
\}
" Do not show fancy icons for Linux server.
if g:is_linux
let g:Lf_ShowDevIcons = 0
endif
" Only fuzzy-search files names
let g:Lf_DefaultMode = 'NameOnly'
" Popup window settings
let g:Lf_PopupWidth = 0.5
let g:Lf_PopupPosition = [0, &columns/4]
" Do not use version control tool to list files under a directory since
" submodules are not searched by default.
let g:Lf_UseVersionControlTool = 0
" Disable default mapping
let g:Lf_ShortcutF = ''
let g:Lf_ShortcutB = ''
" set up working directory for git repository
let g:Lf_WorkingDirectoryMode = 'a'
" Search files in popup window
nnoremap <silent> <leader>f :<C-U>Leaderf file --popup<CR>
" Search vim help files
nnoremap <silent> <leader>h :<C-U>Leaderf help --popup<CR>
" Search tags in current buffer
nnoremap <silent> <leader>t :<C-U>Leaderf bufTag --popup<CR>
"}}
"{{ URL related
""""""""""""""""""""""""""""open-browser.vim settings"""""""""""""""""""
if g:is_win || g:is_mac
" Disable netrw's gx mapping.
let g:netrw_nogx = 1
" Use another mapping for the open URL method
nmap ob <Plug>(openbrowser-smart-search)
xmap ob <Plug>(openbrowser-smart-search)
endif
"}}
"{{ Navigation and tags
""""""""""""""""""""""""""" gutentags settings """"""""""""""""""""""""""""""
" The path to store tags files, instead of in the project root.
let g:gutentags_cache_dir = stdpath('cache') . '/ctags'
let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extra=+q']
let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
let g:gutentags_ctags_extra_args += ['--c-kinds=+px']
let g:gutentags_ctags_exclude = ['*.md', '*.html', '*.json', '*.toml', '*.css', '*.js',]
""""""""""""""""""""""""""" vista settings """"""""""""""""""""""""""""""""""
let g:vista#renderer#icons = {
\ 'member': '',
\ }
" Do not echo message on command line
let g:vista_echo_cursor = 0
" Stay in current window when vista window is opened
let g:vista_stay_on_open = 0
augroup vista_conf
autocmd!
" Double mouse click to go to a tag
autocmd FileType vista* nnoremap <buffer> <silent>
\ <2-LeftMouse> :<C-U>call vista#cursor#FoldOrJump()<CR>
augroup END
nnoremap <silent> <Space>t :<C-U>Vista!!<CR>
"}}
"{{ File editting
""""""""""""""""""""""""""""vim-titlecase settings"""""""""""""""""""""""
" Do not use the default mapping provided
let g:titlecase_map_keys = 0
nmap <leader>gt <Plug>Titlecase
xmap <leader>gt <Plug>Titlecase
nmap <leader>gT <Plug>TitlecaseLine
""""""""""""""""""""""""vim-auto-save settings"""""""""""""""""""""""
" Enable autosave on nvim startup
let g:auto_save = 1
" A list of events to trigger autosave
let g:auto_save_events = ['InsertLeave', 'TextChanged']
" Whether to show autosave status on command line
let g:auto_save_silent = 0
""""""""""""""""""""""""vim-mundo settings"""""""""""""""""""""""
let g:mundo_verbose_graph = 0
let g:mundo_width = 80
nnoremap <silent> <Space>u :MundoToggle<CR>
""""""""""""""""""""""""""""vim-yoink settings"""""""""""""""""""""""""
if g:is_win || g:is_mac
" ctrl-n and ctrl-p will not work if you add the TextChanged event to vim-auto-save events.
" nmap <c-n> <plug>(YoinkPostPasteSwapBack)
" nmap <c-p> <plug>(YoinkPostPasteSwapForward)
" The following p/P mappings are also needed for ctrl-n and ctrl-p to work
" nmap p <plug>(YoinkPaste_p)
" nmap P <plug>(YoinkPaste_P)
" Cycle the yank stack with the following mappings
nmap [y <plug>(YoinkRotateBack)
nmap ]y <plug>(YoinkRotateForward)
" Do not change the cursor position
nmap y <plug>(YoinkYankPreserveCursorPosition)
xmap y <plug>(YoinkYankPreserveCursorPosition)
" Move cursor to end of paste after multiline paste
let g:yoinkMoveCursorToEndOfPaste = 0
" Record yanks in system clipboard
let g:yoinkSyncSystemClipboardOnFocus = 1
endif
""""""""""""""""""""""""""""nvim-minipyank settings"""""""""""""""""""""""""
nmap p <Plug>(miniyank-autoput)
nmap P <Plug>(miniyank-autoPut)
""""""""""""""""""""""""""""better-escape.vim settings"""""""""""""""""""""""""
let g:better_escape_interval = 200
""""""""""""""""""""""""""""vim-xkbswitch settings"""""""""""""""""""""""""
let g:XkbSwitchEnabled = 1
"}}
"{{ Linting and formating
"""""""""""""""""""""""""""""" ale settings """""""""""""""""""""""
" linters for different filetypes
let g:ale_linters = {
\ 'vim': ['vint'],
\ 'cpp': ['cppcheck'],
\ }
" Only run linters in the g:ale_linters dictionary
let g:ale_linters_explicit = 1
" Linter signs
let g:ale_sign_error = 'x'
let g:ale_sign_warning = '!'
"""""""""""""""""""""""""""""" neoformat settings """""""""""""""""""""""
let g:neoformat_enabled_python = ['black', 'yapf']
let g:neoformat_cpp_clangformat = {
\ 'exe': 'clang-format',
\ 'args': ['--style="{IndentWidth: 4}"']
\ }
let g:neoformat_c_clangformat = {
\ 'exe': 'clang-format',
\ 'args': ['--style="{IndentWidth: 4}"']
\ }
let g:neoformat_enabled_cpp = ['clangformat']
let g:neoformat_enabled_c = ['clangformat']
"}}
"{{ Git-related
"""""""""""""""""""""""""vim-signify settings""""""""""""""""""""""""""""""
" The VCS to use
let g:signify_vcs_list = [ 'git' ]
" Change the sign for certain operations
let g:signify_sign_change = '~'
"""""""""""""""""""""""""vim-fugitive settings""""""""""""""""""""""""""""""
nnoremap <silent> <leader>gc :Git commit<CR>
nnoremap <silent> <leader>gs :Git<CR>
nnoremap <silent> <leader>gw :Gwrite<CR>
nnoremap <silent> <leader>gpl :Git pull<CR>
" Note that to use bar literally, we need backslash it, see also `:h :bar`.
nnoremap <silent> <leader>gpu :15split \| term git push
"}}
"{{ Markdown writing
"""""""""""""""""""""""""plasticboy/vim-markdown settings"""""""""""""""""""
" Disable header folding
let g:vim_markdown_folding_disabled = 1
" Whether to use conceal feature in markdown
let g:vim_markdown_conceal = 1
" Disable math tex conceal and syntax highlight
let g:tex_conceal = ''
let g:vim_markdown_math = 0
" Support front matter of various format
let g:vim_markdown_frontmatter = 1 " for YAML format
let g:vim_markdown_toml_frontmatter = 1 " for TOML format
let g:vim_markdown_json_frontmatter = 1 " for JSON format
" Let the TOC window autofit so that it doesn't take too much space
let g:vim_markdown_toc_autofit = 1
"""""""""""""""""""""""""markdown-preview settings"""""""""""""""""""
" Only setting this for suitable platforms
if g:is_win || g:is_mac
" Do not close the preview tab when switching to other buffers
let g:mkdp_auto_close = 0
" Shortcuts to start and stop markdown previewing
nnoremap <silent> <M-m> :<C-U>MarkdownPreview<CR>
nnoremap <silent> <M-S-m> :<C-U>MarkdownPreviewStop<CR>
endif
""""""""""""""""""""""""vim-grammarous settings""""""""""""""""""""""""""""""
if g:is_mac
let g:grammarous#languagetool_cmd = 'languagetool'
let g:grammarous#disabled_rules = {
\ '*' : ['WHITESPACE_RULE', 'EN_QUOTES', 'ARROWS', 'SENTENCE_WHITESPACE',
\ 'WORD_CONTAINS_UNDERSCORE', 'COMMA_PARENTHESIS_WHITESPACE',
\ 'EN_UNPAIRED_BRACKETS', 'UPPERCASE_SENTENCE_START',
\ 'ENGLISH_WORD_REPEAT_BEGINNING_RULE', 'DASH_RULE', 'PLUS_MINUS',
\ 'PUNCTUATION_PARAGRAPH_END', 'MULTIPLICATION_SIGN', 'PRP_CHECKOUT',
\ 'CAN_CHECKOUT', 'SOME_OF_THE', 'DOUBLE_PUNCTUATION', 'HELL',
\ 'CURRENCY', 'POSSESSIVE_APOSTROPHE', 'ENGLISH_WORD_REPEAT_RULE',
\ 'NON_STANDARD_WORD', 'AU', 'DATE_NEW_YEAR'],
\ }
augroup grammarous_map
autocmd!
autocmd FileType markdown nmap <buffer> <leader>x <Plug>(grammarous-close-info-window)
autocmd FileType markdown nmap <buffer> <c-n> <Plug>(grammarous-move-to-next-error)
autocmd FileType markdown nmap <buffer> <c-p> <Plug>(grammarous-move-to-previous-error)
augroup END
endif
""""""""""""""""""""""""unicode.vim settings""""""""""""""""""""""""""""""
nmap ga <Plug>(UnicodeGA)
"}}
"{{ text objects
""""""""""""""""""""""""""""vim-sandwich settings"""""""""""""""""""""""""""""
" Map s to nop since s in used by vim-sandwich. Use cl instead of s.
nmap s <Nop>
omap s <Nop>
"}}
"{{ LaTeX editting
""""""""""""""""""""""""""""vimtex settings"""""""""""""""""""""""""""""
if ( g:is_win || g:is_mac ) && executable('latex')
function! SetServerName() abort
if has('win32')
let nvim_server_file = $TEMP . '/curnvimserver.txt'
else
let nvim_server_file = '/tmp/curnvimserver.txt'
endif
let cmd = printf('echo %s > %s', v:servername, nvim_server_file)
call system(cmd)
endfunction
augroup vimtex_common
autocmd!
autocmd FileType tex nmap <buffer> <F9> <plug>(vimtex-compile)
autocmd FileType tex call SetServerName()
augroup END
let g:vimtex_compiler_latexmk = {
\ 'build_dir' : 'build',
\ }
" TOC settings
let g:vimtex_toc_config = {
\ 'name' : 'TOC',
\ 'layers' : ['content', 'todo', 'include'],
\ 'resize' : 1,
\ 'split_width' : 30,
\ 'todo_sorted' : 0,
\ 'show_help' : 1,
\ 'show_numbers' : 1,
\ 'mode' : 2,
\ }
" Viewer settings for different platforms
if g:is_win
let g:vimtex_view_general_viewer = 'SumatraPDF'
let g:vimtex_view_general_options_latexmk = '-reuse-instance'
let g:vimtex_view_general_options = '-reuse-instance -forward-search @tex @line @pdf'
endif
if g:is_mac
" let g:vimtex_view_method = "skim"
let g:vimtex_view_general_viewer = '/Applications/Skim.app/Contents/SharedSupport/displayline'
let g:vimtex_view_general_options = '-r @line @pdf @tex'
augroup vimtex_mac
autocmd!
autocmd User VimtexEventCompileSuccess call UpdateSkim()
augroup END
" The following code is adapted from https://gist.github.com/skulumani/7ea00478c63193a832a6d3f2e661a536.
function! UpdateSkim() abort
let l:out = b:vimtex.out()
let l:src_file_path = expand('%:p')
let l:cmd = [g:vimtex_view_general_viewer, '-r']
if !empty(system('pgrep Skim'))
call extend(l:cmd, ['-g'])
endif
call jobstart(l:cmd + [line('.'), l:out, l:src_file_path])
endfunction
endif
endif
"}}
"{{ UI: Status line, look
"""""""""""""""""""""""""""vim-airline setting""""""""""""""""""""""""""""""
" Set airline theme to a random one if it exists
let s:candidate_airlinetheme = ['ayu_mirage', 'lucius', 'ayu_dark', 'base16_bright',
\ 'base16_adwaita', 'jellybeans', 'luna', 'raven', 'term', 'base16_summerfruit']
let s:idx = utils#RandInt(0, len(s:candidate_airlinetheme)-1)
let s:theme = s:candidate_airlinetheme[s:idx]
if utils#HasAirlinetheme(s:theme)
let g:airline_theme=s:theme
endif
" Tabline settings
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#fnamemod = ':t'
let g:airline#extensions#tabline#formatter = 'unique_tail_improved'
" Show buffer number for easier switching between buffer,
" see https://github.com/vim-airline/vim-airline/issues/1149
let g:airline#extensions#tabline#buffer_nr_show = 1
" Buffer number display format
let g:airline#extensions#tabline#buffer_nr_format = '%s. '
" Whether to show function or other tags on status line
let g:airline#extensions#vista#enabled = 1
let g:airline#extensions#gutentags#enabled = 1
" Do not show search index in statusline since it is shown on command line
let g:airline#extensions#anzu#enabled = 0
" Enable vim-airline extension for nvim-lsp
let g:airline#extensions#nvimlsp#enabled = 1
" Skip empty sections if there are nothing to show,
" extracted from https://vi.stackexchange.com/a/9637/15292
let g:airline_skip_empty_sections = 1
" Whether to use powerline symbols, see https://vi.stackexchange.com/q/3359/15292
let g:airline_powerline_fonts = 0
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_symbols.branch = '⎇'
let g:airline_symbols.paste = 'ρ'
let g:airline_symbols.spell = 'Ꞩ'
" Only show git hunks which are non-zero
let g:airline#extensions#hunks#non_zero_only = 1
" Speed up airline
let g:airline_highlighting_cache = 1
" The key in the following shortcode are the layout when we use a specific
" input method mode. On my macOS, 0 means that we are trying to input Chinese,
" and 1 means we are using English mode.
" See also https://github.com/vim-airline/vim-airline/blob/master/autoload/airline/extensions/xkblayout.vim#L11
let g:airline#extensions#xkblayout#short_codes = {'0': 'CN', '1': 'US'}
" Disable scrollbar
let g:airline#extensions#scrollbar#enabled = 0
""""""""""""""""""""""""""""vim-startify settings""""""""""""""""""""""""""""
" Do not change working directory when opening files.
let g:startify_change_to_dir = 0
let g:startify_fortune_use_unicode = 1
""""""""""""""""""""""""""""indent-blankline settings""""""""""""""""""""""""""""
let g:indent_blankline_char = '│'
" let g:indent_blankline_char = '┆'
" let g:indent_blankline_char = '┊'
let g:indent_blankline_filetype_exclude = ['help', 'startify', 'git', 'markdown']
"}}
"{{ Misc plugin setting
""""""""""""""""""""""""""""vim-matchup settings"""""""""""""""""""""""""""""
" Improve performance
let g:matchup_matchparen_deferred = 1
let g:matchup_matchparen_timeout = 100
let g:matchup_matchparen_insert_timeout = 30
" Enhanced matching with matchup plugin
let g:matchup_override_vimtex = 1
" Whether to enable matching inside comment or string
let g:matchup_delim_noskips = 0
" Show offscreen match pair in popup window
let g:matchup_matchparen_offscreen = {'method': 'popup'}
" Change highlight color of matching bracket for better visual effects
augroup matchup_matchparen_highlight
autocmd!
autocmd ColorScheme * highlight MatchParen cterm=underline gui=underline
augroup END
" Show matching keyword as underlined text to reduce color clutter
augroup matchup_matchword_highlight
autocmd!
autocmd ColorScheme * hi MatchWord cterm=underline gui=underline
augroup END
"""""""""""""""""""""""""" asyncrun.vim settings """"""""""""""""""""""""""
" Automatically open quickfix window of 6 line tall after asyncrun starts
let g:asyncrun_open = 6
if g:is_win
" Command output encoding for Windows
let g:asyncrun_encs = 'gbk'
endif
""""""""""""""""""""""""""""""firenvim settings""""""""""""""""""""""""""""""
if exists('g:started_by_firenvim') && g:started_by_firenvim
if g:is_mac
set guifont=Iosevka\ Nerd\ Font:h18
endif
" general options
set laststatus=0 nonumber noruler noshowcmd
" general config for firenvim
let g:firenvim_config = {
\ 'globalSettings': {
\ 'alt': 'all',
\ },
\ 'localSettings': {
\ '.*': {
\ 'cmdline': 'neovim',
\ 'priority': 0,
\ 'selector': 'textarea',
\ 'takeover': 'never',
\ },
\ }
\ }
augroup firenvim
autocmd!
autocmd BufEnter *.txt setlocal filetype=markdown
augroup END
endif
""""""""""""""""""""""""""""""nvim-gdb settings""""""""""""""""""""""""""""""
nnoremap <leader>dp :<C-U>GdbStartPDB python -m pdb %<CR>
""""""""""""""""""""""""""""""iron.nvim settings""""""""""""""""""""""""""""""
lua << EOF
local iron = require('iron')
iron.core.set_config{
preferred = {
python = 'ipython'
},
repl_open_cmd = 'vertical 120 split'
}
EOF
""""""""""""""""""""""""""""""register.nvim settings""""""""""""""""""""""""""""""
let g:registers_show_empty_registers = 0
let g:registers_window_border = 'single'
"}}
"}