Advertisement
Guest User

Untitled

a guest
Jan 1st, 2023
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 14.07 KB | None | 0 0
  1. " Allows vim to use a local .vimrc, if found, over the global one
  2.     set exrc
  3.     set secure " can't execute any code, for security
  4.  
  5. " Python
  6.     "let g:python_host_prog  = '/usr/bin/python2'
  7.     "let g:python3_host_prog = '/usr/bin/python3'
  8.  
  9. " Mouse mode: For those very few scenarios, also good for scrolling
  10.     set mouse=a
  11.  
  12. " Remap leader key to space
  13.     let g:mapleader = "\<Space>"
  14.      
  15. " Vim set
  16.     " set number
  17.     set relativenumber
  18.     set foldmethod=syntax
  19.     set nofoldenable
  20.  
  21.     set statusline+=%F
  22.  
  23.     set tabstop=4
  24.     set shiftwidth=4
  25.     set expandtab
  26.     set autoindent
  27.     filetype plugin indent on
  28.  
  29. " Make pwd the directory the current file is in
  30.     map <F8> :cd %:p:h<cr>
  31.  
  32. " New keybind to save quicker (saves having to hit the <CR>)
  33.     nmap <s-w> :up<cr>
  34.     " autocmd CursorHold * update " this will autosave the file now
  35.  
  36. " For navigating between tabs more easily (keybinds versus commands)
  37.     map <C-t><left> :tabp<cr>
  38.     map <C-t><right> :tabn<cr>
  39.     map <C-t><up> :tabr<cr>
  40.     map <C-t><down> :tabl<cr>
  41.      
  42. " Search
  43.     set incsearch
  44.     set nohlsearch " disables by default
  45.     " Pressing ESC twice turns off the highlights for the given search
  46.     nnoremap <esc><esc> :silent! nohls<cr>
  47.     ":noremap <F6> :set hlsearch<cr>
  48.     set inccommand=nosplit
  49.  
  50. " Autocomplete for English
  51.     set spelllang=en
  52.     set complete+=k
  53.     noremap <F5> :setlocal spell! spelllang=en_us<cr>
  54.     " Toggle Spellcheck
  55.     " set dictionary+=/usr/share/dict/words
  56.    
  57. " Completion Related
  58.  
  59.     " set completeopt=longest,menuone
  60.      
  61.      
  62. " Theme and syntax highlighting
  63.     syntax on
  64.     set t_Co=256
  65.     highlight Normal ctermfg=grey ctermbg=black
  66.     set termguicolors
  67.    
  68. " Allows me to go up and down on lines I see visually, not just actual lines
  69.     "nnoremap j gj
  70.     "nnoremap gj j
  71.     nnoremap <expr> j v:count ? (v:count > 5 ? "m'" . v:count : '') . 'j' : 'gj'
  72.     nnoremap <expr> k v:count ? (v:count > 5 ? "m'" . v:count : '') . 'k' : 'gk'
  73.      
  74.  
  75. "Line wrap
  76.     command! -nargs=* Wrap set wrap linebreak nolist
  77.  
  78.  
  79. " Specify a directory for plugins
  80. " - For Neovim: stdpath('data') . '/plugged'
  81. " - Avoid using standard Vim directory names like 'plugin'
  82. call plug#begin(stdpath('data') . '/plugged')
  83.  
  84.      " Essentials
  85.        Plug 'tpope/vim-sensible' " sensible vim defaults
  86.        Plug 'jdhao/better-escape.vim'
  87.            let g:better_escape_shortcut = ['jj', 'jk', 'kj']
  88.             " set time interval to 200 ms
  89.             let g:better_escape_interval = 120
  90.        " Plug 'tpope/vim-obsession'
  91.        Plug 'tpope/vim-fugitive' " good for git
  92.        Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } " fzf for vim
  93.             Plug 'junegunn/fzf.vim'
  94.        Plug 'tpope/vim-sleuth' " auto adjusts shiftwidth and expandtab based on file
  95.        Plug 'tpope/vim-commentary'
  96.        Plug 'justinmk/vim-sneak'
  97.             let g:sneak#label = 1 " makes vim-sneak like easymotion
  98.        Plug 'junegunn/vim-easy-align'
  99.             " Start interactive EasyAlign in visual mode (e.g. vipga)
  100.             xmap ga <Plug>(EasyAlign)
  101.  
  102.            " Start interactive EasyAlign for a motion/text object (e.g. gaip)
  103.            nmap ga <Plug>(EasyAlign)
  104.         Plug 'mbbill/undotree'
  105.         nnoremap <F9> :UndotreeToggle<CR>
  106.  
  107.  
  108.     " File Managers
  109.         Plug 'justinmk/vim-dirvish'
  110.             let g:dirvish_mode = ':sort ,^\v(.*[\/])|\ze,' " sorts folders at the top
  111.         "Plug 'francoiscabrol/ranger.vim' " integrates with ranger
  112.  
  113.     " Text Snippets
  114.         Plug 'SirVer/ultisnips'
  115.             let g:UltiSnipsSnippetsDir = $HOME"/.config/nvim/UltiSnips"
  116.             let g:UltiSnipsSnippetDirectories = ['UltiSnips']
  117.             "let g:UltiSnipsSnippetDirectories = ['UltiSnips', $HOME.'/.vim/UltiSnips']
  118.             let g:UltiSnipsExpandTrigger = '<tab>'
  119.             let g:UltiSnipsJumpForwardTrigger = '<tab>'
  120.             let g:UltiSnipsJumpBackwardTrigger = '<S-tab>'
  121.             let g:UltiSnipsEditSplit = 'tabdo'
  122.    
  123.     " Notetaking and Prose related plugins
  124.        Plug 'vim-pandoc/vim-pandoc'
  125.            let g:pandoc#spell#enabled = 0
  126.        Plug 'lervag/wiki.vim'
  127.           let g:wiki_filetypes = ['md', 'markdown', "lhs"]
  128.           let g:wiki_link_target_type = 'md'
  129.           let g:wiki_root = "~/Sync/Notes/"
  130.        " Plug 'lervag/lists.vim'
  131.           let g:lists_filetypes = ['pandoc', 'markdown', 'md']
  132.           nnoremap <C-h> :ListsToggle<CR>
  133.        " Plug 'lewis6991/spellsitter.nvim'
  134.        " Plug 'edluffy/hologram.nvim'
  135.  
  136.        
  137.     " Data
  138.         Plug 'chrisbra/csv.vim'
  139.  
  140.     " IDE & Syntax
  141.        " Plug 'vim-pandoc/vim-pandoc-syntax'
  142.        "     let g:pandoc#syntax#codeblocks#embeds#langs = [
  143.        "                 \"ruby",
  144.        "                 \"literatehaskell=lhaskell",
  145.        "                 \"mathematica=mathematica",
  146.        "                 \"bash=sh",
  147.        "                 \"python=python",
  148.        "                 \"cpp=c++",
  149.        "                 \"haskell=haskell",
  150.        "                 \"sml=sml",
  151.        "                 \"{.graphviz}=dot",
  152.        "                 \"verilog=verilog"]
  153.        "     let g:pandoc#spell#enabled = 0 " disables spell check
  154.  
  155.         Plug 'sheerun/vim-polyglot' " language packs for vim
  156.             " let g:polyglot_disabled = ['markdown']
  157.        Plug 'itchyny/vim-haskell-indent'
  158.        Plug 'tmhedberg/SimpylFold' " allows for proper folding of python code based on syntax
  159.        " Plug 'neoclide/coc.nvim', {'branch': 'master', 'do': 'yarn install --frozen-lockfile'}
  160.        " Plug 'neoclide/coc.nvim', {'branch': 'master', 'commit': '2ad659d8b1a3d7bef7dca7d33c6ab9363a729100', 'do': 'yarn install --frozen-lockfile'}
  161.        Plug 'neoclide/coc.nvim', {'branch': 'release'}
  162.        "Plug 'sakhnik/nvim-gdb', { 'do': ':!./install.sh' }
  163.        "Plug 'puremourning/vimspector'
  164.  
  165.     " Aesthetics & User Experience
  166.        Plug 'flazz/vim-colorschemes'
  167.        Plug 'arcticicestudio/nord-vim'
  168.        " Plug 'EdenEast/nightfox.nvim'
  169.        Plug 'folke/tokyonight.nvim', { 'branch': 'main' }
  170.        " Plug 'dracula/vim', { 'as': 'dracula' }
  171.        Plug 'itchyny/lightline.vim'
  172.        " Plug 'kevinhwang91/nvim-ufo'
  173.  
  174. call plug#end() " Initialize plugin system
  175.  
  176.  
  177. "autocmd BufNewFile,BufFilePre,BufRead *.md set filetype=markdown.pandoc
  178.  
  179. augroup highlight_yank "highlight yanked text
  180. autocmd!
  181. au TextYankPost * silent! lua vim.highlight.on_yank({higroup="Visual", timeout=200})
  182. augroup END
  183.  
  184. " FZF commands
  185.     nnoremap <silent> <leader>; :BLines<CR>
  186.     nnoremap <silent> <leader>F :History<CR>
  187.     nnoremap <silent> <leader>/ :Rg<CR>
  188.     nnoremap <silent> <leader>f :Files<CR>
  189.     nnoremap <silent> <leader><leader> :Buffers<CR>
  190.     " nnoremap <silent> <leader>f :ProjectFiles<CR>
  191.     "nnoremap <silent> <leader>w :Windows<CR>
  192.     "nnoremap <silent> <leader>o :BTags<CR>
  193.     "nnoremap <silent> <leader>O :Tags<CR>
  194.     "nnoremap <silent> <leader>/ :execute 'Rg ' . input('Rg/')<CR>
  195.     "nnoremap <silent> <leader>. :AgIn
  196.     "nnoremap <silent> <leader>d :Files<CR>
  197.    
  198. " Enable italics
  199.     highlight Comment cterm=italic
  200.     " set t_ZH=^[[3m
  201.     " set t_ZR=^[[23m
  202.    
  203. " Initialize colorscheme
  204.     set background=dark
  205.     colorscheme tokyonight
  206.     "colorscheme dracula
  207.     highlight Normal ctermbg=NONE
  208.     let g:lightline = {
  209.             \ 'colorscheme': 'tokyonight'
  210.           \ }
  211.     set noshowmode " nvim no longer shows the mode we're in; that's shown by lightline
  212.     " let g:nord_cursor_line_number_background = 1
  213.     " let g:nord_italic = 1
  214.     " let g:nord_italic_comments = 1
  215.     " let g:nord_underline = 1
  216.  
  217.     "colorscheme 256_noir
  218.     " hi! clear Conceal
  219.     set t_ZH=
  220.     set t_ZR=
  221.     " set t_Co=256
  222.     " set termguicolors
  223.  
  224. " Coc.nvim config. Super long!
  225.  
  226. " May need for Vim (not Neovim) since coc.nvim calculates byte offset by count
  227. " utf-8 byte sequence
  228. set encoding=utf-8
  229. " Some servers have issues with backup files, see #649
  230. set nobackup
  231. set nowritebackup
  232.  
  233. " Having longer updatetime (default is 4000 ms = 4s) leads to noticeable
  234. " delays and poor user experience
  235. set updatetime=300
  236.  
  237. " Always show the signcolumn, otherwise it would shift the text each time
  238. " diagnostics appear/become resolved
  239. set signcolumn=yes
  240.  
  241. " Use tab for trigger completion with characters ahead and navigate
  242. " NOTE: There's always complete item selected by default, you may want to enable
  243. " no select by `"suggest.noselect": true` in your configuration file
  244. " NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
  245. " other plugin before putting this into your config
  246. " inoremap <silent><expr> <TAB>
  247. "       \ coc#pum#visible() ? coc#pum#next(1) :
  248. "       \ CheckBackspace() ? "\<Tab>" :
  249. "       \ coc#refresh()
  250. " inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
  251.  
  252. " Make <CR> to accept selected completion item or notify coc.nvim to format
  253. " <C-g>u breaks current undo, please make your own choice
  254. " inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
  255. "                               \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
  256.  
  257. function! CheckBackspace() abort
  258.   let col = col('.') - 1
  259.   return !col || getline('.')[col - 1]  =~# '\s'
  260. endfunction
  261.  
  262. " Use <c-space> to trigger completion
  263. if has('nvim')
  264.   inoremap <silent><expr> <c-space> coc#refresh()
  265. else
  266.   inoremap <silent><expr> <c-@> coc#refresh()
  267. endif
  268.  
  269. " Use `[g` and `]g` to navigate diagnostics
  270. " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list
  271. nmap <silent> [g <Plug>(coc-diagnostic-prev)
  272. nmap <silent> ]g <Plug>(coc-diagnostic-next)
  273.  
  274. " GoTo code navigation
  275. nmap <silent> gd <Plug>(coc-definition)
  276. nmap <silent> gy <Plug>(coc-type-definition)
  277. nmap <silent> gi <Plug>(coc-implementation)
  278. nmap <silent> gr <Plug>(coc-references)
  279.  
  280. " Use K to show documentation in preview window
  281. nnoremap <silent> K :call ShowDocumentation()<CR>
  282.  
  283. function! ShowDocumentation()
  284.   if CocAction('hasProvider', 'hover')
  285.     call CocActionAsync('doHover')
  286.   else
  287.     call feedkeys('K', 'in')
  288.   endif
  289. endfunction
  290.  
  291. " Highlight the symbol and its references when holding the cursor
  292. autocmd CursorHold * silent call CocActionAsync('highlight')
  293.  
  294. " Symbol renaming
  295. nmap <leader>rn <Plug>(coc-rename)
  296.  
  297. " Formatting selected code
  298. " xmap <leader>f  <Plug>(coc-format-selected)
  299. " nmap <leader>f  <Plug>(coc-format-selected)
  300.  
  301. augroup mygroup
  302.   autocmd!
  303.   " Setup formatexpr specified filetype(s)
  304.   autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  305.   " Update signature help on jump placeholder
  306.   autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
  307. augroup end
  308.  
  309. " Applying code actions to the selected code block
  310. " Example: `<leader>aap` for current paragraph
  311. xmap <leader>a  <Plug>(coc-codeaction-selected)
  312. nmap <leader>a  <Plug>(coc-codeaction-selected)
  313.  
  314. " Remap keys for applying code actions at the cursor position
  315. nmap <leader>ac  <Plug>(coc-codeaction-cursor)
  316. " Remap keys for apply code actions affect whole buffer
  317. nmap <leader>as  <Plug>(coc-codeaction-source)
  318. " Apply the most preferred quickfix action to fix diagnostic on the current line
  319. nmap <leader>qf  <Plug>(coc-fix-current)
  320.  
  321. " Remap keys for applying refactor code actions
  322. nmap <silent> <leader>re <Plug>(coc-codeaction-refactor)
  323. xmap <silent> <leader>r  <Plug>(coc-codeaction-refactor-selected)
  324. nmap <silent> <leader>r  <Plug>(coc-codeaction-refactor-selected)
  325.  
  326. " Run the Code Lens action on the current line
  327. nmap <leader>cl  <Plug>(coc-codelens-action)
  328.  
  329. " Map function and class text objects
  330. " NOTE: Requires 'textDocument.documentSymbol' support from the language server
  331. xmap if <Plug>(coc-funcobj-i)
  332. omap if <Plug>(coc-funcobj-i)
  333. xmap af <Plug>(coc-funcobj-a)
  334. omap af <Plug>(coc-funcobj-a)
  335. xmap ic <Plug>(coc-classobj-i)
  336. omap ic <Plug>(coc-classobj-i)
  337. xmap ac <Plug>(coc-classobj-a)
  338. omap ac <Plug>(coc-classobj-a)
  339.  
  340. " Remap <C-f> and <C-b> to scroll float windows/popups
  341. if has('nvim-0.4.0') || has('patch-8.2.0750')
  342.   nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  343.   nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
  344.   inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
  345.   inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
  346.   vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  347.   vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
  348. endif
  349.  
  350. " Use CTRL-S for selections ranges
  351. " Requires 'textDocument/selectionRange' support of language server
  352. nmap <silent> <C-s> <Plug>(coc-range-select)
  353. xmap <silent> <C-s> <Plug>(coc-range-select)
  354.  
  355. " Add `:Format` command to format current buffer
  356. command! -nargs=0 Format :call CocActionAsync('format')
  357.  
  358. " Add `:Fold` command to fold current buffer
  359. command! -nargs=? Fold :call     CocAction('fold', <f-args>)
  360.  
  361. " Add `:OR` command for organize imports of the current buffer
  362. command! -nargs=0 OR   :call     CocActionAsync('runCommand', 'editor.action.organizeImport')
  363.  
  364. " Add (Neo)Vim's native statusline support
  365. " NOTE: Please see `:h coc-status` for integrations with external plugins that
  366. " provide custom statusline: lightline.vim, vim-airline
  367. set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
  368.  
  369. " Mappings for CoCList
  370. " Show all diagnostics
  371. nnoremap <silent><nowait> <space>a  :<C-u>CocList diagnostics<cr>
  372. " Manage extensions
  373. nnoremap <silent><nowait> <space>e  :<C-u>CocList extensions<cr>
  374. " Show commands
  375. nnoremap <silent><nowait> <space>c  :<C-u>CocList commands<cr>
  376. " Find symbol of current document
  377. nnoremap <silent><nowait> <space>o  :<C-u>CocList outline<cr>
  378. " Search workspace symbols
  379. nnoremap <silent><nowait> <space>s  :<C-u>CocList -I symbols<cr>
  380. " Do default action for next item
  381. nnoremap <silent><nowait> <space>j  :<C-u>CocNext<CR>
  382. " Do default action for previous item
  383. nnoremap <silent><nowait> <space>k  :<C-u>CocPrev<CR>
  384. " Resume latest coc list
  385. nnoremap <silent><nowait> <space>p  :<C-u>CocListResume<CR>
  386.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement