" TODO " - Make :Mark optional " - https://github.com/christoomey/vim-sort-motion " - https://github.com/kana/vim-textobj-user/wiki " - https://github.com/kana/vim-textobj-indent " - https://vimawesome.com/plugin/vim-operator-surround " - https://vimawesome.com/?q=fugitive " + Gstatus mapping " - https://github.com/octol/vim-cpp-enhanced-highlight """ README {{{1 """"""""""""""""""""""" "" Post-Git {{{2 " After cloning the root repository " git submodule init " git submodule update --init --recursive pack/*/start " git submodule update --init --recursive pack/*/opt " After upgrading the repository " git submodule sync " git submodule update " git submodule update --init --recursive pack/*/start " " To see empty modules (ZSH globbing) " ls -1d pack/*/*/*(^F) " git submodule update --init --recursive pack/*/opt " " To update submodules to latest origin commits " git submodule foreach 'git fetch; echo "\n\n"' " git submodule foreach 'LANG=C git status | egrep --color=always "(up to date|behind)"; echo -n " "; git branch -r | grep HEAD; echo "\n\n"' " git submodule foreach 'git merge FETCH_HEAD; echo "\n\n"' " To create all doc indexes " :helptags ALL "" Debug {{{2 " To see all loaded VIM scripts " :scriptnames " To only see some of the loaded VIM scripts " :filter /opt/ scriptnames " To edit a script from its number " :script 3 """ Helper functions {{{1 """"""""""""""""""""""" function ToggleFlag(option,flag) exec ('let lopt = &' . a:option) if lopt =~ (".*" . a:flag . ".*") exec ('set ' . a:option . '-=' . a:flag) else exec ('set ' . a:option . '+=' . a:flag) endif endfunction " https://vim.fandom.com/wiki/Faster_loading_of_large_files function! LargeFile() " no syntax highlighting etc set eventignore+=FileType " save memory when other file is viewed setlocal bufhidden=unload " is read-only (write with :w new_filename) setlocal buftype=nowrite " no undo possible setlocal undolevels=-1 " display message autocmd VimEnter * echo "The file is larger than " . (g:LargeFile / 1024 / 1024) . " MB, so some options are changed (see .vimrc for details)." endfunction """ Directories {{{1 """"""""""""""""""""""" if getcwd() == $HOME " Move away from home folder to speed-up call to CtrlP... cd $HOME/tmp endif " ** From the Arch Linux global vimrc ** " Move temporary files to a secure location to protect against CVE-2017-1000382 if exists('$XDG_CACHE_HOME') let &g:directory=$XDG_CACHE_HOME else let &g:directory=$HOME . '/.cache' endif let &g:undodir=&g:directory . '/vim/undo//' let &g:backupdir=&g:directory . '/vim/backup//' let &g:directory.='/vim/swap//' " Create directories if they doesn't exist if ! isdirectory(expand(&g:directory)) silent! call mkdir(expand(&g:directory), 'p', 0700) endif if ! isdirectory(expand(&g:backupdir)) silent! call mkdir(expand(&g:backupdir), 'p', 0700) endif if ! isdirectory(expand(&g:undodir)) silent! call mkdir(expand(&g:undodir), 'p', 0700) endif """ VIM Options {{{1 """"""""""""""""""""""" " Note: Options are sorted as in the :options window " Default settings from Bram {{{2 source $VIMRUNTIME/defaults.vim " Put these in an autocmd group, so that we can delete them easily. augroup vimrcEx au! " For all text files set 'textwidth' to 78 characters. autocmd FileType text setlocal textwidth=78 augroup END " https://vim.fandom.com/wiki/Faster_loading_of_large_files " file is large from 10mb let g:LargeFile = 1024 * 1024 * 10 augroup LargeFile au! autocmd BufReadPre * let f=getfsize(expand("")) | if f > g:LargeFile || f == -2 | call LargeFile() | endif augroup END " 2 - moving around, searching and patterns {{{2 set whichwrap=b,s,<,>,[,] set nowrapscan set ignorecase set smartcase " 4 - displaying text {{{2 set nowrap set list set listchars=tab:→\ ,trail:·,nbsp:˙ set relativenumber set numberwidth=2 " 5 - syntax, highlighting and spelling {{{2 "if has("gui_running") "endif set background=light set hlsearch colorscheme morning highlight Cursor guifg=#000000 guibg=#FF0058 highlight StatusLine guifg=#dd1234 guibg=#ffffff set spell set spelllang=en_gb " 6 - multiple windows {{{2 set hidden set splitright set splitbelow " 9 - using the mouse {{{2 set mousehide " 10 - GUI {{{2 if has("gui_running") " Menu set guioptions-=m map :call ToggleFlag("guioptions","m") " Toolbar set guioptions-=T " No scrollbars set guioptions-=rL set guiheadroom=0 endif " 13 - selecting text {{{2 " set clipboard+=unnamedplus " Doesn't work as expected with Yoink & Subversive " 14 - editing text {{{2 " Flags that tell how automatic formatting works (see help fo-table) " o: Automatically insert the current comment leader after hitting 'o' or 'O' in Normal mode set formatoptions-=o set nrformats+=alpha " 15 - tabs and indenting {{{2 set shiftwidth=2 set expandtab " 16 - folding {{{2 set foldmethod=marker set foldlevel=1 " 19 - reading and writing files {{{2 set backup set undofile " 21 - command line editing {{{2 set wildignore+=*.o " 23 - quickfix {{{2 " External grep " " Tutorial: https://phelipetls.github.io/posts/extending-vim-with-ripgrep/ " if executable("rg") set grepprg=rg\ --vimgrep set grepformat=%f:%l:%c:%m " Quickfix " :gr[ep] " :grepa[dd] " Location " :lgr[ep][!] " Unimpaired shortcuts: " [^Q ]^Q [Q ]Q [q ]q (file/first/previous) " Same with L endif " 26 - various {{{2 set gdefault " use the 'g' flag for ":substitute" """ Key Mapping {{{1 """"""""""""""""""""""" " To test whether a mapping is already used: try the command with no {rhs} " See :map-special-keys, :map-special-chars & " To see all mappings into a buffer: " redir @a | silent nmap | redir END | vnew | put a | let @a="" | sort r /\S\+$/ "" For French AZERTY keyboard {{{2 "" let mapleader="²" " Use with nmap ( [ nmap ) ] omap ( [ omap ) ] xmap ( [ xmap ) ] map è ` map èè `` "" Generic {{{2 "" " Movements map inoremap inoremap inoremap inoremap noremap j gj noremap k gk nmap Q gq$ nmap Y y$ map g :tabclose noremap w W nnoremap :vert help vnoremap y:vert help " nnoremap :tab help vnoremap y:tab help " nnoremap :NERDTree ~/.vim nnoremap :tabedit ~/.vim/vimrc "" External Tools {{{2 "" noremap k :py3f /usr/share/clang/clang-format-14/clang-format.py "" Operator-pending {{{2 " (see Subversive module) " ie = inner entire buffer onoremap ie :exec "normal! ggVG" " iv = current viewable text in the buffer onoremap iv :exec "normal! HVL" " vim-swap package: select "swappable" items omap i, (swap-textobject-i) xmap i, (swap-textobject-i) omap a, (swap-textobject-a) xmap a, (swap-textobject-a) "" Abbreviations {{{2 "" "cabbr %% expand('%:p:h') " Use %:h and learn more! """ File types {{{1 """"""""""""""""""""""" let g:markdown_folding=1 """ Base Packages {{{1 """"""""""""""""""""""" " This section contains packages that extend VIM without changing its basic " behaviour so that an advanced user shouldn't be (too) disappointed. "" CtrlP {{{2 "" "" Full path fuzzy file, buffer, mru, tag, ... finder let g:ctrlp_cmd = 'CtrlPBuffer' let g:ctrlp_prompt_mappings = { 'ToggleMRURelative()': [''] } let g:ctrlp_switch_buffer = 'et' let g:ctrlp_max_depth = 5 " \v === Very Magic let g:ctrlp_custom_ignore = { \ 'dir': '\v\/(build|\.git$)', \ 'file': '\v\.o$' \ } " From Mixed mode, C-F moves to Files & Ctrl-B moves to Buffers let g:ctrlp_types = ['fil', 'mru', 'buf'] " MRU options let g:ctrlp_tilde_homedir = 1 let g:ctrlp_mruf_relative = 0 "" NERDTree {{{2 "" "" File system explorer nnoremap :NERDTreeFocus nnoremap n :NERDTreeFind nnoremap :NERDTreeMirror let NERDTreeChDirMode=2 let NERDTreeNaturalSort=0 let NERDTreeQuitOnOpen=1 let NERDTreeSortOrder=['\/$', '*', '\.swp$', '\~$'] "" Secure Modelines {{{2 "" "" Secure alternative to Vim modelines set nomodeline let g:secure_modelines_verbose=1 let g:secure_modelines_allowed_items = [ \ "list", "nolist", \ "foldlevel", "fdl", \ \ "textwidth", "tw", \ "softtabstop", "sts", \ "tabstop", "ts", \ "shiftwidth", "sw", \ "expandtab", "et", "noexpandtab", "noet", \ "filetype", "ft", \ "foldmethod", "fdm", \ "readonly", "ro", "noreadonly", "noro", \ "rightleft", "rl", "norightleft", "norl", \ "cindent", "cin", "nocindent", "nocin", \ "smartindent", "si", "nosmartindent", "nosi", \ "autoindent", "ai", "noautoindent", "noai", \ "spell", "nospell", \ "spelllang", "spl" \ ] "" Sensible {{{2 "" "" Universal set of defaults "" Repeat {{{2 "" "" Enable repeating supported plugin maps with "." """ Extra Packages {{{1 """"""""""""""""""""""" " This section contains packages that: " - change VIM behaviour (and could mislead an advanced user); " - a user could live without. "" Asterisk {{{2 "" "" Improved star motions map * (asterisk-z*) map g* (asterisk-gz*) map # (asterisk-z#) map g# (asterisk-gz#) " z = don't move "" Cutlass {{{2 "" "" TODO: Check origin repository "" Optional: Redirect all change and delete operations to the black hole register " Forked from https://github.com/svermeulen/vim-cutlass.git " - Removed the "d" mappings from vim-cutlass/autoload/cutlass.vim " since I cannot get used to using an "m" mapping to "cut", " - Changed "x" to behave like "d", without yanking " " Use [Y to "forget" the last cut. packadd! cutlass "" Easymotion {{{2 "" "" Simpler way to use some motions " Use french key "é" as prefix map é (easymotion-prefix) map éé (easymotion-W) let g:EasyMotion_keys = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' " Use Upper J/K to move to line #0 (lower j/k keep cursor in column) let g:EasyMotion_startofline = 0 nmap (easymotion-prefix)z (easymotion-overwin-line) map (easymotion-prefix). (easymotion-repeat) map (easymotion-prefix)" (easymotion-next) map (easymotion-prefix)& (easymotion-prev) "" Mark {{{2 "" packadd! ingo-library nmap * MarkSearchAnyNext nmap # MarkSearchAnyPrev nmap M MarkToggle nmap N MarkConfirmAllClear if &t_Co == 256 || has("gui_running") let g:mwDefaultHighlightingPalette = 'extended' endif " The plugin will create the following mappings if they are not already " assigned to key sequences (and vim will complain when redefining). " " MarkSet ²m " MarkRegex ²r " MarkClear ²n " MarkSearchCurrentNext ²* " MarkSearchCurrentPrev ²# " MarkSearchAnyNext ²/ " MarkSearchAnyPrev ²? " MarkSearchNext * " MarkSearchPrev # nmap IgnoreMark1 MarkClear nmap IgnoreMark2 MarkSearchCurrentNext nmap IgnoreMark3 MarkSearchCurrentPrev nmap IgnoreMark4 MarkSearchNext nmap IgnoreMark5 MarkSearchPrev "" Mundo {{{2 "" "" Allow for removing, changing, and adding surroundings. nnoremap :MundoToggle "" Subversive {{{2 "" "" Optional: Two new operator motions to perform quick substitutions. packadd! subversive " subversive-substitute-motion " Note: Works with yoink plug-in to swap through yanks " Note: This is shadowing the change character key 's' " so you will have to use the longer form 'cl'. " nmap s (SubversiveSubstitute) nmap ss (SubversiveSubstituteLine) nmap S (SubversiveSubstituteToEndOfLine) " Visual mode substitution xmap s (SubversiveSubstitute) " RTFM: subversive-substitute-over-range-motion " For range motion, see vim help: text-objects " See also above in "Key Mapping" — "Operator-pending", in vimrc, " for new substitution ranges. " Current text is saved into register W " Use "w to insert the register content or " use to insert the word under the cursor. " See vim help: cmdline-history, c_CTRL-R & c_CTRL-R_CTRL-W let g:subversiveCurrentTextRegister='w' nmap s (SubversiveSubstituteRange) xmap s (SubversiveSubstituteRange) nmap ss (SubversiveSubstituteWordRange) " subversive-confirming nmap c (SubversiveSubstituteRangeConfirm) xmap c (SubversiveSubstituteRangeConfirm) nmap cc (SubversiveSubstituteWordRangeConfirm) " subversive-abolish-integration nmap S (SubversiveSubvertRange) xmap S (SubversiveSubvertRange) nmap SS (SubversiveSubvertWordRange) "" Surround {{{2 "" "" Allow for removing, changing, and adding surroundings. "" Tabular {{{2 "" "" Optional: Aligning text " packadd! tabular "" Unimpaired {{{2 "" "" Provides several pairs of bracket maps " unimpaired-next next & previous " unimpaired-lines space & exchange " unimpaired-toggling Options [ ] y " unimpaired-encoding encoding & decoding "" Yoink {{{2 "" "" Optional: History of yanks that you can choose between when pasting. packadd! yoink let g:yoinkAutoFormatPaste=0 let g:yoinkIncludeDeleteOperations=1 let g:yoinkMoveCursorToEndOfPaste=1 let g:yoinkSyncSystemClipboardOnFocus=0 " Yank mappings "nmap y (YoinkYankPreserveCursorPosition) "xmap y (YoinkYankPreserveCursorPosition) " Note: Using upper-case Y because lower-case are already used by Unimpaired nmap [Y (YoinkRotateBack) nmap ]Y (YoinkRotateForward) "" Paste mappings nmap p (YoinkPaste_p) nmap P (YoinkPaste_P) nmap (YoinkPostPasteSwapForward) nmap (YoinkPostPasteSwapBack) nmap (YoinkPostPasteToggleFormat) """ Dev Packages {{{1 """"""""""""""""""""""" " This section contains packages that are mostly useful when developing " software -- for basic editing of text files they are overkill. " Doxygen C++ comments " See https://vim.fandom.com/wiki/Continuing_doxygen_comments " " Fold method & initial level autocmd FileType cpp setlocal comments^=:/// foldmethod=syntax foldlevel=2 "" Abolish {{{2 "" "" Find, substitute, and abbreviate several variations of a word at once. " :help abolish-coercion "" ALE {{{2 "" "" Optional: Asynchronous Lint Engine packadd! ale let g:ale_linters = {'sh': ['shellcheck']} let g:ale_linters_explicit=1 "" Commentary {{{2 "" "" C++ {{{2 "" "let g:cpp_function_highlight = 0 "let g:cpp_attributes_highlight = 1 "let g:cpp_member_highlight = 1 "let g:cpp_simple_highlight = 1 "" Direnv {{{2 "" "" Optional: Run direnv's hook appropriately if ! executable('asdf') let $PATH .= ':' .$HOME. '/.asdf/bin' if ! executable('asdf') echo 'Cannot find the asdf executable' endif endif " echo 'asdf is '. exepath('asdf') let g:direnv_cmd = $HOME . '/.asdf/installs/direnv/2.32.1/bin/direnv' packadd! direnv "" FSwitch {{{2 "" "" Switch between companion files of source code let g:fsnonewfiles=1 nnoremap oo :FSHere nnoremap ol :FSRight nnoremap oL :FSSplitRight nnoremap oh :FSLeft nnoremap oH :FSSplitLeft nnoremap ok :FSAbove nnoremap oK :FSSplitAbove nnoremap oj :FSBelow nnoremap oJ :FSSplitBelow augroup fswitch_vimrc au! au BufRead */src/*/src/*.cpp let b:fswitchlocs='reg:!\(src/.*/\)src!\1include!' " ProtoBuf au BufRead *.proto let b:fswitchdst = 'options' | let b:fswitchlocs = '.' " RTmaps " au BufRead *.u/src/*.cpp let b:fswitchlocs='reg:/src/local_interfaces/' " au BufRead *.u/local_interfaces/*.h* let b:fswitchlocs='reg:/local_interfaces/src/' augroup END "" Fugitive {{{2 "" "" Optional: Set of commands defined as a gateway to Git packadd! fugitive "" GitGutter {{{2 "" "" git diff in the 'gutter' (sign column). "" HexDec {{{2 "" "" Optional: Converts numbers under cursor " packadd! hexdex "" Indent Guides {{{2 "" "" Optional: Visually displaying indent levels " packadd! indent-guides " let g:indent_guides_enable_on_vim_startup=1 " let g:indent_guides_guide_size=1 " let g:indent_guides_start_level=2 "" MediaWiki {{{2 "" "" Optional: Syntax highlighter for MediaWiki-based projects "packadd mediawiki.vim "" PlantUML {{{2 "" "" Optional: Plugin for PlantUML syntax packadd plantuml-syntax "" Rooter {{{2 "" "" Changes the working directory to the project root "" Scriptease {{{2 "" "" Optional: Plugin for making/debugging Vim plugins "packadd! scriptease "" Sleuth {{{2 "" "" Automatically adjusts 'shiftwidth' and 'expandtab' heuristically "" Swap {{{2 "" "" Swap delimited items "" Visual Increment {{{2 "" "" Increase and decrease number or letter sequences via visual mode " See also " - https://github.com/nishigori/increment-activator.git " Increment the list that you have defined. " - https://github.com/vim-scripts/VisIncr " Charles Campbell's visual increment plugin "" Vue.js {{{2 "" "" Optional: Syntax Highlight for Vue.js components "packadd! vue "" YouCompleteMe {{{2 "" nnoremap yd :YcmDiags nnoremap yf :YcmCompleterFixIt nnoremap yg :YcmCompleterGoToImprecise nnoremap yG :YcmCompleterGoToReferences nnoremap yR :YcmCompleterRefactorRename nnoremap yy :YcmCompleterGetTypeImprecise nnoremap y= :YcmCompleterGetDocImprecise nnoremap yg :splitYcmCompleterGoToImprecise let g:ycm_always_populate_location_list = 1 let g:ycm_auto_hover = '' let g:ycm_autoclose_preview_window_after_insertion = 0 let g:ycm_complete_in_strings = 0 let g:ycm_error_symbol = '!>' let g:ycm_warning_symbol = ':>' " }}}1 " Tim Pope's sensible.vim is loaded after vimrc. " " vim:ts=50:fdm=marker:foldlevel=1:nolist