Advertisement
ArshiaAghaei

init.vim

Mar 14th, 2022
2,148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 6.85 KB | None | 0 0
  1. " Load packer.nvim and LSP
  2.  
  3. lua require('plugins')
  4. lua require('lsp')
  5. lua require('lsp-config')
  6.  
  7. " Make packer.nvim auto compile
  8. augroup packer_user_config
  9.   autocmd!
  10.   autocmd BufWritePost plugins.lua source <afile> | PackerCompile
  11. augroup end
  12.  
  13. " Set leader key to space
  14. let mapleader = "\<Space>"
  15.  
  16. " Some initial configs
  17. set hidden
  18. set nobackup
  19. set nowritebackup
  20. set cmdheight=2
  21. set updatetime=300
  22. set shortmess+=c
  23. set signcolumn=yes
  24. set number
  25. set mouse=a
  26. au BufWinEnter * match ExtraWhitespace /\s\+$/
  27. au InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
  28. au InsertLeave * match ExtraWhitespace /\s\+$/
  29. au BufWinLeave * call clearmatches()
  30. set nocompatible
  31. set showmatch
  32. set hlsearch
  33. set incsearch
  34. set tabstop=4
  35. set softtabstop=4
  36. set expandtab
  37. set shiftwidth=4
  38. set autoindent
  39. set wildmode=longest, list
  40. filetype plugin indent on
  41. set clipboard=unnamedplus
  42. set cursorline
  43. set ttyfast
  44. set spell
  45.  
  46. " Copy to clipboard
  47.  
  48. nnoremap <leader>Y "+yg_
  49. vnoremap <leader>y "+y
  50. nnoremap <leader>y "+y
  51. nnoremap <leader>yy "+yy
  52.  
  53. " Paste from clipboard
  54.  
  55. nnoremap <leader>p "+p
  56. nnoremap <leader>P "+p
  57. vnoremap <leader>p "+p
  58. vnoremap <leader>P "+p
  59.  
  60. " Put some packer.nvim shortcuts
  61. nnoremap <silent> <leader>u <cmd>PackerUpdate<CR>
  62. nnoremap <silent> <leader>i <cmd>PackerInstall<CR>
  63. vnoremap <silent> <leader>i <cmd>PackerUpdate<CR>
  64. vnoremap <silent> <leader>u <cmd>PackerInstall<CR>
  65.  
  66.  
  67. " Set save key
  68.  
  69. inoremap <silent> <C-s> <cmd>w<CR>
  70. nnoremap <silent> <C-s> <cmd>w<CR>
  71. vnoremap <silent> <C-s> <cmd>w<CR>
  72.  
  73.  
  74. " Quick edit this file
  75.  
  76. nnoremap <silent> <leader>s <cmd>e $MYVIMRC<CR>
  77. vnoremap <silent> <leader>s <Esc>e $MYVIMRC<CR>
  78.  
  79. " Quickly edit plugins file
  80.  
  81. nnoremap <silent> <leader>p <cmd>e ~/.config/nvim/lua/plugins.lua<CR>
  82. vnoremap <silent> <leader>p <cmd>e ~/.config/nvim/lua/plugins.lua<CR>
  83.  
  84. " Quickly edit xmonad.hs
  85.  
  86. nnoremap <silent> <leader>x <cmd>e ~/.config/xmonad/xmonad.hs<CR>
  87. vnoremap <silent> <leader>x <cmd>e ~/.config/xmonad/xmonad.hs<CR>
  88.  
  89. " Quickly edit ~/.xmobarrc
  90.  
  91. nnoremap <silent> <leader>a <cmd>e ~/.xmobarrc<CR>
  92. vnoremap <silent> <leader>a <cmd>e ~/.xmobarrc<CR>
  93.  
  94.  
  95. " Add/remove/update a lsp
  96.  
  97. nnoremap <silent> <leader>l <cmd>e ~/.config/nvim/lua/lsp.lua<CR>
  98. vnoremap <silent> <leader>l <cmd>e ~/.config/nvim/lua/lsp.lua<CR>
  99.  
  100. " Work on lsp-config
  101. nnoremap <silent> <leader>c <cmd>e ~/.config/nvim/lua/lsp-config.lua<CR>
  102. nnoremap <silent> <leader>c <cmd>e ~/.config/nvim/lua/lsp-config.lua<CR>
  103.  
  104. " setup mapping to call :LazyGit and :LazyGitConfig
  105. nnoremap <silent> <leader>g  :LazyGit<CR>
  106. nnoremap <silent> <leader>gc :LazyGitConfig<CR>
  107.  
  108. if executable('nvr')
  109.     let $GIT_EDITOR = "nvr -cc split --remote-wait +'set bufhidden=wipe'"
  110. endif
  111.  
  112. " Remove all trailing whitespaces
  113. nnoremap <silent> <leader>rs :let _s=@/ <Bar> :%s/\s\+$//e <Bar> :let @/=_s <Bar> :nohl <Bar> :unlet _s <CR>
  114.  
  115. " Cppman config
  116.  
  117. function! s:JbzCppMan()
  118.     let old_isk = &iskeyword
  119.     setl iskeyword+=:
  120.     let str = expand("<cword>")
  121.     let &l:iskeyword = old_isk
  122.     execute 'Man ' . str
  123. endfunction
  124. command! JbzCppMan :call s:JbzCppMan()
  125.  
  126. au FileType cpp nnoremap <buffer>K :JbzCppMan<CR>
  127.  
  128. " OpenBrowser config
  129.  
  130. let g:openbrowser_search_engines = extend(
  131. \ get(g:, 'openbrowser_search_engines', {}),
  132. \ {
  133. \   'cppreference': 'https://en.cppreference.com/mwiki/index.php?title=Special%3ASearch&search={query}',
  134. \   'qt': 'https://doc.qt.io/qt-5/search-results.html?q={query}',
  135. \   'stackoverflow': 'https://stackoverflow.com/search?q={query}',
  136. \   'cpp': 'cplusplus.com/search.do?q={query}',
  137. \   'python': 'https://docs.python.org/3/search.html?q={query}&check_keywords=yes&area=default',
  138. \   'rust': 'https://doc.rust-lang.org/std/index.html?search={query}',
  139. \   'google': 'https://www.google.com/search?q={query}'
  140. \ },
  141. \ 'keep'
  142. \)
  143.  
  144. nnoremap <silent> <leader>sc :call openbrowser#smart_search(expand('<cword>'), "cppreference")<CR>
  145. nnoremap <silent> <leader>sq :call openbrowser#smart_search(expand('<cword>'), "qt")<CR>
  146. nnoremap <silent> <leader>sd :call openbrowser#smart_search(expand('<cword>'), "cpp")<CR>
  147. nnoremap <silent> <leader>ss :call openbrowser#smart_search(expand('<cword>'), "stackoverflow")<CR>
  148. nnoremap <silent> <leader>sp :call openbrowser#smart_search(expand('<cword>'), "python")<CR>
  149. nnoremap <silent> <leader>sr :call openbrowser#smart_search(expand('<cword>'), "rust")<CR>
  150. nnoremap <silent> <leader>sg :call openbrowser#smart_search(expand('<cword>'), "google")<CR>
  151.  
  152.  
  153. " Vim-Gutentags + Gutentags-plus config
  154.  
  155. set tags=./tags;
  156. let g:gutentags_ctags_exclude_wildignore = 1
  157. let g:gutentags_ctags_exclude = [
  158.   \'node_modules', '_build', 'build', 'CMakeFiles', '.mypy_cache', 'venv',
  159.   \'*.md', '*.tex', '*.css', '*.html', '*.json', '*.xml', '*.xmls', '*.ui']
  160.  
  161. let g:gutentags_modules = ['ctags', 'gtags_cscope']
  162. let g:gutentags_project_root = ['.root']
  163. let g:gutentags_cache_dir = expand('~/.cache/tags')
  164. let g:gutentags_plus_switch = 1
  165.  
  166. " Vista.vim configs
  167.  
  168. nnoremap <silent> <leader>v :Vista!!<CR>
  169.  
  170. function! NearestMethodOrFunction() abort
  171.   return get(b:, 'vista_nearest_method_or_function', '')
  172. endfunction
  173.  
  174. set statusline+=%{NearestMethodOrFunction()}
  175.  
  176. " By default vista.vim never run if you don't call it explicitly.
  177. "
  178. " If you want to show the nearest function in your statusline automatically,
  179. " you can add the following line to your vimrc
  180. autocmd VimEnter * call vista#RunForNearestMethodOrFunction()
  181.  
  182. " Vim-spector configs
  183.  
  184. let g:vimspector_enable_mappings = 'HUMAN'
  185. nnoremap <leader>b <Plug>VimspectorBaloonEval
  186. vnoremap <leader>b <Plug>VimspectorBaloonEval
  187.  
  188.  
  189. " Set color theme
  190. set termguicolors
  191. colorscheme bluewery
  192. let g:lightline = { 'colorscheme': 'bluewery' }
  193.  
  194. " Vifm toggle keybinding
  195.  
  196. nnoremap <silent> <leader>m <cmd>Vifm .<CR>
  197.  
  198. " Find files using Telescope command-line sugar.
  199. nnoremap <leader>ff <cmd>Telescope find_files<cr>
  200. nnoremap <leader>fg <cmd>Telescope live_grep<cr>
  201. nnoremap <leader>fb <cmd>Telescope buffers<cr>
  202. nnoremap <leader>fh <cmd>Telescope help_tags<cr>
  203.  
  204. " Discord presence
  205.  
  206. " General options
  207. let g:presence_auto_update         = 1
  208. let g:presence_neovim_image_text   = "The One True Text Editor"
  209. let g:presence_main_image          = "neovim"
  210. let g:presence_client_id           = "793271441293967371"
  211. let g:presence_log_level           = "debug"
  212. let g:presence_debounce_timeout    = 10
  213. let g:presence_enable_line_number  = 1
  214. let g:presence_blacklist           = []
  215. let g:presence_buttons             = 1
  216. let g:presence_file_assets         = {}
  217.  
  218. " Rich Presence text options
  219. let g:presence_editing_text        = "Editing %s"
  220. let g:presence_file_explorer_text  = "Browsing %s"
  221. let g:presence_git_commit_text     = "Committing changes"
  222. let g:presence_plugin_manager_text = "Managing plugins"
  223. let g:presence_reading_text        = "Reading %s"
  224. let g:presence_workspace_text      = "Working on %s"
  225. let g:presence_line_number_text    = "Line %s out of %s"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement