Advertisement
MorganF

init.nvim

May 6th, 2022
2,903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 10.04 KB | None | 0 0
  1. set hidden
  2. set shortmess+=O
  3.  
  4. " Install vim-plug
  5. let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
  6. if empty(glob(data_dir . '/autoload/plug.vim'))
  7.     silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs  https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
  8.     autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
  9. endif
  10.  
  11. " Configure plugins
  12. call plug#begin(stdpath('data') . '/plugged')
  13.  
  14. " Nice defaults
  15. Plug 'tpope/vim-sensible'
  16.  
  17. " Lua functions
  18. Plug 'nvim-lua/plenary.nvim'
  19.  
  20. " UI
  21. Plug 'kyazdani42/nvim-web-devicons' " for file icons
  22. Plug 'akinsho/bufferline.nvim', { 'tag': 'v2.*' }
  23. Plug 'majutsushi/tagbar', { 'on': 'TagbarToggle' }
  24. Plug 'nvim-telescope/telescope.nvim'
  25. Plug 'nvim-telescope/telescope-file-browser.nvim'
  26. Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'make' }
  27. Plug 'lukas-reineke/indent-blankline.nvim'
  28. Plug 'psliwka/vim-smoothie'
  29. Plug 'kaicataldo/material.vim', { 'branch': 'main' }
  30. Plug 'projekt0n/github-nvim-theme'
  31. Plug 'nvim-lualine/lualine.nvim'
  32.  
  33. " Autocomplete
  34. Plug 'neoclide/coc.nvim', { 'branch': 'release' }
  35. Plug 'raimondi/delimitmate'
  36.  
  37. " Git
  38. Plug 'tpope/vim-fugitive'
  39.  
  40. " Lang
  41. Plug 'rust-lang/rust.vim', { 'for': 'rust' }
  42. Plug 'cespare/vim-toml', { 'for': 'toml' }
  43. Plug 'lervag/vimtex', { 'for': 'LaTeX' }
  44. Plug 'gregsexton/MatchTag', { 'for': 'html' }
  45. Plug 'sheerun/vim-polyglot'
  46.  
  47. " Utility
  48. Plug 'tpope/vim-surround'
  49. Plug 'editorconfig/editorconfig-vim'
  50. Plug 'max397574/better-escape.nvim'
  51. Plug 'numToStr/Comment.nvim'
  52. Plug 'phaazon/hop.nvim'
  53.  
  54. " Snipits
  55. Plug 'honza/vim-snippets'
  56.  
  57. call plug#end()
  58.  
  59. " Vim settings
  60. set encoding=utf-8
  61. set nowrap
  62. set showmatch
  63. set hlsearch
  64. set number
  65. set mouse=a
  66. set wildchar=<Tab> wildmenu wildmode=full
  67. syntax enable
  68. filetype plugin indent on
  69. set tabstop=4
  70. set shiftwidth=4
  71. set expandtab
  72. set conceallevel=2
  73. set emoji
  74. set history=1000
  75. set backspace=indent,eol,start
  76. set undofile
  77. set undodir=/tmp
  78. set foldlevel=0
  79. set inccommand=nosplit
  80.  
  81. " Performance
  82. set nocursorline
  83. set nocursorcolumn
  84. set scrolljump=5
  85. set lazyredraw
  86. set redrawtime=10000
  87. set synmaxcol=180
  88. set re=0
  89.  
  90. " Coc
  91. set cmdheight=1
  92. set updatetime=300
  93. set signcolumn=yes
  94. set shortmess+=c
  95. set nobackup
  96. set nowritebackup
  97.  
  98.  
  99. """ Mappings
  100. " Remap leader
  101. let mapleader = ","
  102.  
  103. " emulate windows copy, cut behavior
  104. vnoremap <LeftRelease> "+y<LeftRelease>
  105. vnoremap <C-c> "+y<CR>
  106. vnoremap <C-x> "+d<CR>
  107.  
  108. " disable hl with 2 esc
  109. noremap <silent><esc> <esc>:noh<CR><esc>
  110.  
  111. " Plugins
  112. nmap <F5> :TagbarToggle<CR>
  113.  
  114. " Buffer navigation
  115. nnoremap <silent> <tab> :BufferLineCycleNext<cr>
  116. nnoremap <silent> <S-tab> :BufferLineCyclePrev<cr>
  117. nnoremap <silent> kb <cmd>bdelete<cr>
  118.  
  119. " new line in normal mode and back
  120. map <Enter> o<ESC>
  121. map <S-Enter> O<ESC>
  122.  
  123. " Hop mappings
  124. nnoremap f <cmd>HopChar1<cr>
  125. nnoremap s <cmd>HopChar2<cr>
  126. nnoremap w <cmd>HopWord<cr>
  127. vnoremap f <cmd>HopChar1<cr>
  128. vnoremap s <cmd>HopChar2<cr>
  129. vnoremap w <cmd>HopWord<cr>
  130.  
  131. " Telescope mappings
  132. nnoremap <leader>ff <cmd>Telescope find_files<cr>
  133. nnoremap <leader>fg <cmd>Telescope live_grep<cr>
  134. nnoremap <leader>fh <cmd>Telescope help_tags<cr>
  135. nnoremap <f4> <cmd>Telescope file_browser<cr>
  136.  
  137. " Edit shortcuts
  138. nnoremap <silent> <leader>ev :execute 'edit' resolve($MYVIMRC)<cr>
  139. nnoremap <silent> <leader>xv :source $MYVIMRC<cr>
  140.  
  141. """ End mappings
  142.  
  143. " Tagbar configuration
  144. let g:tagbar_autofocus = 1
  145.  
  146. " GUI
  147. let g:material_theme_style = 'darker'
  148. let $NVIM_TUI_ENABLE_TRUE_COLOR = 1
  149. set termguicolors
  150. silent! colorscheme github_dimmed
  151. set synmaxcol=500
  152.  
  153. " Lua settings
  154. lua << EOF
  155. require("bufferline").setup {
  156.     options = {
  157.         diagnostics = "coc",
  158.         show_close_icon = false,
  159.         show_buffer_close_icons = false,
  160.         numbers = "buffer_id"
  161.     }
  162. }
  163.  
  164. require("indent_blankline").setup {}
  165.  
  166. require("Comment").setup()
  167.  
  168. require("hop").setup()
  169.  
  170. require("better_escape").setup {
  171.     mapping = {",,"},
  172.     timeout = 150,
  173.     clear_empty_lines = false,
  174.     keys = "<Esc>",
  175. }
  176.  
  177. require("telescope").setup {
  178.     defaults = { file_ignore_patterns = {"node_modules"} },
  179.     extensions = {
  180.         fzf = {
  181.             fuzzy = true,
  182.             override_generic_sorter = true,
  183.             override_file_sorter = true,
  184.             case_mode = "smart_case",
  185.         }
  186.     }
  187. }
  188.  
  189. require("telescope").load_extension("file_browser")
  190. require("telescope").load_extension("fzf")
  191.  
  192. require("lualine").setup {
  193.   options = {
  194.     icons_enabled = true,
  195.     theme = "github_dimmed",
  196.     component_separators = { left = '', right = ''},
  197.     section_separators = { left = '', right = ''},
  198.     disabled_filetypes = {},
  199.     always_divide_middle = true,
  200.     globalstatus = false,
  201.   },
  202.   sections = {
  203.     lualine_a = {'mode'},
  204.     lualine_b = {'branch', 'diff', 'diagnostics'},
  205.     lualine_c = {},
  206.     lualine_x = {'encoding', 'fileformat', 'filetype'},
  207.     lualine_y = {'progress'},
  208.     lualine_z = {'location'}
  209.   },
  210.   inactive_sections = {
  211.     lualine_a = {},
  212.     lualine_b = {},
  213.     lualine_c = {'filename'},
  214.     lualine_x = {'location'},
  215.     lualine_y = {},
  216.     lualine_z = {}
  217.   },
  218.   tabline = {},
  219.   extensions = {}
  220. }
  221. EOF
  222.  
  223. " LaTeX settings
  224. let g:tex_flavor = 'latex'
  225. let g:vimtex_quickfix_mode = 0
  226. set conceallevel=1
  227. let g:tex_conceal = 'abdmg'
  228.  
  229. " Return to last edit position when opening files
  230. autocmd BufReadPost *
  231.      \ if line("'\"") > 0 && line("'\"") <= line("$") |
  232.      \   exe "normal! g`\"" |
  233.      \ endif
  234.  
  235.  
  236. " Use <c-space> to trigger completion.
  237. if has('nvim')
  238.   inoremap <silent><expr> <c-space> coc#refresh()
  239. else
  240.   inoremap <silent><expr> <c-@> coc#refresh()
  241. endif
  242.  
  243. " Make <CR> auto-select the first completion item and notify coc.nvim to
  244. " format on enter, <cr> could be remapped by other vim plugin
  245. inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
  246.                               \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
  247. " Use tab for trigger completion with characters ahead and navigate.
  248. inoremap <silent><expr> <TAB>
  249.       \ pumvisible() ? coc#_select_confirm() :
  250.       \ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
  251.       \ <SID>check_back_space() ? "\<TAB>" :
  252.       \ coc#refresh()
  253.  
  254. function! s:check_back_space() abort
  255.   let col = col('.') - 1
  256.   return !col || getline('.')[col - 1]  =~# '\s'
  257. endfunction
  258.  
  259. let g:coc_snippet_next = '<tab>'
  260. let g:coc_snippet_prev = '<S-Tab>'
  261.  
  262. " Use `[g` and `]g` to navigate diagnostics
  263. " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
  264. nmap <silent> [g <Plug>(coc-diagnostic-prev)
  265. nmap <silent> ]g <Plug>(coc-diagnostic-next)
  266.  
  267. " GoTo code navigation.
  268. nmap <silent> gd <Plug>(coc-definition)
  269. nmap <silent> gy <Plug>(coc-type-definition)
  270. nmap <silent> gi <Plug>(coc-implementation)
  271. nmap <silent> gr <Plug>(coc-references)
  272.  
  273. " Run the Code Lens action on the current line.
  274. nmap <leader>cl <Plug>(coc-codelens-action)
  275.  
  276. " Use K to show documentation in preview window.
  277. nnoremap <silent> K :call <SID>show_documentation()<CR>
  278.  
  279. function! s:show_documentation()
  280.   if (index(['vim','help'], &filetype) >= 0)
  281.     execute 'h '.expand('<cword>')
  282.   elseif (coc#rpc#ready())
  283.     call CocActionAsync('doHover')
  284.   else
  285.     execute '!' . &keywordprg . " " . expand('<cword>')
  286.   endif
  287. endfunction
  288.  
  289. " Highlight the symbol and its references when holding the cursor.
  290. autocmd CursorHold * silent call CocActionAsync('highlight')
  291.  
  292. " Symbol renaming.
  293. nmap <leader>rn <Plug>(coc-rename)
  294.  
  295. " Formatting selected code.
  296. xmap <F1> :Format<cr>
  297. nmap <F1> :Format<cr>
  298.  
  299. " Applying codeAction to the selected region.
  300. " Example: `<leader>aap` for current paragraph
  301. xmap <leader>a  <Plug>(coc-codeaction-selected)
  302. nmap <leader>a  <Plug>(coc-codeaction-selected)
  303.  
  304. " Remap keys for applying codeAction to the current buffer.
  305. nmap <leader>ac  <Plug>(coc-codeaction)
  306. " Apply AutoFix to problem on the current line.
  307. nmap <leader>qf  <Plug>(coc-fix-current)
  308.  
  309. " Map function and class text objects
  310. " NOTE: Requires 'textDocument.documentSymbol' support from the language server.
  311. xmap if <Plug>(coc-funcobj-i)
  312. omap if <Plug>(coc-funcobj-i)
  313. xmap af <Plug>(coc-funcobj-a)
  314. omap af <Plug>(coc-funcobj-a)
  315. xmap ic <Plug>(coc-classobj-i)
  316. omap ic <Plug>(coc-classobj-i)
  317. xmap ac <Plug>(coc-classobj-a)
  318. omap ac <Plug>(coc-classobj-a)
  319.  
  320. " Remap <C-f> and <C-b> for scroll float windows/popups.
  321. if has('nvim-0.4.0') || has('patch-8.2.0750')
  322.     nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  323.     nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
  324.     inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
  325.     inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
  326.     vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  327.     vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
  328. endif
  329.  
  330. " Use CTRL-S for selections ranges.
  331. " Requires 'textDocument/selectionRange' support of language server.
  332. nmap <silent> <C-s> <Plug>(coc-range-select)
  333. xmap <silent> <C-s> <Plug>(coc-range-select)
  334.  
  335. " Add `:Format` command to format current buffer.
  336. command! -nargs=0 Format :call CocAction('format')
  337.  
  338. " Add `:Fold` command to fold current buffer.
  339. command! -nargs=? Fold :call     CocAction('fold', <f-args>)
  340.  
  341. " Add `:OR` command for organize imports of the current buffer.
  342. command! -nargs=0 OR   :call     CocAction('runCommand', 'editor.action.organizeImport')
  343.  
  344. " Coc languages
  345. let g:coc_global_extensions = [
  346.       \ 'coc-vimtex',
  347.       \ 'coc-omni',
  348.       \ 'coc-clangd',
  349.       \ 'coc-snippets',
  350.       \ 'coc-pyright',
  351.       \ 'coc-json',
  352.       \ 'coc-css',
  353.       \ 'coc-yaml',
  354.       \ 'coc-rust-analyzer',
  355.       \ 'coc-vimlsp',
  356.       \ 'coc-tsserver',
  357.       \ 'coc-syntax',
  358.       \ 'coc-prettier',
  359.       \ 'coc-git',
  360.       \ 'coc-sh',
  361.       \ 'coc-highlight',
  362.       \ 'coc-html',
  363.       \ 'coc-eslint',
  364.       \ 'coc-lists'
  365.       \]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement