" is comma let mapleader = ',' " allow moving cursor just after the last chraracter of the line set virtualedit=onemore set foldmethod=marker " use line C-style comments instead of block ones (/* ... */) set commentstring=//%s " Indentination {{{ function SetIndent(expandtab, shiftwidth) let &l:expandtab = a:expandtab let &l:shiftwidth = str2nr(a:shiftwidth) let &l:tabstop = &shiftwidth let &l:softtabstop = &shiftwidth endfunction command -nargs=1 Indent call SetIndent(1, ) command -nargs=1 IndentTabs call SetIndent(0, ) " use 2 spaces for indentination set expandtab shiftwidth=2 tabstop=2 softtabstop=2 " round indents to multiple of shiftwidth when using shift (< and >) commands set shiftround let g:indentLine_char = "\u2502" let g:indentLine_first_char = g:indentLine_char let g:indentLine_showFirstIndentLevel = 1 let g:indentLine_fileTypeExclude = ['text', 'help', 'tutor', 'man'] augroup vimrc-indentlines-disable autocmd! autocmd TermOpen * IndentLinesDisable " autocmd VimEnter * if bufname('%') == '' | IndentLinesDisable | endif augroup END let g:detectindent_max_lines_to_analyse = 128 let g:detectindent_check_comment_syntax = 1 function s:DetectIndent() if !empty(&bt) | return | endif let g:detectindent_preferred_indent = &l:shiftwidth let g:detectindent_preferred_expandtab = &l:expandtab DetectIndent endfunction augroup vimrc-detect-indent autocmd! autocmd BufReadPost * call s:DetectIndent() augroup END " }}} " Invisible characters {{{ set list let &listchars = "tab:\u2192 ,extends:>,precedes:<,eol:\u00ac,trail:\u00b7" let &showbreak = '>' set display+=uhex " }}} " Cursor and Scrolling {{{ set number relativenumber cursorline " remember cursor position augroup vimrc-editing-remember-cursor-position autocmd! autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exec "normal! g`\"" | endif augroup END " }}} " Wrapping {{{ set nowrap colorcolumn=81,101,121 " }}} " Mappings {{{ " stay in the Visual mode when using shift commands xnoremap < >gv " 2 mappings for quick prototyping: duplicate this line and comment it out nmap ] m'yygccp`'j nmap [ m'yygccP`'k command! -nargs=+ -complete=command PutOutput execute 'put =execute(' . escape(string(), '|"') . ')' " ,c is easier to type than "+ because it doesn't require pressing Shift noremap c "+ " make the default Vim mappings more consistent " https://www.reddit.com/r/vim/comments/dgbr9l/mappings_i_would_change_for_more_consistent_vim/ nmap U nnoremap Y y$ " is treated as in terminals, so the original function of " is inaccessible when something is bound to (buffer switching in my " case). and are basically useless because they are equivalent " to j and k respectively, but now they go to newer or older recorded cursor " position in the jump list. nnoremap nnoremap " Source of this trick: nnoremap Q gq " normal mode nnoremap dg :.diffget nnoremap dp :.diffput " visual mode xnoremap dg :diffget xnoremap dp :diffput " Horizontal scroll " Alt+hjkl and Alt+Arrow - scroll one column/row " Alt+Shift+hjkl - scroll half a page " normal mode nnoremap zh nnoremap zH nnoremap zh nnoremap nnoremap nnoremap nnoremap nnoremap nnoremap nnoremap zl nnoremap zL nnoremap zl " visual mode xnoremap zh xnoremap zH xnoremap zh xnoremap xnoremap xnoremap xnoremap xnoremap xnoremap xnoremap zl xnoremap zL xnoremap zl " }}} " Keymap switcher {{{ nnoremap kk set keymap& nnoremap kr set keymap=russian-jcuken-custom nnoremap ku set keymap=ukrainian-jcuken-custom nnoremap DotfilesSwapKeymaps let g:dotfiles_prev_keymap = &keymap command! -nargs=0 DotfilesSwapKeymaps let [g:dotfiles_prev_keymap, &keymap] = [&keymap, g:dotfiles_prev_keymap] " }}} " Search {{{ " ignore case if the pattern doesn't contain uppercase characters (use '\C' " anywhere in pattern to override these two settings) set ignorecase smartcase nnoremap \ nohlsearch let g:indexed_search_center = 1 " search inside a visual selection xnoremap / /\%>=line("'<")-1l\%<=line("'>")+1l xnoremap ? ?\%>=line("'<")-1l\%<=line("'>")+1l " * and # in the Visual mode will search the selected text function! s:VisualStarSearch(search_cmd) let tmp = @" normal! y let @/ = '\V' . substitute(escape(@", a:search_cmd . '\'), '\n', '\\n', 'g') let @" = tmp endfunction " HACK: my mappings are added on VimEnter to override mappings from the " vim-indexed-search plugin augroup vimrc-editing-visual-star-search autocmd! autocmd VimEnter * \ xmap * call VisualStarSearch('/')n \|xmap # call VisualStarSearch('?')N augroup END " command! -nargs=+ Search let @/ = escape(, '/') | normal // " command! -nargs=+ SearchLiteral let @/ = '\V'.escape(, '/\') | normal // " }}} " Replace {{{ " show the effects of the :substitute command incrementally, as you type " (works similar to 'incsearch') set inccommand=nosplit " quick insertion of the substitution command nnoremap gs :%s///g xnoremap gs :s///g nnoremap gss :%s///g xnoremap gss :s///g " }}} " Formatting {{{ " don't insert a comment after hitting 'o' or 'O' in the Normal mode augroup vimrc-editing-formatting autocmd! autocmd FileType * set formatoptions-=o augroup END " }}} " plugins {{{ let g:delimitMate_expand_space = 1 let g:delimitMate_expand_cr = 1 let g:surround_{char2nr('*')} = "**\r**" let g:pencil#wrapModeDefault = 'soft' let g:pencil#conceallevel = 0 let g:pencil#cursorwrap = 0 xmap ga (LiveEasyAlign) nmap ga (LiveEasyAlign) let g:sneak#prompt = 'sneak> ' map f Sneak_f map F Sneak_F map t Sneak_t map T Sneak_T noremap s s noremap S S " Remove the mappings that I won't use let g:tcomment_maps = 0 " Closely replicate the behavior of tpope/vim-commentary nmap gc TComment_gc nmap gcc TComment_gcc nmap gC TComment_gcb " The default block commenting mapping refuses to work on a single line, as " a workaround I give it another empty one to work with. nmap gCC m'o''TComment_gcb+ xnoremap gc :TCommentMaybeInline xnoremap gC :TCommentBlock " Make an alias for the comment text object omap gc ac " }}} " language-specific settings {{{ let g:rust_recommended_style = 0 let g:haskell_conceal = 0 let g:haskell_conceal_enumerations = 0 let g:haskell_multiline_strings = 1 let g:vim_markdown_conceal = 0 let g:vim_markdown_conceal_code_blocks = 0 let g:vim_markdown_no_default_key_mappings = 0 let g:vala_syntax_folding_enabled = 0 " }}}