init.vim 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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. " GUI -------------------------------------------------------------------------
  134. " set wak=no "используем ALT как обычно, а не для вызова пункта меню
  135. " if has("gui_running")
  136. " "убираем меню и тулбар
  137. " set guioptions-=m
  138. " set guioptions-=T
  139. " "убираем скроллбары
  140. " set guioptions-=r
  141. " set guioptions-=l
  142. " "используем консольные диалоги вместо графических
  143. " set guioptions+=c
  144. " " "антиалиасинг для шревтоф
  145. " " set antialias
  146. " "прячем курсор
  147. " set mousehide
  148. " " "Так не выводятся ненужные escape последовательности в :shell
  149. " " set noguipty
  150. "
  151. " " set guifont=Source_Code_Pro:h13:cRUSSIAN:qDRAFT
  152. " " set guifont=mplus\ Nerd\ Font\ 16.5
  153. " " set guifont=Iosevka\ 16
  154. " " set guifont=Cascadia\ Code\ PL\ SemiLight\ 17
  155. " " set guifont=Cascadia\ Mono\ PL\ 16.5
  156. " " set guifont=Recursive\ Mono\ Casual\ Static\ Medium\ 17
  157. " set guifont=Recursive\ Mono\ Casual\ Static\ 16
  158. " endif
  159. "##############################################################################
  160. " Plugins used by vim
  161. " Specify a directory for plugins
  162. " - For Neovim: stdpath('data') . '/plugged'
  163. " - Avoid using standard Vim directory names like 'plugin'
  164. "##############################################################################
  165. call plug#begin('~/.config/nvim/plugged')
  166. "#########################################
  167. " Code/project navigation
  168. "#########################################
  169. Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
  170. Plug 'vifm/vifm.vim'
  171. " Code and files fuzzy finder
  172. " Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
  173. " Plug 'junegunn/fzf.vim'
  174. "#########################################
  175. " Code completion
  176. "#########################################
  177. " Plug 'neoclide/coc.nvim', {'branch': 'release'}
  178. " Plug 'ycm-core/YouCompleteMe', { 'do': './install.py' }
  179. " Plug 'ycm-core/YouCompleteMe', { 'for': 'python' }
  180. Plug 'ycm-core/YouCompleteMe'
  181. " LSP
  182. Plug 'neovim/nvim-lspconfig'
  183. " Completion
  184. Plug 'hrsh7th/nvim-cmp'
  185. Plug 'hrsh7th/cmp-nvim-lsp'
  186. " Plug 'hrsh7th/cmp-nvim-lua'
  187. " Plug 'saadparwaiz1/cmp_luasnip'
  188. " Plug 'L3MON4D3/LuaSnip'
  189. Plug 'prabirshrestha/vim-lsp'
  190. Plug 'prabirshrestha/asyncomplete.vim'
  191. Plug 'prabirshrestha/asyncomplete-lsp.vim'
  192. Plug 'mattn/vim-lsp-settings'
  193. " " For JS/JSX
  194. " Plug 'yuezk/vim-js'
  195. " Plug 'maxmellon/vim-jsx-pretty'
  196. "#########################################
  197. " Other
  198. "#########################################
  199. " Plug 'gruvbox-community/gruvbox'
  200. " Plug 'vim-airline/vim-airline'
  201. " Plug 'vim-airline/vim-airline-themes'
  202. Plug 'preservim/nerdcommenter'
  203. Plug 'tpope/vim-surround'
  204. " " Plug 'etdev/vim-hexcolor'
  205. " Plug 'ap/vim-css-color'
  206. Plug 'chrisbra/Colorizer'
  207. Plug 'luochen1990/rainbow'
  208. Plug 'nvim-treesitter/nvim-treesitter'
  209. Plug 'nvim-orgmode/orgmode'
  210. " Tell vim-plug we finished declaring plugins, so it can load them
  211. call plug#end()
  212. "##############################################################################
  213. " NERDTree Settings
  214. "##############################################################################
  215. noremap <C-F12> :NERDTreeToggle<CR>
  216. " Autorefresh on tree focus
  217. function! NERDTreeRefresh()
  218. if &filetype == "nerdtree"
  219. silent exe substitute(mapcheck("R"), "<CR>", "", "")
  220. endif
  221. endfunction
  222. autocmd BufEnter * call NERDTreeRefresh()
  223. "##############################################################################
  224. " NERDCommenter Settings
  225. "##############################################################################
  226. map <Leader>/ <plug>NERDCommenterToggle
  227. " map <C-c>/ <plug>NERDCommenterToggle
  228. let g:NERDSpaceDelims = 1 " Add spaces after comment delimiters by default
  229. let g:NERDCompactSexyComs = 1 " Use compact syntax for prettified multi-line comments
  230. let g:NERDCommentEmptyLines = 1 " Allow commenting and inverting empty lines (useful when commenting a region)
  231. let g:NERDTrimTrailingWhitespace = 1 " Enable trimming of trailing whitespace when uncommenting
  232. let g:NERDToggleCheckAllLines = 1 " Enable NERDCommenterToggle to check all selected lines is commented or not
  233. let g:NERDCreateDefaultMappings = 0 " Cancel NERD's default mappings
  234. " let g:NERDDefaultAlign = 'left' " Align line-wise comment delimiters flush left instead of following code indentation
  235. "##############################################################################
  236. " ranbow Settings
  237. "##############################################################################
  238. "set to 0 if you want to enable it later via :RainbowToggle
  239. let g:rainbow_active = 1
  240. "##############################################################################
  241. " Colorizer Settings
  242. "##############################################################################
  243. " :let g:colorizer_auto_filetype='css,html,py,lua'
  244. " :let g:colorizer_auto_color = 1
  245. "##############################################################################
  246. " orgmode Settings
  247. "##############################################################################
  248. lua << EOF
  249. -- Load custom tree-sitter grammar for org filetype
  250. require('orgmode').setup_ts_grammar()
  251. -- Tree-sitter configuration
  252. require'nvim-treesitter.configs'.setup {
  253. -- If TS highlights are not enabled at all, or disabled via `disable` prop, highlighting will fallback to default Vim syntax highlighting
  254. highlight = {
  255. enable = true,
  256. additional_vim_regex_highlighting = {'org'}, -- Required for spellcheck, some LaTex highlights and code block highlights that do not have ts grammar
  257. },
  258. ensure_installed = {'org'}, -- Or run :TSUpdate org
  259. }
  260. -- require('orgmode').setup({
  261. -- org_agenda_files = {'~/Dropbox/org/*', '~/my-orgs/**/*'},
  262. -- org_default_notes_file = '~/Dropbox/org/refile.org',
  263. -- })
  264. EOF
  265. lua << EOF
  266. require'cmp'.setup({
  267. sources = {
  268. { name = 'orgmode' }
  269. }
  270. })
  271. EOF
  272. "##############################################################################
  273. " YouCompleteMe Settings
  274. "##############################################################################
  275. let g:python3_host_prog = '~/Projects/Python/Virtualenvironments/poetry_venvs/py3.10.x_pynvim/.venv/bin/python3'
  276. " :nnoremap fd :YcmCompleter GoToDefinition<CR>
  277. " :nnoremap bb <C-o>
  278. " let g:loaded_youcompleteme = 1
  279. " let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
  280. " let g:ycm_extra_conf_globlist = ['!~/*']
  281. let g:ycm_python_binary_path = '/usr/bin/python3'
  282. " let g:ycm_autoclose_preview_window_after_completion = 1
  283. " let g:ycm_min_num_of_chars_for_completion = 1
  284. " for python
  285. " let g:ycm_semantic_triggers = {'python': ['re!from\s+\S+\s+import\s']}
  286. " "##############################################################################
  287. " " LSP Settings
  288. " "##############################################################################
  289. " lua << EOF
  290. " -- Set completeopt to have a better completion experience
  291. " vim.o.completeopt = 'menuone,noselect'
  292. "
  293. " -- luasnip setup
  294. " local luasnip = require 'luasnip'
  295. "
  296. " -- nvim-cmp setup
  297. " local cmp = require 'cmp'
  298. " cmp.setup {
  299. " completion = {
  300. " autocomplete = true
  301. " },
  302. " snippet = {
  303. " expand = function(args)
  304. " require('luasnip').lsp_expand(args.body)
  305. " end,
  306. " },
  307. " mapping = {
  308. " ['<C-p>'] = cmp.mapping.select_prev_item(),
  309. " ['<C-n>'] = cmp.mapping.select_next_item(),
  310. " ['<C-d>'] = cmp.mapping.scroll_docs(-4),
  311. " ['<C-f>'] = cmp.mapping.scroll_docs(4),
  312. " ['<C-Space>'] = cmp.mapping.complete(),
  313. " ['<C-e>'] = cmp.mapping.close(),
  314. " ['<CR>'] = cmp.mapping.confirm {
  315. " behavior = cmp.ConfirmBehavior.Replace,
  316. " select = true,
  317. " },
  318. " ['<Tab>'] = function(fallback)
  319. " if vim.fn.pumvisible() == 1 then
  320. " vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-n>', true, true, true), 'n')
  321. " elseif luasnip.expand_or_jumpable() then
  322. " vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '')
  323. " else
  324. " fallback()
  325. " end
  326. " end,
  327. " ['<S-Tab>'] = function(fallback)
  328. " if vim.fn.pumvisible() == 1 then
  329. " vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-p>', true, true, true), 'n')
  330. " elseif luasnip.jumpable(-1) then
  331. " vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-jump-prev', true, true, true), '')
  332. " else
  333. " fallback()
  334. " end
  335. " end,
  336. " },
  337. " sources = {
  338. " { name = 'nvim_lsp' },
  339. " { name = 'luasnip' },
  340. " { name = 'nvim_lua' },
  341. " },
  342. " }
  343. " EOF
  344. "
  345. " lua << EOF
  346. " local nvim_lsp = require('lspconfig')
  347. "
  348. " -- Use an on_attach function to only map the following keys
  349. " -- after the language server attaches to the current buffer
  350. " local on_attach = function(client, bufnr)
  351. "
  352. " local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
  353. " local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
  354. "
  355. " -- Enable completion triggered by <c-x><c-o>
  356. " buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
  357. "
  358. " -- Mappings.
  359. " local opts = { noremap=true, silent=true }
  360. "
  361. " -- See `:help vim.lsp.*` for documentation on any of the below functions
  362. " buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
  363. " buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
  364. " buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
  365. " buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
  366. " buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
  367. " buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
  368. " buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
  369. " buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
  370. " buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
  371. " buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
  372. " buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
  373. " buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
  374. " buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
  375. " buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
  376. " buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
  377. " buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
  378. " buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
  379. " end
  380. "
  381. " -- Use a loop to conveniently call 'setup' on multiple servers and
  382. " -- map buffer local keybindings when the language server attaches
  383. " local servers = { 'pyright', 'rust_analyzer' }
  384. " for _, lsp in ipairs(servers) do
  385. " nvim_lsp[lsp].setup {
  386. " on_attach = on_attach,
  387. " flags = {
  388. " debounce_text_changes = 150,
  389. " }
  390. " }
  391. " end
  392. " EOF
  393. "##############################################################################
  394. " vim-lsp Settings
  395. "##############################################################################
  396. " vim-lsp-settings won't detect hls automatically (2020-10-26). Let's teach it:
  397. if (executable('haskell-language-server-wrapper'))
  398. au User lsp_setup call lsp#register_server({
  399. \ 'name': 'haskell-language-server-wrapper',
  400. \ 'cmd': {server_info->['haskell-language-server-wrapper', '--lsp']},
  401. \ 'whitelist': ['haskell'],
  402. \ })
  403. endif
  404. " Mappings
  405. function! s:on_lsp_buffer_enabled() abort
  406. setlocal omnifunc=lsp#complete
  407. setlocal signcolumn=yes
  408. if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
  409. nmap <buffer> gd <plug>(lsp-definition)
  410. nmap <buffer> gr <plug>(lsp-references)
  411. nmap <buffer> gf <plug>(lsp-code-action)
  412. nmap <buffer> gi <plug>(lsp-implementation)
  413. nmap <buffer> gt <plug>(lsp-type-definition)
  414. " nmap <buffer> <F2> <plug>(lsp-rename)
  415. nmap <buffer> [g <Plug>(lsp-previous-diagnostic)
  416. nmap <buffer> ]g <Plug>(lsp-next-diagnostic)
  417. nmap <buffer> K <plug>(lsp-hover)
  418. xmap <buffer> f <plug>(lsp-document-range-format)
  419. " nmap <buffer> <F5> <plug>(lsp-code-lens)
  420. " buffer format on save
  421. " autocmd BufWritePre <buffer> LspDocumentFormatSync
  422. endfunction
  423. " Decorations
  424. augroup lsp_install
  425. au!
  426. let g:lsp_signs_enabled = 1 " enable signs
  427. let g:lsp_diagnostics_echo_cursor = 1 " enable echo under cursor when in normal mode
  428. let g:lsp_signs_error = {'text': '✗'}
  429. " let g:lsp_signs_warning = {'text': '‼', 'icon': '/path/to/some/icon'} " icons require GUI
  430. " let g:lsp_signs_hint = {'icon': '/path/to/some/other/icon'} " icons require GUI
  431. let g:lsp_signs_warning = {'text': '‼'}
  432. let g:lsp_highlight_references_enabled = 1
  433. highlight link LspErrorText GruvboxRedSign " requires gruvbox
  434. highlight clear LspWarningLine
  435. " highlight lspReference ctermfg=red guifg=red ctermbg=green guibg=green
  436. highlight lspReference guibg=#303010
  437. " call s:on_lsp_buffer_enabled only for languages that has the server registered.
  438. autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
  439. augroup END
  440. "##############################################################################
  441. " Mappings
  442. "##############################################################################
  443. " <Leader> key ----------------------------------------------------------------
  444. " let mapleader = " "
  445. let mapleader = ","
  446. let maplocalleader = "\\"
  447. " Removes highlight of your last search ---------------------------------------
  448. noremap <C-c>h :nohlsearch<CR>
  449. vnoremap <C-c>h :nohlsearch<CR>
  450. inoremap <C-c>h :nohlsearch<CR>
  451. " Bind Ctrl+<movement> keys to move around the windows ------------------------
  452. noremap <C-j> <C-w>j
  453. noremap <C-k> <C-w>k
  454. noremap <C-l> <C-w>l
  455. noremap <C-h> <C-w>h
  456. set splitbelow "новое окно появляется снизу
  457. " Resize windows --------------------------------------------------------------
  458. noremap <Up> :resize +2<CR>
  459. noremap <Down> :resize -2<CR>
  460. noremap <Left> :vertical resize -2<CR>
  461. noremap <Right> :vertical resize +2<CR>
  462. inoremap <Up> <Esc>:resize +2<CR>a
  463. inoremap <Down> <Esc>:resize -2<CR>a
  464. inoremap <Left> <Esc>:vertical resize -2<CR>a
  465. inoremap <Right> <Esc>:vertical resize +2<CR>a
  466. " Switch file encoding --------------------------------------------------------
  467. set wcm=<Tab> "WTF? but all work
  468. menu Encoding.cp1251 :e ++enc=cp1251<CR>
  469. menu Encoding.koi8-r :e ++enc=koi8-r<CR>
  470. menu Encoding.cp866 :e ++enc=cp866<CR>
  471. menu Encoding.utf-8 :e ++enc=utf-8 <CR>
  472. noremap <F11> :emenu Encoding.<TAB>
  473. " Edit & Apply changes in config file -----------------------------------------
  474. nnoremap <Leader>ev :tabnew ~/.config/nvim/init.vim<CR>
  475. nnoremap <Leader>sv :source ~/.config/nvim/init.vim<CR>
  476. " Move line up/down -----------------------------------------------------------
  477. nnoremap <M-k> :m .-2<CR>==
  478. nnoremap <M-j> :m .+1<CR>==
  479. inoremap <M-k> <Esc>:m .-2<CR>==gi
  480. inoremap <M-j> <Esc>:m .+1<CR>==gi
  481. vnoremap <M-k> :m '<-2<CR>gv=gv
  482. vnoremap <M-j> :m '>+1<CR>gv=gv
  483. " Easier moving of code blocks (doesn't lose selection) -----------------------
  484. vnoremap < <gv
  485. vnoremap > >gv
  486. " Execute Python script -------------------------------------------------------
  487. nnoremap <F10> <Esc>:w<CR>:! python3 %<CR>
  488. inoremap <F10> <Esc>:w<CR>:! python3 %<CR>a
  489. " Open, Save, Update & Quit ---------------------------------------------------
  490. nnoremap <C-o> :browse confirm e <CR>
  491. " Close buffer without saving
  492. map <Esc><Esc> :q!<CR>
  493. " Quit all windows without saving
  494. nnoremap <Leader>q :qa!<CR>
  495. " Save
  496. nnoremap <C-s> :w<CR>
  497. inoremap <C-s> <Esc>:w<CR>a
  498. " Tabs ------------------------------------------------------------------------
  499. " Open new tab
  500. nnoremap <Leader>tn :tabnew<CR>
  501. inoremap <Leader>tn <Esc>:tabnew<CR>a
  502. " Switch between tabs
  503. " nnoremap <F8> :tabfirst <CR>
  504. " nnoremap <F9> :tablast <CR>
  505. nnoremap <M-{> :tabfirst <CR>
  506. nnoremap <M-}> :tablast <CR>
  507. nnoremap <M-[> :tabp <CR>
  508. nnoremap <M-]> :tabn <CR>
  509. nnoremap <M-1> 1gt
  510. nnoremap <M-2> 2gt
  511. nnoremap <M-3> 3gt
  512. nnoremap <M-4> 4gt
  513. nnoremap <M-5> 5gt
  514. nnoremap <M-6> 6gt
  515. nnoremap <M-7> 7gt
  516. nnoremap <M-8> 8gt
  517. nnoremap <M-9> 9gt
  518. " Go to BOL and EOL -----------------------------------------------------------
  519. inoremap <M-h> <ESC>0i
  520. inoremap <M-l> <ESC>$a
  521. nnoremap <S-h> 0
  522. nnoremap <S-l> $
  523. " Return from insert mode to normal -------------------------------------------
  524. inoremap jj <ESC>
  525. " inoremap <M-;> <ESC>
  526. " Insert a new line above/below -----------------------------------------------
  527. nnoremap <M-a> O<Esc>
  528. nnoremap <M-Enter> o<Esc>
  529. inoremap <M-a> <Esc>O
  530. inoremap <M-Enter> <Esc>o
  531. " Aligning --------------------------------------------------------------------
  532. " center
  533. " inoremap <C-c>c <Esc>:center<CR>a
  534. " nnoremap <C-c>c :center<CR>
  535. " left
  536. inoremap <C-c>l <Esc>:left<CR>a
  537. nnoremap <C-c>l :left<CR>
  538. " right
  539. inoremap <C-c>r <Esc>:right<CR>a
  540. nnoremap <C-c>r :right<CR>
  541. nnoremap Q <nop>
  542. nnoremap <Enter> <nop>
  543. " Switching colorscheme -------------------------------------------------------
  544. " let g:oeanic_next_terminal_italic = 1
  545. " let g:palenight_terminal_italics=1
  546. " let g:oceanic_italic_comments = 1
  547. " let g:tokyonight_enable_italic = 1
  548. " let g:tokyonight_style = 'night' " available: night, storm
  549. " let g:solarized_termcolors=256
  550. map <F1> :colorscheme OceanicNext<CR>
  551. map <F2> :colorscheme gruvbox<CR>
  552. " map <F3> :colorscheme gruvbox-material<CR>
  553. " map <F4> :colorscheme palenight<CR>
  554. map <F5> :colorscheme tokyonight<CR>
  555. map <F6> :colorscheme ayu<CR>
  556. " map <F7> :colorscheme onedark<CR>
  557. map <F8> :colorscheme darcula<CR>
  558. map <F9> :colorscheme memorycolor<CR>
  559. " map <F9> :colorscheme base16-flat_Cobalt2<CR>
  560. " colorscheme predawn
  561. " colorscheme nord
  562. " colorscheme ayu
  563. " colorscheme oceanicnext
  564. " colorscheme material-theme
  565. " colorscheme onehalfdark
  566. " colorscheme solarized
  567. " colorscheme cobalt2
  568. " Несколько удобных биндингов для с, c++, java, python ------------------------
  569. augroup filetype_coding
  570. autocmd!
  571. au FileType python inoremap :: <END>:<CR>
  572. au FileType python inoremap (: ():<CR>
  573. au FileType python inoremap #ifn if __name__ == "__main__":<CR>
  574. au FileType python inoremap #t # TODO: <Esc>i
  575. au FileType python inoremap #f # FIXME: <Esc>i
  576. " au FileType c,cpp,cc,h,java inoremap {<CR> {<CR>}<Esc>O
  577. " au FileType c,cpp,cc,h,java inoremap #M int main(int argc, char * argv[])<CR>{<CR>return 0;<CR>}<CR><Esc>2kO
  578. " au FileType c,cpp,cc,h,java inoremap #m int main()<CR>{<CR>return 0;<CR>}<CR><Esc>2kO
  579. " au FileType c,cpp,cc,h,java inoremap #d #define
  580. " au FileType c,cpp,cc,h,java inoremap #e #endif /* */<Esc>hhi
  581. " au FileType c,cpp,cc,h,java inoremap #" #include ""<Esc>i
  582. " au FileType c,cpp,cc,h,java inoremap #< #include <><Esc>i
  583. " au FileType c,cpp,cc,h,java inoremap #f /* FIXME: */<Esc>hhi
  584. " au FileType c,cpp,cc,h,java inoremap #t /*TODO: */<Esc>hhi
  585. " au FileType c,cpp,cc,h,java inoremap ;; <END>;<CR>
  586. " au FileType c,cpp,cc,h,java inoremap (; ();<CR>
  587. " au FileType c,cpp,cc,h,java inoremap ({ () {<CR>}<Esc>O
  588. " au FileType c,cpp,cc,h,java inoremap /*<Space> /* */<Esc>3ha
  589. " au FileType c,cpp,cc,h,java inoremap ` <END>;
  590. " au FileType c,cpp,cc,h,java inoremap ' ''<Left>
  591. " au FileType c,cpp,cc,h,java inoremap " ""<Left>
  592. " au FileType c,cpp,cc,h,java inoremap ( ()<Left>
  593. " au FileType c,cpp,cc,h,java inoremap [ []<Left>
  594. " au FileType c,cpp,cc,h,java,python inoremap nl <END><CR>
  595. " au FileType c,cpp,cc,h,java,python inoremap ~ <END>:
  596. augroup END
  597. " Copy/Cut/Past from/to system buffer -----------------------------------------
  598. vnoremap <C-x> "+d
  599. vnoremap <C-c> "*y :let @+=@*<CR>
  600. map <C-p> "+p
  601. " Highlight hex colors toggle -------------------------------------------------
  602. noremap <F12> :ColorToggle<CR>
  603. " Surround the selection in "", '', () ----------------------------------------
  604. " vnoremap <Leader>" <ESC>`<i"<ESC>`>la"<ESC>
  605. " vnoremap <Leader>' <ESC>`<i'<ESC>`>la'<ESC>
  606. " vnoremap <Leader>( <ESC>`<i(<ESC>`>la)<ESC>