#+TITLE: Vim Config :DRAWER: #+PROPERTY: header-args+ :comments none #+PROPERTY: header-args+ :mkdirp yes #+PROPERTY: header-args+ :tangle ~/.vimrc :END: * Plugins Install ** Plug start #+BEGIN_SRC conf call plug#begin('~/.vim/plugged') #+END_SRC ** Manage Files #+BEGIN_SRC conf Plug 'tpope/vim-vinegar' " Combine with netrw to create a delicious salad dressing Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' } " A command-line fuzzy finder written in Go Plug 'junegunn/fzf.vim' " Fzf for vim #+END_SRC ** Text Objects #+BEGIN_SRC conf Plug 'kana/vim-textobj-user' " Create your own text objects Plug 'kana/vim-textobj-line' " Text objects for the current line Plug 'kana/vim-textobj-entire' " Text objects for entire buffer Plug 'michaeljsmith/vim-indent-object' " Defines a new text object representing lines of code at the same indent level Plug 'jiangmiao/auto-pairs' " Vim plugin, insert or delete brackets, parens, quotes in pair #+END_SRC ** Git #+BEGIN_SRC conf Plug 'jreybert/vimagit' Plug 'tpope/vim-fugitive' " A Git wrapper so awesome, it should be illegal Plug 'junegunn/gv.vim' " A git commit browser Plug 'mhinz/vim-signify' " Show a diff using Vim its sign column #+END_SRC ** Motions, Search #+BEGIN_SRC conf Plug 'terryma/vim-expand-region' " Vim plugin that allows you to visually select increasingly larger regions of text using the same key combination Plug 'justinmk/vim-sneak' " The missing motion for Vim Plug 'haya14busa/is.vim' " Improved incremental searching for Vim #+END_SRC ** Manipulate Things #+BEGIN_SRC conf Plug 'tpope/vim-surround' " Quoting/parenthesizing made simple Plug 'tpope/vim-commentary' " Comment stuff out Plug 'junegunn/vim-easy-align' " A Vim alignment plugin Plug 'Olical/vim-enmasse' " Edit every line in a quickfix list at the same time Plug 'mhinz/vim-grepper', { 'on': ['Grepper', '(GrepperOperator)'] } " #+END_SRC ** Utils #+BEGIN_SRC conf Plug 'tpope/vim-repeat' " Enable repeating supported plugin maps with '.' Plug 'tpope/vim-obsession' " Continuously updated session files Plug 'tpope/vim-eunuch' " eunuch.vim: helpers for UNIX Plug 'kana/vim-operator-user' " Define your own operator easily Plug 'majutsushi/tagbar' " Vim plugin that displays tags in a window, ordered by scope Plug 'tpope/vim-speeddating' " use CTRL-A/CTRL-X to increment dates, times, and more Plug 'liuchengxu/vim-which-key' " Vim plugin that shows keybindings in popup #+END_SRC ** Visual #+BEGIN_SRC conf Plug 'itchyny/lightline.vim' " A light and configurable statusline/tabline for Vim Plug 'Yggdroot/indentLine' " A vim plugin to display the indention levels with thin vertical lines Plug 'ryanoasis/vim-devicons' " Adds file type glyphs/icons to many popular Vim plugins such as: NERDTree, vim-airline, unite, vim-startify and many more Plug 'mhinz/vim-startify' " The fancy start screen for Vim Plug 'junegunn/goyo.vim' " Distraction-free writing in Vim #+END_SRC ** Themes #+BEGIN_SRC conf Plug 'morhetz/gruvbox' " Retro groove color scheme for Vim #+END_SRC ** Language Server Protocol #+begin_src conf Plug 'autozimu/LanguageClient-neovim', { \ 'branch': 'next', \ 'do': 'bash install.sh', \ } #+end_src ** Snippnets and autocompletion #+BEGIN_SRC conf Plug 'SirVer/ultisnips' " The ultimate snippet solution for Vim " TODO Alternative https://github.com/Shougo/neosnippet.vim Plug 'honza/vim-snippets' " Vim-snipmate default snippets #+END_SRC ** Syntax Checking and Build Utils #+BEGIN_SRC conf Plug 'neomake/neomake' " Asynchronous linting and make framework for Neovim/Vim #+END_SRC ** Auto Completion #+BEGIN_SRC conf Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } " Dark powered asynchronous completion framework for neovim Plug 'Nelyah/deoplete-mu' " Completion of Contacts using Mu #+END_SRC ** Tmux #+BEGIN_SRC conf Plug 'christoomey/vim-tmux-navigator' " Seamless navigation between tmux panes and vim splits Plug 'jpalardy/vim-slime' " Used to type text into a REPL #+END_SRC ** Syntax #+BEGIN_SRC conf Plug 'sheerun/vim-polyglot' " A solid language pack for Vim #+END_SRC ** Markdown #+BEGIN_SRC conf Plug 'plasticboy/vim-markdown', { 'for': 'markdown' } " Markdown Vim Mode Plug 'mzlogin/vim-markdown-toc', { 'for': 'markdown' } " A vim plugin to generate table of contents for Markdown files Plug 'JamshedVesuna/vim-markdown-preview', { 'for': 'markdown' } " A light Vim plugin for previewing markdown files in a browser Plug 'nelstrom/vim-markdown-folding' " Fold markdown documents by section #+END_SRC ** LaTeX #+BEGIN_SRC conf Plug 'lervag/vimtex', { 'for': 'tex' } " A modern vim plugin for editing LaTeX files. #+END_SRC ** Matlab #+BEGIN_SRC conf Plug 'tdehaeze/matlab-vim', { 'for': 'matlab' } " Edit Matlab M-files in Vim editor Plug 'djoshea/vim-matlab-fold', { 'for': 'matlab' } " Vim code folding for Matlab files #+END_SRC ** Org Mode #+BEGIN_SRC conf Plug 'jceb/vim-orgmode' " Text outlining and task management for Vim Plug 'vim-scripts/SyntaxRange' " Define a different filetype syntax on regions of a buffer Plug 'chrisbra/NrrwRgn' " A Narrow Region Plugin for vim Plug 'mattn/calendar-vim' " calendar vimscript Plug 'vim-scripts/utl.vim' " Univeral Text Linking - Execute URLs, footnotes, open emails, organize ideas #+END_SRC ** Others / To test #+BEGIN_SRC conf " Plug 'francoiscabrol/ranger.vim' " Ranger integration in vim and neovim " Plug 'brooth/far.vim' " Find And Replace Vim plugin " Plug 'justinmk/vim-gtfo' " Go to Terminal or File manager " Plug 'sjl/gundo.vim', { 'on': 'GundoToggle' } " Vim plugin to visualize your Vim undo tree " Plug 'drzel/vim-line-no-indicator' " Simple and expressive line number indicator #+END_SRC ** Plug End #+BEGIN_SRC conf call plug#end() #+END_SRC * Basic ** General #+BEGIN_SRC conf set runtimepath+=~/.vim " Sets how many lines of history VIM has to remember set history=500 " Enable filetype plugins filetype plugin on filetype indent on " Set to auto read when a file is changed from the outside set autoread " writes the content of the file automatically if you call :make set autowrite " Share clipboard with system set clipboard+=unnamedplus " Define Leader Key as Space key let mapleader = "\" let g:mapleader = "\" let maplocalleader = "," #+END_SRC ** VIM user interface #+BEGIN_SRC conf " Set 7 lines to the cursor - when moving vertically using j/k set so=7 " Avoid garbled characters in Chinese language windows OS let $LANG='en' set langmenu=en " Set Timeout config set timeout set ttimeout set timeoutlen=500 set ttimeoutlen=50 " Turn on the wild menu set wildmenu " Ignore compiled files set wildignore=*.o,*~,*.pyc if has("win16") || has("win32") set wildignore+=.git\*,.hg\*,.svn\* else set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store endif set wildmode=full "Always show current position set ruler " Height of the command bar set cmdheight=1 " A buffer becomes hidden when it is abandoned set hid " Configure backspace so it acts as it should act set backspace=eol,start,indent set whichwrap+=<,>,h,l " Ignore case when searching set ignorecase " When searching try to be smart about cases set smartcase " Option for smarter completions that will be case aware set infercase " Highlight search results set hlsearch " Makes search act like search in modern browsers set incsearch " Don't redraw while executing macros (good performance config) set lazyredraw " For regular expressions turn magic on set magic " Show matching brackets when text indicator is over them set showmatch " Don't show tab line if there is only one tab set showtabline=1 " How tany tenths of a second to blink when matching brackets set mat=2 " No annoying sound on errors set noerrorbells set novisualbell set t_vb= set tm=500 " Add a bit extra margin to the left set foldcolumn=0 " Improve VIM scrolling set ttyfast " Relative Numbers set relativenumber " Smarter J and K navigation nnoremap j v:count ? (v:count > 5 ? "m'" . v:count : '') . 'j' : 'gj' nnoremap k v:count ? (v:count > 5 ? "m'" . v:count : '') . 'k' : 'gk' " Splits open at the bottom and right, which is non-retarded, unlike vim defaults. set splitbelow splitright #+END_SRC ** Foldings #+BEGIN_SRC conf if has('folding') if has('windows') let &fillchars='vert: ' " less cluttered vertical window separators endif set foldmethod=indent " not as cool as syntax, but faster set foldlevelstart=99 " start unfolded endif #+END_SRC ** Colors and Fonts #+BEGIN_SRC conf syntax enable set background=dark let base16colorspace=256 let g:gruvbox_contrast_dark = 'soft' try colorscheme gruvbox catch endtry " set cursor shapes for insert and replace modes set guicursor=n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20 " Set utf8 as standard encoding set encoding=utf-8 set fileencoding=utf-8 " Use Unix as the standard file type set ffs=unix,dos,mac " Do not highlight the cursor line : http://vim.wikia.com/wiki/Highlight_current_line set nocursorline set nocursorcolumn " Always show the status line set laststatus=2 " Underline for bad spelled words hi clear SpellBad hi SpellBad cterm=underline " Set style for gVim hi SpellBad gui=undercurl #+END_SRC ** Files, backups and undo #+BEGIN_SRC conf " Turn backup off, since most stuff is in SVN, git et.c anyway... set nobackup set nowb set noswapfile #+END_SRC ** Text, tab and indent related #+BEGIN_SRC conf " Use spaces instead of tabs set expandtab " Be smart when using tabs set smarttab " 1 tab == 4 spaces set shiftwidth=4 set tabstop=4 " Word wrap without line breaks set wrap set linebreak set nolist " list disables linebreak set autoindent " Auto Indentation set nosmartindent " No Smart Indentation #+END_SRC ** Moving around, tabs, windows and buffers #+BEGIN_SRC conf " Specify the behavior when switching between buffers try set switchbuf=useopen,usetab catch endtry " Return to last edit position when opening files (You want this!) au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif set splitbelow set splitright " This enables mouse in all modes set mouse=a " Automatically equalize splits when Vim is resized autocmd VimResized * wincmd = #+END_SRC ** Misc #+BEGIN_SRC conf " Enable Line Number set number " Speed up cursor movments : http://superuser.com/a/625994/587300 set regexpengine=1 " https://github.com/xolox/vim-easytags/issues/88 " Set the maximum column for syntax highlighting set synmaxcol=250 #+END_SRC ** Helper functions #+BEGIN_SRC conf function! CmdLine(str) exe "menu Foo.Bar :" . a:str emenu Foo.Bar unmenu Foo endfunction function! VisualSelection(direction, extra_filter) range let l:saved_reg = @" execute "normal! vgvy" let l:pattern = escape(@", '\\/.*$^~[]') let l:pattern = substitute(l:pattern, "\n$", "", "") if a:direction == 'gv' call CmdLine("Ag \"" . l:pattern . "\" " ) elseif a:direction == 'replace' call CmdLine("%s" . '/'. l:pattern . '/') endif let @/ = l:pattern let @" = l:saved_reg endfunction " Don't close window, when deleting a buffer command! Bclose call BufcloseCloseIt() function! BufcloseCloseIt() let l:currentBufNum = bufnr("%") let l:alternateBufNum = bufnr("#") if buflisted(l:alternateBufNum) buffer # else bnext endif if bufnr("%") == l:currentBufNum new endif if buflisted(l:currentBufNum) execute("bdelete! ".l:currentBufNum) endif endfunction #+END_SRC ** GUI related #+BEGIN_SRC conf set guifont=Hack\ Nerd\ Font\ Mono:h13 set gfn=Hack\ Nerd\ Font\ Mono:h13 " Disable scrollbars set guioptions-=r set guioptions-=R set guioptions-=l set guioptions-=L #+END_SRC ** Turn persistent undo on #+BEGIN_SRC conf try set undodir=~/.vim_runtime/temp_dirs/undodir set undofile catch endtry #+END_SRC * Mappings ** Normal mode related #+BEGIN_SRC conf " Smart way to move between windows noremap j noremap k noremap h noremap l #+END_SRC ** Insert mode related #+BEGIN_SRC conf " Paste while in insert mode inoremap * " Go to the end of line inoremap A " Go to the beginning of line inoremap I #+END_SRC ** Visual mode related #+BEGIN_SRC conf " Visual mode pressing / or ? searches for the current selection vnoremap / :call VisualSelection('', '')/=@/ vnoremap ? :call VisualSelection('', '')?=@/ " Re-select visual block after indenting vnoremap < >gv " Move visual block vnoremap J :m '>+1gv=gv vnoremap K :m '<-2gv=gv #+END_SRC ** Add some delimiters #+BEGIN_SRC conf " use $ as a delimiter xnoremap i$ :normal! T$vt$ xnoremap a$ :normal! T$hvt$l onoremap i$ :normal vi$ onoremap a$ :normal va$ #+END_SRC ** Command mode related #+BEGIN_SRC conf " Bash like keys for the command line cnoremap cnoremap cnoremap cnoremap cnoremap #+END_SRC ** Terminal mode related #+BEGIN_SRC conf " tnoremap tnoremap h h tnoremap j j tnoremap k k tnoremap l l #+END_SRC ** Correct misspelled works Taken from: https://vi.stackexchange.com/questions/68/autocorrect-spelling-mistakes #+BEGIN_SRC conf " Go back to last misspelled word and pick first suggestion. inoremap u[s1z=`]au " Select last misspelled word (typing will edit). nnoremap [sve inoremap [sve snoremap b[sviw #+END_SRC * Filetypes ** Vim Which Key #+BEGIN_SRC conf nnoremap :WhichKey ',' let g:which_key_map_local = {} #+END_SRC ** Mails #+begin_src conf autocmd FileType mail set spell spelllang=en_us,fr #+end_src ** MarkDown #+BEGIN_SRC conf " Automatically turn on spell-checking for Markdown files au BufRead,BufNewFile *.md setlocal spell spelllang=fr,en #+END_SRC ** LaTeX #+BEGIN_SRC conf " TODO : améliorer ça au BufRead,BufNewFile *.tikz set filetype=tex let tex_no_error=1 " TODO: used to not highlight underscores au BufRead,BufNewFile *.tex set filetype=tex au BufRead,BufNewFile *.tex let b:AutoPairs={'(':')', '[':']', '{':'}',"'":"'",'"':'"', '`':'`', '$':'$'} au BufRead,BufNewFile *.tex set iskeyword+=- " " clear the current list of matches that cause error-highlighting " syn clear texOnlyMath " " still mark '^' as an error outside of math mode " syn match texOnlyMath /[\^]/ " autocmd FileType tex,tikz nnoremap lt (vimtex-toc-toggle) " autocmd FileType tex,tikz nnoremap ll (vimtex-labels-open) " autocmd FileType tex,tikz nnoremap lv (vimtex-view) " autocmd FileType tex,tikz nnoremap lf (vimtex-reverse-search) " " Make Tikz " nnoremap mt :Make pdf t=tikz f=%:t:r " nnoremap mto :make open t=tikz f=%:t:r " " Make LaTeX " nnoremap ml :Make pdf f=%:t:r " nnoremap mlo :make open f=%:t:r #+END_SRC ** Arduino #+BEGIN_SRC conf au BufRead,BufNewFile *.pde set filetype=arduino au BufRead,BufNewFile *.ino set filetype=arduino " au FileType arduino map ac :!platformio run " au FileType arduino map au :!platformio run -s --target=upload " au FileType arduino map am :!platformio serialports monitor --port=/dev/cu #+END_SRC ** Python #+BEGIN_SRC conf let g:slime_python_ipython = 1 au FileType python setlocal expandtab au FileType python setlocal tabstop=4 au FileType python setlocal shiftwidth=4 " Run Section au FileType python nmap SlimeParagraphSend " Run Selected text au FileType python vmap SlimeRegionSend " CD to directory of current file " TODO - Should enter the command. This just output the command without runing " it... au FileType python nmap c :SlimeSend0('cd '.expand('%:p:h')) " let python_highlight_all = 1 " au FileType python syn keyword pythonDecorator True None False self " au BufNewFile,BufRead *.jinja set syntax=htmljinja " au BufNewFile,BufRead *.mako set ft=mako " au FileType python map F :set foldmethod=indent " au FileType python inoremap $r return " au FileType python inoremap $i import " au FileType python inoremap $p print " au FileType python inoremap $f #--- a " au FileType python map 1 /class " au FileType python map 2 /def " au FileType python map C ?class " au FileType python map D ?def #+END_SRC ** Matlab #+BEGIN_SRC conf " TODO Run Section (delimited by %%) au FileType matlab nmap mm SlimeParagraphSend let g:which_key_map_local.m = { 'name' : '+matlab' } " Run either Selected text au FileType matlab vmap mm SlimeRegionSend let g:which_key_map_local.mm = 'run-code' func! GetSelectedText() normal gv"xy let result = getreg("x") normal gv return result endfunc " Help on the current selection au FileType matlab vmap mh :SlimeSend0('help '.expand(GetSelectedText())) let g:which_key_map_local.mh = 'help' " Documentation on the current selection au FileType matlab vmap mH :SlimeSend0('doc '.expand(GetSelectedText())) let g:which_key_map_local.mh = 'help' " Open the current file in the Matlab Editor (usefull for debuging) au FileType matlab nmap me :SlimeSend0('edit '.expand('%:p')) let g:which_key_map_local.me = 'edit-gui' " Run all the file au FileType matlab nmap mr :SlimeSend0('run '.expand('%:t')) let g:which_key_map_local.mr = 'run-file' " Send "cd filepath" to matlab au FileType matlab nmap mc :SlimeSend0('cd '.expand('%:p:h')) let g:which_key_map_local.mr = 'cd-file' " Open workspace au FileType matlab nmap mw :SlimeSend0('workspace') let g:which_key_map_local.mr = 'workspace' #+END_SRC ** Sage #+BEGIN_SRC conf " TODO Run Section au FileType sage.python nmap SlimeParagraphSend " Run Selected text au FileType sage.python vmap SlimeRegionSend #+END_SRC ** Save Which Key Configuration #+BEGIN_SRC conf call which_key#register(',', "g:which_key_map_local") #+END_SRC * Plugins Config ** junegunn/fzf #+BEGIN_SRC conf " This is the default extra key bindings let g:fzf_action = { \ 'ctrl-t': 'tab split', \ 'ctrl-h': 'split', \ 'ctrl-v': 'vsplit' } " [[B]Commits] Customize the options used by 'git log': let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"' let g:fzf_colors = \ { 'fg': ['fg', 'Normal'], \ 'bg': ['bg', 'Normal'], \ 'hl': ['fg', 'Comment'], \ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'], \ 'bg+': ['bg', 'CursorLine', 'CursorColumn'], \ 'hl+': ['fg', 'Statement'], \ 'info': ['fg', 'PreProc'], \ 'prompt': ['fg', 'Conditional'], \ 'pointer': ['fg', 'Exception'], \ 'marker': ['fg', 'Keyword'], \ 'spinner': ['fg', 'Label'], \ 'header': ['fg', 'Comment'] } function! s:fzf_statusline() " Override statusline as you like highlight fzf1 ctermfg=161 ctermbg=251 highlight fzf2 ctermfg=23 ctermbg=251 highlight fzf3 ctermfg=237 ctermbg=251 setlocal statusline=%#fzf1#\ >\ %#fzf2#fz%#fzf3#f endfunction autocmd! User FzfStatusLine call fzf_statusline() #+END_SRC ** autozimu/LanguageClient-neovim #+begin_src conf let g:LanguageClient_serverCommands = { \ 'matlab': ['java', ' -Djava.library.path=$MATLABROOT/bin/glnxa64 -cp $MATLABROOT/extern/engines/java/jar/engine.jar:$MATLABROOT/java/jar/jmi.jar:/home/thomas/github/matlab-langserver/build/libs/lsp-matlab-0.1.jar org.tokor.lspmatlab.Application'], \ } nnoremap :call LanguageClient_contextMenu() " Or map each action separately nnoremap K :call LanguageClient#textDocument_hover() nnoremap gd :call LanguageClient#textDocument_definition() nnoremap :call LanguageClient#textDocument_rename() #+end_src ** JamshedVesuna/vim-markdown-preview #+BEGIN_SRC conf let vim_markdown_preview_github=1 let vim_markdown_preview_browser='Google Chrome' let vim_markdown_preview_temp_file=1 " let vim_markdown_preview_pandoc=1 #+END_SRC ** mhinz/vim-signify #+BEGIN_SRC conf let g:signify_vcs_list = ['git'] let g:signify_disable_by_default = 1 #+END_SRC ** Deoplete #+BEGIN_SRC conf let g:deoplete#enable_at_startup = 1 " let g:deoplete#omni#functions = {} " set completeopt=longest,menuone,preview " let g:deoplete#sources = {} " let g:deoplete#enable_smart_case = 1 " call deoplete#custom#set('ultisnips', 'matchers', ['matcher_fuzzy']) #+END_SRC ** SirVer/ultisnips #+BEGIN_SRC conf let g:UltiSnipsSnippetsDir = '~/.vim/UltiSnip' " inoremap pumvisible() ? "\" : "\" let g:UltiSnipsExpandTrigger="" " let g:UltiSnipsJumpForwardTrigger="" " let g:UltiSnipsJumpBackwardTrigger="" #+END_SRC ** honza/vim-snippets #+BEGIN_SRC conf let g:snipMate = {} let g:snipMate.scope_aliases = {} #+END_SRC ** itchyny/lightline.vim #+BEGIN_SRC conf function! LightlineObsession() return '%{ObsessionStatus("")}' endfunction " \ 'colorscheme': 'gruvbox', let g:lightline = { \ 'colorscheme': 'solarized', \ 'active': { \ 'left': [ [ 'mode', 'paste' ], \ [ 'filename', 'modified', 'fugitive', 'obsession' ] ] \ }, \ 'component': { \ 'fugitive': '%{exists("*fugitive#head")?fugitive#head():""}' \ }, \ 'component_expand': { \ 'obsession': 'LightlineObsession' \ }, \ 'component_visible_condition': { \ 'fugitive': '(exists("*fugitive#head") && ""!=fugitive#head())' \ }, \ 'separator': { 'left': '', 'right': '' }, \ 'subseparator': { 'left': "|", 'right': "|" } \ } #+END_SRC ** Autopairs #+BEGIN_SRC conf " Incompatibilité entre auto-pairs et clang-complete let g:AutoPairsMapCR = 0 imap AutoPairsReturn #+END_SRC ** Yggdroot/indentLine #+BEGIN_SRC conf " :IndentLinesToggle toggles lines on and off. let g:indentLine_color_term = 239 #+END_SRC ** ryanoasis/vim-devicons #+BEGIN_SRC conf let g:webdevicons_enable_ctrlp = 1 #+END_SRC ** junegunn/goyo.vim #+BEGIN_SRC conf let g:goyo_width=100 let g:goyo_margin_top = 2 let g:goyo_margin_bottom = 2 #+END_SRC This is for soft line breaks #+BEGIN_SRC conf function! s:goyo_enter() set wrap linebreak nolist textwidth=0 wrapmargin=0 let b:quitting = 0 let b:quitting_bang = 0 autocmd QuitPre let b:quitting = 1 cabbrev q! let b:quitting_bang = 1 q! endfunction #+END_SRC Quit Vim if this is the only remaining buffer #+BEGIN_SRC conf function! s:goyo_leave() if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1 if b:quitting_bang qa! else qa endif endif endfunction #+END_SRC #+BEGIN_SRC conf autocmd! User GoyoEnter call goyo_enter() autocmd! User GoyoLeave call goyo_leave() #+END_SRC ** tpope/vim-surround #+BEGIN_SRC conf vmap Si S(i_f) au FileType mako vmap Si S"i${ _(2f"a) } " surroung un visual mode : use S, then b to make the text bold in markdown let g:surround_{char2nr('b')} = "__\r__" #+END_SRC ** Vim-Markdown #+BEGIN_SRC conf let g:vim_markdown_folding_disabled = 1 let g:vim_markdown_conceal = 0 let g:vim_markdown_toc_autofit = 1 let g:vim_markdown_toml_frontmatter = 1 let g:tex_conceal = "" #+END_SRC ** Neomake #+BEGIN_SRC conf " Latex autocmd! BufWritePost *.tex Neomake let g:neomake_tex_chktex_maker = { \ 'exe': 'chktex', \ 'args': ['--inputfiles'], \ 'errorformat': \ '%EError %n in %f line %l: %m,' . \ '%WWarning %n in %f line %l: %m,' . \ '%WMessage %n in %f line %l: %m,' . \ '%Z%p^,' . \ '%-G%.%#' \ } let g:neomake_tex_enabled_makers = ['chktex'] " Matlab autocmd! BufWritePost *.m Neomake let g:neomake_matlab_mlint_maker = { \ 'exe': 'mlint', \ 'mapexpr': "neomake_bufname.':'.v:val", \ 'errorformat': \ '%f:L %l (C %c): %m,' . \ '%f:L %l (C %c-%*[0-9]): %m,', \ } let g:neomake_matlab_enabled_makers = ['mlint'] #+END_SRC ** lervag/vimtex #+BEGIN_SRC conf " let g:tex_conceal="" " autocmd FileType tex let b:vimtex_main = 'main.tex' " let g:vimtex_mappings_enabled=0 #+END_SRC ** jpalardy/vim-slime #+BEGIN_SRC conf if exists('$TMUX') let g:slime_target = "tmux" let g:slime_default_config = {"socket_name": split($TMUX, ",")[0], "target_pane": ":.2"} let g:slime_dont_ask_default = 1 endif #+END_SRC ** mhinz/vim-grepper #+BEGIN_SRC conf " nnoremap G :Grepper -tool ag " nmap gs (GrepperOperator) " xmap gs (GrepperOperator) #+END_SRC ** Editor config #+BEGIN_SRC conf " To ensure that this plugin works well with Tim Pope's fugitive, use the following patterns array: let g:EditorConfig_exclude_patterns = ['fugitive://.*'] #+END_SRC ** Polyglot #+BEGIN_SRC conf let g:polyglot_disabled = ['latex'] #+END_SRC * Bindings ** Vim Which Key #+BEGIN_SRC conf nnoremap :WhichKey '' let g:which_key_map = {} #+END_SRC ** Direct ones #+BEGIN_SRC conf " Switch with last buffer nnoremap :e # " let g:which_key_map. = 'last-buffer' #+END_SRC ** Quit #+BEGIN_SRC conf let g:which_key_map.q = { 'name' : '+quit' } " Quit nnoremap qq :qa let g:which_key_map.q.q = 'quit' " Quit - Force nnoremap qQ :qa! let g:which_key_map.q.Q = 'quit-force' " Quit - Save nnoremap qw :wq let g:which_key_map.q.w = 'quit-save' " Quit - Save all nnoremap qW :wqa let g:which_key_map.q.W = 'quit-save-all' #+END_SRC ** Files #+BEGIN_SRC conf let g:which_key_map.f = { 'name' : '+files' } " Fast saving nnoremap fs :w! let g:which_key_map.f.s = 'save-file' " Fast saving all nnoremap fS :wa! let g:which_key_map.f.S = 'save-all' " Find Files noremap ff :Files let g:which_key_map.f.f = 'find-file' " Find File corresping to Word nnoremap fw \ :call fzf#vim#files('.', fzf#vim#with_preview({'options': ['--query', expand('')]})) " TODO - Add visual keymap " vnoremap fw " \ :call fzf#vim#files('.', fzf#vim#with_preview({'options': ['--query', 0]})) let g:which_key_map.f.w = 'find-file-word' #+END_SRC ** Buffers #+BEGIN_SRC conf let g:which_key_map.b = { 'name' : '+buffers' } " Buffer Create noremap bc :enew let g:which_key_map.b.c = 'buffer-create' " Buffer Delete noremap bd :Bclose let g:which_key_map.b.d = 'buffer-delete' " Buffer Delete all others noremap bD :bufdo bd let g:which_key_map.b.D = 'buffer-delete-others' " Buffer Next noremap bn :bnext let g:which_key_map.b.n = 'buffer-next' " Buffer Previous noremap bp :bprevious let g:which_key_map.b.p = 'buffer-previous' " Find Buffers noremap bf :Buffers let g:which_key_map.b.f = 'buffer-find' " Buffer Home (startify) noremap bh :Startify let g:which_key_map.b.h = 'buffer-home' " CD to buffer path noremap bw :cd %:p:h:pwd let g:which_key_map.b.w = 'buffer-pwd' #+END_SRC ** Tabs #+BEGIN_SRC conf let g:which_key_map.t = { 'name' : '+tabs' } " Let 'tt' toggle between this and the last accessed tab let g:lasttab = 1 au TabLeave * let g:lasttab = tabpagenr() " Tab New nnoremap tc :tabnew let g:which_key_map.t.c = 'tab-create' " Tab Delete nnoremap td :tabclose let g:which_key_map.t.d = 'tab-delete' " Tab Maximize nnoremap tD :tabonly let g:which_key_map.t.D = 'tab-delete-others' " Tab Left nnoremap th gt let g:which_key_map.t.h = 'tab-left' " Tab Right nnoremap tl gT let g:which_key_map.t.l = 'tab-right' " Tab Move Left nnoremap tH :tabmove -1 let g:which_key_map.t.H = 'tab-move-left' " Tab Move Right nnoremap tL :tabmove +1 let g:which_key_map.t.L = 'tab-move-right' " Tab Toggle nnoremap tt :exe "tabn ".g:lasttab let g:which_key_map.t.t = 'tab-toggle' #+END_SRC ** Terminals #+BEGIN_SRC conf let g:which_key_map.T = { 'name' : '+terminals' } " Quickly create a new terminal in a new tab nnoremap Tc :tab new:term let g:which_key_map.T.c = 'term-create' " Quickly create a new terminal in a vertical split nnoremap T/ :vsplit:term " let g:which_key_map.T./ = 'term-vert' " Quickly create a new terminal in a horizontal split nnoremap T- :split:term " let g:which_key_map.T.- = 'term-hor' #+END_SRC ** Splits / Windows #+BEGIN_SRC conf let g:which_key_map.w = { 'name' : '+windows' } " Split Horizontal nnoremap w- :split " let g:which_key_map.w.- = 'win-hor' " Split Vertical nnoremap w/ :vsplit " let g:which_key_map.w./ = 'win-vert' " Split Maximize nnoremap wD o let g:which_key_map.w.D = 'win-delete-others' " Split Delete nnoremap wd q let g:which_key_map.w.d = 'win-delete' " Split Go Left nnoremap wh :wincmd h let g:which_key_map.w.h = 'win-left' " Split Go Down nnoremap wj :wincmd j let g:which_key_map.w.j = 'win-down' " Split Go Up nnoremap wk :wincmd k let g:which_key_map.w.k = 'win-up' " Split Go Right nnoremap wl :wincmd l let g:which_key_map.w.l = 'win-right' " Split to Tab nnoremap wt T let g:which_key_map.w.t = 'win-make-tab' " Find window nnoremap wf :Windows let g:which_key_map.w.f = 'win-find' " Maximize window nnoremap wm :call MaximizeToggle() let g:which_key_map.w.m = 'win-maximize' function! MaximizeToggle() if exists("s:maximize_session") exec "source " . s:maximize_session call delete(s:maximize_session) unlet s:maximize_session let &hidden=s:maximize_hidden_save unlet s:maximize_hidden_save else let s:maximize_hidden_save = &hidden let s:maximize_session = tempname() set hidden exec "mksession! " . s:maximize_session only endif endfunction #+END_SRC ** Check Spell #+BEGIN_SRC conf let g:which_key_map.S = { 'name' : '+spell-check' } " CheckSpell Toggle noremap St :setlocal spell! let g:which_key_map.S.t = 'spell-toggle' " CheckSpell Correct noremap Sc z= let g:which_key_map.S.c = 'spell-correct' " CheckSpell Do first noremap SC 1z= let g:which_key_map.S.C = 'spell-correct-first' " CheckSpell Language noremap Sl :set spelllang= let g:which_key_map.S.l = 'spell-language' " CheckSpell Next noremap Sn ]s let g:which_key_map.S.n = 'spell-next' " CheckSpell Next and correct noremap SN ]s1z= let g:which_key_map.S.N = 'spell-next-correct' " CheckSpell Previous noremap Sp [s let g:which_key_map.S.p = 'spell-prev' " CheckSpell Previous and correct noremap SP [s1z= let g:which_key_map.S.P = 'spell-prev-correct' " CheckSpell Add to dictionnary noremap Sa zg let g:which_key_map.S.a = 'spell-add-dict' #+END_SRC ** Make #+BEGIN_SRC conf let g:which_key_map.m = { 'name' : '+make' } " Make Make nnoremap mm :Make -B let g:which_key_map.m.m = 'make' " Make Clean nnoremap mc :Make clean let g:which_key_map.m.c = 'make-clean' " Make Force nnoremap mf :Make! -B let g:which_key_map.m.f = 'make-force' " Make Run nnoremap mr :Make! run let g:which_key_map.m.r = 'make-run' " Make Open nnoremap mo :make! open let g:which_key_map.m.o = 'make-open' #+END_SRC ** Search #+BEGIN_SRC conf let g:which_key_map.s = { 'name' : '+search' } " Search History noremap sh :History let g:which_key_map.s.h = 'search-history' " Search Tags noremap sT :Tags let g:which_key_map.s.T = 'search-tags' " Search All noremap sa :Rg let g:which_key_map.s.g = 'search-all' " Search Word noremap sw :exe ':Rg ' . expand('') let g:which_key_map.s.w = 'search-word' " Search todo keyboard " TODO - should not have to press enter nnoremap st :Grepper -tool rg -query TODO let g:which_key_map.s.t = 'search-todos' #+END_SRC ** TODO - GIT #+BEGIN_SRC conf let g:which_key_map.g = { 'name' : '+git' } " Git Gutter nnoremap gg :SignifyToggle let g:which_key_map.g.g = 'git-' " Git Gutter Highlight nnoremap gG :SignifyToggleHighlight let g:which_key_map.g.G = 'git-' " Git Commit nnoremap gc :Gcommit let g:which_key_map.g.c = 'git-commit' " Git Status nnoremap gs :Gstatus let g:which_key_map.g.s = 'git-status' " Git Diff nnoremap gd :Gdiff let g:which_key_map.g.d = 'git-diff' " Git Blame nnoremap gb :Gblame let g:which_key_map.g.b = 'git-blame' " Git Visualise nnoremap gv :GV let g:which_key_map.g.v = 'git-visualize' " Git File (visualise) nnoremap gF :GV! let g:which_key_map.g.F = 'git-file' " Git Find Commits noremap gf :Commits let g:which_key_map.g.f = 'git-find-commit' #+END_SRC ** Errors #+BEGIN_SRC conf let g:which_key_map.e = { 'name' : '+errors' } function! s:GetBufferList() redir =>buflist silent! ls redir END return buflist endfunction function! ToggleLocationList() let curbufnr = winbufnr(0) for bufnum in map(filter(split(s:GetBufferList(), '\n'), 'v:val =~ "Location List"'), 'str2nr(matchstr(v:val, "\\d\\+"))') if curbufnr == bufnum lclose return endif endfor let winnr = winnr() let prevwinnr = winnr("#") let nextbufnr = winbufnr(winnr + 1) try lopen catch /E776/ echohl ErrorMsg echo "Location List is Empty." echohl None return endtry if winbufnr(0) == nextbufnr lclose if prevwinnr > winnr let prevwinnr-=1 endif else if prevwinnr > winnr let prevwinnr+=1 endif endif " restore previous window exec prevwinnr."wincmd w" exec winnr."wincmd w" endfunction " Error Toggle nnoremap ee :call ToggleLocationList() let g:which_key_map.e.e = 'error-toggle' " Error Open nnoremap eo :lopen let g:which_key_map.e.o = 'error-open' " Error Close nnoremap ec :lclose let g:which_key_map.e.c = 'error-close' " Error Next nnoremap en :lnext let g:which_key_map.e.n = 'error-next' " Error Previous nnoremap ep :lprevious let g:which_key_map.e.p = 'error-previous' #+END_SRC ** Text #+BEGIN_SRC conf let g:which_key_map.x = { 'name' : '+text' } " Start interactive EasyAlign in visual mode (e.g. vipga) and for a motion xmap xa (EasyAlign) nmap xa (EasyAlign) let g:which_key_map.x.a = 'text-align' " Indent all file nnoremap x= mzgg=G`z " let g:which_key_map.x.= = 'text-indent-file' " Custom Multiple Cursor " http://www.kevinli.co/posts/2017-01-19-multiple-cursors-in-500-bytes-of-vimscript/ let g:mc = "y/\\V\=escape(@\", '/')\\" " Multiple Cursor nnoremap xm *``cgn vnoremap xm g:mc . "``cgn" let g:which_key_map.x.m = 'multiple-cursor' " Multiple Cursor - reserve direction nnoremap xM *``cgN vnoremap xM g:mc . "``cgN" let g:which_key_map.x.M = 'multiple-cursor-reverse' " Delete trainling Whitespaces fun! TrimWhitespace() let l:save = winsaveview() keeppatterns %s/\s\+$//e call winrestview(l:save) endfun nnoremap xt :call TrimWhitespace() let g:which_key_map.x.t = 'delete-trailing-whitespaces' #+END_SRC ** Config #+BEGIN_SRC conf let g:which_key_map.c = { 'name' : '+config' } let s:activatedsh = 0 function! ToggleSyntaxH() if s:activatedsh == 0 let s:activatedsh = 1 set synmaxcol=800 else let s:activatedsh = 0 set synmaxcol=100 endif endfunction " Toggle Syntax column nnoremap cs :call ToggleSyntaxH() let g:which_key_map.c.s = 'toggle-syntax-col' let s:activatedh = 0 function! ToggleH() if s:activatedh == 0 let s:activatedh = 1 match Search '\%>80v.\+' else let s:activatedh = 0 match none endif endfunction " Toggle Highlight nnoremap ch :call ToggleH() let g:which_key_map.c.h = 'toggle-highlight' " Reload vim config noremap cr :source $MYVIMRC let g:which_key_map.c.e = 'reload-config' " Edit vim config noremap ce :e $MYVIMRC let g:which_key_map.c.e = 'edit-config' " Disable highlight noremap c :noh let g:which_key_map.c.enter = 'disable-highlight' " Theme noremap ct :noh let g:which_key_map.c.t = 'choose-theme' #+END_SRC ** Insert #+BEGIN_SRC conf let g:which_key_map.i = { 'name' : '+insert' } " Insert Snippet noremap is :Snippets let g:which_key_map.i.s = 'insert-snippet' #+END_SRC ** Save Which Key Configuration #+BEGIN_SRC conf call which_key#register('', "g:which_key_map") #+END_SRC