.vimrc 18 KB

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