init.vim 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. "##############################################################################
  2. " General settings
  3. "##############################################################################
  4. set nocompatible " no vi-compatible
  5. " Automatic reloading config file (for NERDCommenter) -------------------------
  6. autocmd! VimEnter * :source ~/.config/nvim/init.vim
  7. autocmd VimEnter,TabEnter *.py,*.lua,*.html,*.css,*.txt :ColorHighlight
  8. " Не автокомментировать новые линии при переходе на новую строку
  9. autocmd BufEnter * set fo-=c fo-=r fo-=o
  10. " autocmd! VimEnter * :redraw
  11. " To ALWAYS use the clipboard for ALL operations (instead of '+' or '*') ------
  12. " set clipboard+=unnamedplus
  13. " Showing line numbers and length ---------------------------------------------
  14. set number
  15. set relativenumber
  16. " set linespace=3
  17. set wrap linebreak nolist "Данная вариация работает как wrap,... но
  18. " переносит строчки не посимвольно, а по словам
  19. set tw=79 "width of document (used by gd)
  20. set fo-=t "don't automatically wrap text when typing
  21. set colorcolumn=80
  22. highlight ColorColumn ctermbg=233
  23. set cursorline "highlight current line
  24. set cursorcolumn "highlight current column
  25. set whichwrap=<,>,[,],h,l "не останавливаться курсору на конце строки
  26. set ttimeoutlen=20 "Понижаем задержку ввода escape последовательностей
  27. let &t_SI.="\e[5 q" "SI = режим вставки
  28. let &t_SR.="\e[3 q" "SR = режим замены
  29. let &t_EI.="\e[1 q" "EI = нормальный режим
  30. "Где 1 - это мигающий прямоугольник
  31. "2 - обычный прямоугольник
  32. "3 - мигающее подчёркивание
  33. "4 - просто подчёркивание
  34. "5 - мигающая вертикальная черта
  35. "6 - просто вертикальная черта
  36. " Indents ---------------------------------------------------------------------
  37. " set autoindent "при начале новой строки, отступ копируется из предыдущей
  38. set smartindent
  39. set mouse=a
  40. set noex "не читаем файл конфигурации из текущей директории
  41. set stal=2 "постоянно выводим строку с табами
  42. set tpm=20 "максимальное количество открытых табов
  43. set history=50
  44. set undolevels=50
  45. set noerrorbells "instead of beeping
  46. set wildmenu "красивое автодополнение
  47. set cmdheight=2 "Give more space for displaying messages.
  48. set scrolloff=3 "when scrolling, keep cursor 3 lines away from screen border
  49. set showmatch "for brackets
  50. highlight MatchParen cterm=underline ctermbg=Cyan ctermfg=none
  51. highlight MatchParen gui=underline guibg=Cyan guifg=none
  52. " Allow plugins by file type (required for plugins!) --------------------------
  53. filetype plugin on
  54. filetype indent on
  55. " filetype plugin indent on
  56. syntax on "Enable syntax highlighting
  57. " remove ugly vertical lines on window division
  58. " set fillchars+=vert:\
  59. " Real programmers don't use TABs but spaces ----------------------------------
  60. set tabstop=2
  61. set softtabstop=2
  62. set shiftwidth=2
  63. set shiftround
  64. set expandtab
  65. " Search -----------------------------------------------------------------------
  66. set hlsearch
  67. set incsearch
  68. set ignorecase
  69. set smartcase
  70. " Disable backup and swap files - they trigger too many events ----------------
  71. " for file system watchers
  72. set nobackup
  73. set nowritebackup
  74. set noswapfile
  75. " Show whitespaces and other symbols ------------------------------------------
  76. " set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:␣
  77. " set list
  78. " Go to the last editing position ---------------------------------------------
  79. " При редактировании файла всегда переходить на последнюю известную
  80. " позицию курсора. Если позиция ошибочная - не переходим.
  81. autocmd BufReadPost *
  82. \ if line("'\"") > 0 && line("'\"") <= line("$") |
  83. \ exe "normal! g`\"" |
  84. \ endif
  85. " Statusline ------------------------------------------------------------------
  86. set showmode "показывать текущий режим
  87. set showcmd "показывать незавершенные команды в статусбаре
  88. set laststatus=2 "always show statusline
  89. "set statusline=%#title#%F%m%r%h%w\ %y%=[HEX=\%02.2B]\ [%{&encoding}]\ [%{&fileformat}]\ [POS=%l,%c,\ %p%%]\ [LEN=%L] "формат строки состояния
  90. set statusline=
  91. set statusline+=%#DiffText# " :hi to choose the color
  92. set statusline+=\ %M\ %F%r%h%w\ %y
  93. set statusline+=%= " Right side settings
  94. set statusline+=%#TabLineSel#
  95. set statusline+=\ HEX=%02.2B
  96. set statusline+=\ %{&encoding}[%{&fileformat}]
  97. set statusline+=\ %l:%c/%L\ %p%%
  98. set statusline+=\ [%n]
  99. "##############################################################################
  100. " Encoding
  101. "##############################################################################
  102. set encoding=utf8 "кодировка по дефолту
  103. set termencoding=utf8 "Кодировка вывода на терминал
  104. set fileencodings=utf8,cp1251,koi8r,cp866 "Возможные кодировки файлов (автоматическая перекодировка)
  105. " Run commands in normal mode with switched cyrillic --------------------------
  106. set langmap=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ,фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz
  107. " Переключение раскладок средствами Vim по Ctr+^ ------------------------------
  108. set keymap=russian-jcukenwin
  109. set iminsert=0 "Язык ввода при старте Вима - Английский
  110. set imsearch=0 "Аналогично настраивается режим поиска
  111. set autochdir "текущий каталог всегда совпадает с содержимым активного окна
  112. set browsedir=current "browsedir "last", "buffer" or "current": which directory used for the file browser
  113. " Show whitespaces by red color -----------------------------------------------
  114. " MUST be inserted BEFORE the colorscheme command
  115. autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red
  116. autocmd InsertLeave * match ExtraWhitespace /\s\+$/
  117. "##############################################################################
  118. " Colorscheme and GUI Settings
  119. "##############################################################################
  120. if has("termguicolors")
  121. set termguicolors
  122. else
  123. set t_Co=256
  124. endif
  125. set background=dark
  126. " colorscheme ayu
  127. " colorscheme darcula
  128. " colorscheme memorycolor
  129. " colorscheme OceanicNext
  130. " colorscheme OceanicMaterial
  131. colorscheme Everforest
  132. " colorscheme gruvbox-material
  133. "##############################################################################
  134. " Plugins used by vim
  135. " Specify a directory for plugins
  136. " - For Neovim: stdpath('data') . '/plugged'
  137. " - Avoid using standard Vim directory names like 'plugin'
  138. "##############################################################################
  139. call plug#begin('~/.config/nvim/plugged')
  140. "#########################################
  141. " Code/project navigation
  142. "#########################################
  143. Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
  144. Plug 'vifm/vifm.vim'
  145. Plug 'nvim-telescope/telescope.nvim'
  146. Plug 'nvim-lua/plenary.nvim'
  147. Plug 'DreamMaoMao/yazi.nvim'
  148. "#########################################
  149. " Code completion
  150. "#########################################
  151. Plug 'ycm-core/YouCompleteMe'
  152. "#########################################
  153. " Other
  154. "#########################################
  155. Plug 'preservim/nerdcommenter'
  156. Plug 'tpope/vim-surround'
  157. Plug 'chrisbra/Colorizer'
  158. Plug 'luochen1990/rainbow'
  159. Plug 'nvim-treesitter/nvim-treesitter'
  160. " Tell vim-plug we finished declaring plugins, so it can load them
  161. call plug#end()
  162. "##############################################################################
  163. " NERDTree Settings
  164. "##############################################################################
  165. noremap <C-F12> :NERDTreeToggle<CR>
  166. " Autorefresh on tree focus
  167. function! NERDTreeRefresh()
  168. if &filetype == "nerdtree"
  169. silent exe substitute(mapcheck("R"), "<CR>", "", "")
  170. endif
  171. endfunction
  172. autocmd BufEnter * call NERDTreeRefresh()
  173. "##############################################################################
  174. " NERDCommenter Settings
  175. "##############################################################################
  176. map <Leader>/ <plug>NERDCommenterToggle
  177. " map <C-c>/ <plug>NERDCommenterToggle
  178. let g:NERDSpaceDelims = 1 " Add spaces after comment delimiters by default
  179. let g:NERDCompactSexyComs = 1 " Use compact syntax for prettified multi-line comments
  180. let g:NERDCommentEmptyLines = 1 " Allow commenting and inverting empty lines (useful when commenting a region)
  181. let g:NERDTrimTrailingWhitespace = 1 " Enable trimming of trailing whitespace when uncommenting
  182. let g:NERDToggleCheckAllLines = 1 " Enable NERDCommenterToggle to check all selected lines is commented or not
  183. let g:NERDCreateDefaultMappings = 0 " Cancel NERD's default mappings
  184. " let g:NERDDefaultAlign = 'left' " Align line-wise comment delimiters flush left instead of following code indentation
  185. "##############################################################################
  186. " ranbow Settings
  187. "##############################################################################
  188. "set to 0 if you want to enable it later via :RainbowToggle
  189. let g:rainbow_active = 1
  190. "##############################################################################
  191. " Colorizer Settings
  192. "##############################################################################
  193. " :let g:colorizer_auto_filetype='css,html,py,lua'
  194. " :let g:colorizer_auto_color = 1
  195. "##############################################################################
  196. " YouCompleteMe Settings
  197. "##############################################################################
  198. let g:ycm_python_binary_path = '/usr/bin/python3'
  199. let g:python3_host_prog = '~/Projects/Python/Virtualenvironments/poetry_venvs/py3.10.x_pynvim/.venv/bin/python3'
  200. " :nnoremap fd :YcmCompleter GoToDefinition<CR>
  201. " :nnoremap bb <C-o>
  202. " let g:loaded_youcompleteme = 1
  203. " let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
  204. " let g:ycm_extra_conf_globlist = ['!~/*']
  205. " let g:ycm_autoclose_preview_window_after_completion = 1
  206. " let g:ycm_min_num_of_chars_for_completion = 1
  207. " for python
  208. " let g:ycm_semantic_triggers = {'python': ['re!from\s+\S+\s+import\s']}
  209. "##############################################################################
  210. " Mappings
  211. "##############################################################################
  212. " <Leader> key ----------------------------------------------------------------
  213. " let mapleader = " "
  214. let mapleader = ","
  215. let maplocalleader = "\\"
  216. " Removes highlight of your last search ---------------------------------------
  217. noremap <C-c>h :nohlsearch<CR>
  218. vnoremap <C-c>h :nohlsearch<CR>
  219. inoremap <C-c>h :nohlsearch<CR>
  220. " Bind Ctrl+<movement> keys to move around the windows ------------------------
  221. noremap <C-j> <C-w>j
  222. noremap <C-k> <C-w>k
  223. noremap <C-l> <C-w>l
  224. noremap <C-h> <C-w>h
  225. set splitbelow "новое окно появляется снизу
  226. " Resize windows --------------------------------------------------------------
  227. noremap <Up> :resize +2<CR>
  228. noremap <Down> :resize -2<CR>
  229. noremap <Left> :vertical resize -2<CR>
  230. noremap <Right> :vertical resize +2<CR>
  231. inoremap <Up> <Esc>:resize +2<CR>a
  232. inoremap <Down> <Esc>:resize -2<CR>a
  233. inoremap <Left> <Esc>:vertical resize -2<CR>a
  234. inoremap <Right> <Esc>:vertical resize +2<CR>a
  235. " Switch file encoding --------------------------------------------------------
  236. set wcm=<Tab> "WTF? but all work
  237. menu Encoding.cp1251 :e ++enc=cp1251<CR>
  238. menu Encoding.koi8-r :e ++enc=koi8-r<CR>
  239. menu Encoding.cp866 :e ++enc=cp866<CR>
  240. menu Encoding.utf-8 :e ++enc=utf-8 <CR>
  241. noremap <F11> :emenu Encoding.<TAB>
  242. " Edit & Apply changes in config file -----------------------------------------
  243. nnoremap <Leader>ev :tabnew ~/.config/nvim/init.vim<CR>
  244. nnoremap <Leader>sv :source ~/.config/nvim/init.vim<CR>
  245. nnoremap <Leader>eg :tabnew ~/.config/nvim/ginit.vim<CR>
  246. nnoremap <Leader>sg :source ~/.config/nvim/ginit.vim<CR>
  247. nnoremap <Leader>gy :Yazi<CR>
  248. " Move line up/down -----------------------------------------------------------
  249. nnoremap <M-k> :m .-2<CR>==
  250. nnoremap <M-j> :m .+1<CR>==
  251. inoremap <M-k> <Esc>:m .-2<CR>==gi
  252. inoremap <M-j> <Esc>:m .+1<CR>==gi
  253. vnoremap <M-k> :m '<-2<CR>gv=gv
  254. vnoremap <M-j> :m '>+1<CR>gv=gv
  255. " Easier moving of code blocks (doesn't lose selection) -----------------------
  256. vnoremap < <gv
  257. vnoremap > >gv
  258. " Execute Python script -------------------------------------------------------
  259. nnoremap <F10> <Esc>:w<CR>:! python3 %<CR>
  260. inoremap <F10> <Esc>:w<CR>:! python3 %<CR>a
  261. " Open, Save, Update & Quit ---------------------------------------------------
  262. nnoremap <C-o> :browse confirm e <CR>
  263. " Close buffer without saving
  264. map <Esc><Esc> :q!<CR>
  265. " Quit all windows without saving
  266. nnoremap <Leader>q :qa!<CR>
  267. " Save
  268. nnoremap <C-s> :w<CR>
  269. inoremap <C-s> <Esc>:w<CR>a
  270. " Tabs ------------------------------------------------------------------------
  271. " Open new tab
  272. nnoremap <Leader>tn :tabnew<CR>
  273. inoremap <Leader>tn <Esc>:tabnew<CR>a
  274. " Switch between tabs
  275. " nnoremap <F8> :tabfirst <CR>
  276. " nnoremap <F9> :tablast <CR>
  277. nnoremap <M-{> :tabfirst <CR>
  278. nnoremap <M-}> :tablast <CR>
  279. nnoremap <M-[> :tabp <CR>
  280. nnoremap <M-]> :tabn <CR>
  281. nnoremap <M-1> 1gt
  282. nnoremap <M-2> 2gt
  283. nnoremap <M-3> 3gt
  284. nnoremap <M-4> 4gt
  285. nnoremap <M-5> 5gt
  286. nnoremap <M-6> 6gt
  287. nnoremap <M-7> 7gt
  288. nnoremap <M-8> 8gt
  289. nnoremap <M-9> 9gt
  290. " Go to BOL and EOL -----------------------------------------------------------
  291. inoremap <C-a> <ESC>0i
  292. inoremap <C-e> <ESC>$a
  293. " nnoremap <C-a> 0
  294. " nnoremap <C-e> $
  295. " Delete to EOL ---------------------------------------------------------------
  296. nnoremap <C-k> d$
  297. inoremap <C-k> <ESC> d$a
  298. " Delete to BOL ---------------------------------------------------------------
  299. nnoremap <C-u> d0
  300. inoremap <C-u> <ESC> d0i
  301. " Return from insert mode to normal -------------------------------------------
  302. inoremap jj <ESC>
  303. " inoremap <M-;> <ESC>
  304. " Insert a new line above/below -----------------------------------------------
  305. nnoremap <M-a> O<Esc>
  306. nnoremap <M-Enter> o<Esc>
  307. inoremap <M-a> <Esc>O
  308. inoremap <M-Enter> <Esc>o
  309. " Aligning --------------------------------------------------------------------
  310. " left
  311. inoremap <C-c>l <Esc>:left<CR>a
  312. nnoremap <C-c>l :left<CR>
  313. " right
  314. inoremap <C-c>r <Esc>:right<CR>a
  315. nnoremap <C-c>r :right<CR>
  316. " center
  317. " inoremap <C-c>c <Esc>:center<CR>a
  318. " nnoremap <C-c>c :center<CR>
  319. nnoremap Q <nop>
  320. nnoremap <Enter> <nop>
  321. " Switching colorscheme -------------------------------------------------------
  322. " let g:oeanic_next_terminal_italic = 1
  323. " let g:palenight_terminal_italics=1
  324. " let g:oceanic_italic_comments = 1
  325. " let g:tokyonight_enable_italic = 1
  326. " let g:tokyonight_style = 'night' " available: night, storm
  327. " let g:solarized_termcolors=256
  328. map <F1> :colorscheme OceanicNext<CR>
  329. map <F2> :colorscheme gruvbox<CR>
  330. " map <F3> :colorscheme gruvbox-material<CR>
  331. " map <F4> :colorscheme palenight<CR>
  332. map <F5> :colorscheme tokyonight<CR>
  333. map <F6> :colorscheme ayu<CR>
  334. " map <F7> :colorscheme onedark<CR>
  335. map <F8> :colorscheme darcula<CR>
  336. map <F9> :colorscheme memorycolor<CR>
  337. " map <F9> :colorscheme base16-flat_Cobalt2<CR>
  338. " colorscheme predawn
  339. " colorscheme nord
  340. " colorscheme ayu
  341. " colorscheme oceanicnext
  342. " colorscheme material-theme
  343. " colorscheme onehalfdark
  344. " colorscheme solarized
  345. " colorscheme cobalt2
  346. " Copy/Cut/Past from/to system buffer -----------------------------------------
  347. vnoremap <C-x> "+d
  348. vnoremap <C-c> "*y :let @+=@*<CR>
  349. map <C-p> "+p
  350. " Highlight hex colors toggle -------------------------------------------------
  351. noremap <F12> :ColorToggle<CR>
  352. " Несколько удобных биндингов для с, c++, java, python ------------------------
  353. augroup filetype_coding
  354. autocmd!
  355. au FileType python inoremap :: <END>:<CR>
  356. au FileType python inoremap (: ():<CR>
  357. au FileType python inoremap #ifn if __name__ == "__main__":<CR>
  358. au FileType python inoremap #t # TODO: <Esc>i
  359. au FileType python inoremap #f # FIXME: <Esc>i
  360. " au FileType c,cpp,cc,h,java inoremap {<CR> {<CR>}<Esc>O
  361. " au FileType c,cpp,cc,h,java inoremap #M int main(int argc, char * argv[])<CR>{<CR>return 0;<CR>}<CR><Esc>2kO
  362. " au FileType c,cpp,cc,h,java inoremap #m int main()<CR>{<CR>return 0;<CR>}<CR><Esc>2kO
  363. " au FileType c,cpp,cc,h,java inoremap #d #define
  364. " au FileType c,cpp,cc,h,java inoremap #e #endif /* */<Esc>hhi
  365. " au FileType c,cpp,cc,h,java inoremap #" #include ""<Esc>i
  366. " au FileType c,cpp,cc,h,java inoremap #< #include <><Esc>i
  367. " au FileType c,cpp,cc,h,java inoremap #f /* FIXME: */<Esc>hhi
  368. " au FileType c,cpp,cc,h,java inoremap #t /*TODO: */<Esc>hhi
  369. " au FileType c,cpp,cc,h,java inoremap ;; <END>;<CR>
  370. " au FileType c,cpp,cc,h,java inoremap (; ();<CR>
  371. " au FileType c,cpp,cc,h,java inoremap ({ () {<CR>}<Esc>O
  372. " au FileType c,cpp,cc,h,java inoremap /*<Space> /* */<Esc>3ha
  373. " au FileType c,cpp,cc,h,java inoremap ` <END>;
  374. " au FileType c,cpp,cc,h,java inoremap ' ''<Left>
  375. " au FileType c,cpp,cc,h,java inoremap " ""<Left>
  376. " au FileType c,cpp,cc,h,java inoremap ( ()<Left>
  377. " au FileType c,cpp,cc,h,java inoremap [ []<Left>
  378. " au FileType c,cpp,cc,h,java,python inoremap nl <END><CR>
  379. " au FileType c,cpp,cc,h,java,python inoremap ~ <END>:
  380. augroup END