literate-dotfiles/vim.org

1199 lines
28 KiB
Org Mode

#+TITLE: Vim Config
#+SETUPFILE: ./setup/org-setup-file.org
#+PROPERTY: header-args :comments none
#+PROPERTY: header-args+ :mkdirp yes
#+PROPERTY: header-args+ :tangle ~/.vimrc
* Plugins Install
** Plug start
#+BEGIN_SRC vimrc
call plug#begin('~/.vim/plugged')
#+end_src
** Manage Files
File Manager:
#+begin_src vimrc
Plug 'tpope/vim-vinegar'
#+end_src
Fuzzy Find:
#+begin_src vimrc
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'make' }
#+end_src
** Text Objects
#+begin_src vimrc
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 vimrc
" Plug 'mhinz/vim-signify' " Show a diff using Vim its sign column
Plug 'TimUntersberger/neogit'
#+end_src
** Motions, Search
#+begin_src vimrc
Plug 'justinmk/vim-sneak' " The missing motion for Vim
Plug 'haya14busa/is.vim' " Automatically clear highlight after search
#+end_src
** Manipulate Things
#+begin_src vimrc
Plug 'tpope/vim-surround' " Quoting/parenthesizing made simple
Plug 'tpope/vim-commentary' " Comment stuff out
Plug 'junegunn/vim-easy-align' " A Vim alignment plugin
#+end_src
The following two packages are used to search and modify multiple files at once
#+begin_src vimrc
" Plug 'Olical/vim-enmasse' " Edit every line in a quickfix list at the same time
" Plug 'mhinz/vim-grepper', { 'on': ['Grepper', '<plug>(GrepperOperator)'] } "
#+end_src
** Utils
#+begin_src vimrc
Plug 'tpope/vim-repeat' " Enable repeating supported plugin maps with '.'
Plug 'tpope/vim-speeddating' " use CTRL-A/CTRL-X to increment dates, times, and more
#+end_src
** Visual
#+begin_src vimrc
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
#+end_src
** Themes
#+begin_src vimrc
Plug 'morhetz/gruvbox' " Retro groove color scheme for Vim
#+end_src
Other nice themes are [[https://github.com/mhartington/oceanic-next][oceanic-next]] and [[https://github.com/jacoborus/tender.vim][tender]].
** TODO Language Server Protocol
#+begin_src vimrc
" LSP Support
Plug 'neovim/nvim-lspconfig'
Plug 'williamboman/nvim-lsp-installer'
" Autocompletion
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'saadparwaiz1/cmp_luasnip'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-nvim-lua'
" Snippets
Plug 'L3MON4D3/LuaSnip'
Plug 'rafamadriz/friendly-snippets'
Plug 'VonHeikemen/lsp-zero.nvim'
#+end_src
#+begin_src vimrc
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
#+end_src
** Snippnets and autocompletion
#+begin_src vimrc
" Plug 'SirVer/ultisnips' " The ultimate snippet solution for Vim
" Plug 'honza/vim-snippets' " Vim-snipmate default snippets
#+end_src
** Syntax Checking and Build Utils
#+begin_src vimrc
" Plug 'neomake/neomake' " Asynchronous linting and make framework for Neovim/Vim
#+end_src
** Tmux
#+begin_src vimrc
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 vimrc
" Plug 'sheerun/vim-polyglot' " A solid language pack for Vim
#+end_src
** LaTeX
#+begin_src vimrc
" Plug 'lervag/vimtex', { 'for': 'tex' } " A modern vim plugin for editing LaTeX files.
#+end_src
** Matlab
#+begin_src vimrc
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
** Plug End
#+begin_src vimrc
call plug#end()
#+end_src
* Basic
** General
#+begin_src vimrc
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 = "\<Space>"
let g:mapleader = "\<Space>"
let maplocalleader = ","
#+end_src
** VIM user interface
#+begin_src vimrc
" 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 <expr> j v:count ? (v:count > 5 ? "m'" . v:count : '') . 'j' : 'gj'
nnoremap <expr> 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 vimrc
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 vimrc
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 vimrc
" 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 vimrc
" Use spaces instead of tabs
set expandtab
" Be smart when using tabs
set smarttab
" 1 tab == 4 spaces
set shiftwidth=4
set tabstop=4
" Enable Line Number
set number
#+end_src
From https://stackoverflow.com/questions/36950231/auto-wrap-lines-in-vim-without-inserting-newlines.
#+begin_src vimrc
" Word wrap without line breaks
set textwidth=0
set wrapmargin=0
set wrap
set linebreak
" set columns=160
#+end_src
#+begin_src vimrc
set autoindent " Auto Indentation
set nosmartindent " No Smart Indentation
#+end_src
** Moving around, tabs, windows and buffers
#+begin_src vimrc
" 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 vimrc
" 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 vimrc
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 <SID>BufcloseCloseIt()
function! <SID>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 vimrc
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 vimrc
try
set undodir=~/.vim_runtime/temp_dirs/undodir
set undofile
catch
endtry
#+end_src
* Mappings
** Normal mode related
#+begin_src vimrc
" Smart way to move between windows
noremap <C-j> <C-W>j
noremap <C-k> <C-W>k
noremap <C-h> <C-W>h
noremap <C-l> <C-W>l
#+end_src
** Insert mode related
#+begin_src vimrc
" Paste while in insert mode
inoremap <C-v> <C-r>*
" Go to the end of line
inoremap <C-e> <Esc>A
" Go to the beginning of line
inoremap <C-a> <Esc>I
#+end_src
** Visual mode related
#+begin_src vimrc
" Visual mode pressing / or ? searches for the current selection
vnoremap <silent> / :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
vnoremap <silent> ? :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
" Re-select visual block after indenting
vnoremap < <gv
vnoremap > >gv
" Move visual block
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
#+end_src
** Add some delimiters
#+begin_src vimrc
" use $ as a delimiter
xnoremap i$ :<C-u>normal! T$vt$<CR>
xnoremap a$ :<C-u>normal! T$hvt$l<CR>
onoremap i$ :normal vi$<CR>
onoremap a$ :normal va$<CR>
#+end_src
** Command mode related
#+begin_src vimrc
" Bash like keys for the command line
cnoremap <C-A> <Home>
cnoremap <C-E> <End>
cnoremap <C-K> <C-U>
cnoremap <C-P> <Up>
cnoremap <C-N> <Down>
#+end_src
** Terminal mode related
#+begin_src vimrc
" tnoremap <Esc> <C-\><C-n>
tnoremap <C-w>h <C-\><C-n><C-w>h
tnoremap <C-w>j <C-\><C-n><C-w>j
tnoremap <C-w>k <C-\><C-n><C-w>k
tnoremap <C-w>l <C-\><C-n><C-w>l
#+end_src
** Correct misspelled works
Taken from: https://vi.stackexchange.com/questions/68/autocorrect-spelling-mistakes
#+begin_src vimrc
" Go back to last misspelled word and pick first suggestion.
inoremap <C-L> <c-g>u<Esc>[s1z=`]a<c-g>u
" Select last misspelled word (typing will edit).
nnoremap <C-K> <Esc>[sve<C-G>
inoremap <C-K> <Esc>[sve<C-G>
snoremap <C-K> <Esc>b[sviw<C-G>
#+end_src
* Filetypes
** Mails
#+begin_src vimrc
autocmd FileType mail set spell spelllang=en_us,fr
autocmd FileType mail set textwidth=0
function! Mailcomplete(findstart, base)
if a:findstart == 1
let line = getline('.')
let idx = col('.')
while idx > 0
let idx -= 1
let c = line[idx]
if c == ':' || c == '>'
return idx + 2
else
continue
endif
endwhile
return idx
else
return split(system('~/.local/scripts/find-config.sh ' . a:base), '\n')
endif
endfunction
setl omnifunc=Mailcomplete
#+end_src
#+begin_src bash :shebang "#!/usr/bin/env bash" :tangle-mode (identity #o555) :tangle ~/.local/scripts/find-config.sh
search="$@"
contacts=`mu cfind "$search"`
emails=`echo "$contacts" | awk -F' ' '{print "<" $NF ">"}'`
names=`echo "$contacts" | awk -F' ' '{$NF=""; print $0}'`
paste -d "" <(printf %s "$names") <(printf %s "$emails")
#+end_src
** MarkDown
#+begin_src vimrc
" Automatically turn on spell-checking for Markdown files
au BufRead,BufNewFile *.md setlocal spell spelllang=fr,en
#+end_src
** LaTeX
#+begin_src vimrc
au BufRead,BufNewFile *.tikz set filetype=tex
let tex_no_error=1 " 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 <leader>lt <plug>(vimtex-toc-toggle)
" autocmd FileType tex,tikz nnoremap <leader>ll <plug>(vimtex-labels-open)
" autocmd FileType tex,tikz nnoremap <leader>lv <plug>(vimtex-view)
" autocmd FileType tex,tikz nnoremap <leader>lf <plug>(vimtex-reverse-search)
" " Make Tikz
" nnoremap <leader>mt :Make pdf t=tikz f=%:t:r<cr>
" nnoremap <leader>mto :make open t=tikz f=%:t:r<cr>
" " Make LaTeX
" nnoremap <leader>ml :Make pdf f=%:t:r<cr>
" nnoremap <leader>mlo :make open f=%:t:r<cr>
#+end_src
** Arduino
#+begin_src vimrc
au BufRead,BufNewFile *.pde set filetype=arduino
au BufRead,BufNewFile *.ino set filetype=arduino
" au FileType arduino map <leader>ac :!platformio run<CR>
" au FileType arduino map <leader>au :!platformio run -s --target=upload<CR>
" au FileType arduino map <leader>am :!platformio serialports monitor --port=/dev/cu
#+end_src
** Python
#+begin_src vimrc
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 <buffer> <localleader><localleader> <Plug>SlimeParagraphSend
" Run Selected text
au FileType python vmap <buffer> <localleader><localleader> <Plug>SlimeRegionSend
" CD to directory of current file
au FileType python nmap <buffer> <localleader>c :SlimeSend0('cd '.expand('%:p:h'))<CR>
#+end_src
** Matlab
#+begin_src vimrc
" Run Section (delimited by %%)
au FileType matlab nmap <buffer> <localleader>mm <Plug>SlimeParagraphSend
" Run either Selected text
au FileType matlab vmap <buffer> <localleader>mm <Plug>SlimeRegionSend
#+end_src
#+begin_src vimrc
func! GetSelectedText()
normal gv"xy
let result = getreg("x")
normal gv
return result
endfunc
" Help on the current selection
au FileType matlab vmap <buffer> <localleader>mh :<C-U>SlimeSend0('help '.expand(GetSelectedText()))<CR>
" Documentation on the current selection
au FileType matlab vmap <buffer> <localleader>mH :<C-U>SlimeSend0('doc '.expand(GetSelectedText()))<CR>
" Open the current file in the Matlab Editor (usefull for debuging)
au FileType matlab nmap <buffer> <localleader>me :SlimeSend0('edit '.expand('%:p'))<CR>
" Run all the file
au FileType matlab nmap <buffer> <localleader>mr :SlimeSend0('run '.expand('%:t'))<CR>
" Send "cd filepath" to matlab
au FileType matlab nmap <buffer> <localleader>mc :SlimeSend0('cd '.expand('%:p:h'))<CR>
" Open workspace
au FileType matlab nmap <buffer> <localleader>mw :SlimeSend0('workspace')<CR>
#+end_src
* Plugins Config
** Treesitter
#+begin_src vimrc
lua <<EOF
require'nvim-treesitter.configs'.setup {
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
}
EOF
#+end_src
** =junegunn/fzf=
#+begin_src vimrc
" " 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 <SID>fzf_statusline()
#+end_src
** =autozimu/LanguageClient-neovim=
#+begin_src vimrc
" 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 <F5> :call LanguageClient_contextMenu()<CR>
" " Or map each action separately
" nnoremap <silent> K :call LanguageClient#textDocument_hover()<CR>
" nnoremap <silent> gd :call LanguageClient#textDocument_definition()<CR>
" nnoremap <silent> <F2> :call LanguageClient#textDocument_rename()<CR>
#+end_src
** =JamshedVesuna/vim-markdown-preview=
#+begin_src vimrc
" 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 vimrc
let g:signify_vcs_list = ['git']
let g:signify_disable_by_default = 1
#+end_src
** =Deoplete=
#+begin_src vimrc
" 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 vimrc
" let g:UltiSnipsSnippetsDir = '~/.vim/UltiSnip'
" " inoremap <silent><expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
" let g:UltiSnipsExpandTrigger="<C-j>"
" let g:UltiSnipsJumpForwardTrigger="<tab>"
" let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
#+end_src
** =honza/vim-snippets=
#+begin_src vimrc
let g:snipMate = {}
let g:snipMate.scope_aliases = {}
#+end_src
** =itchyny/lightline.vim=
#+begin_src vimrc
" \ 'colorscheme': 'gruvbox',
let g:lightline = {
\ 'colorscheme': 'solarized',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'filename', 'modified', 'fugitive' ] ]
\ },
\ 'component': {
\ 'fugitive': '%{exists("*fugitive#head")?fugitive#head():""}'
\ },
\ 'component_visible_condition': {
\ 'fugitive': '(exists("*fugitive#head") && ""!=fugitive#head())'
\ },
\ 'separator': { 'left': '', 'right': '' },
\ 'subseparator': { 'left': "|", 'right': "|" }
\ }
#+end_src
** Git
#+begin_src vimrc
lua <<EOF
local neogit = require('neogit')
neogit.setup {}
EOF
#+end_src
** LSP
#+begin_src vimrc
lua <<EOF
local lsp = require('lsp-zero')
lsp.preset('recommended')
lsp.setup()
EOF
#+end_src
** =Autopairs=
#+begin_src vimrc
" Incompatibilité entre auto-pairs et clang-complete
let g:AutoPairsMapCR = 0
imap <silent><CR> <CR><Plug>AutoPairsReturn
#+end_src
** =Yggdroot/indentLine=
#+begin_src vimrc
" :IndentLinesToggle toggles lines on and off.
let g:indentLine_color_term = 239
#+end_src
** =ryanoasis/vim-devicons=
#+begin_src vimrc
let g:webdevicons_enable_ctrlp = 1
#+end_src
** =tpope/vim-surround=
#+begin_src vimrc
vmap Si S(i_<esc>f)
au FileType mako vmap Si S"i${ _(<esc>2f"a) }<esc>
" surroung un visual mode : use S, then b to make the text bold in markdown
let g:surround_{char2nr('b')} = "__\r__"
#+end_src
** =Neomake=
#+begin_src vimrc
" " 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 vimrc
" 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 vimrc
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 vimrc
" nnoremap <leader>G :Grepper -tool ag<cr>
" nmap gs <plug>(GrepperOperator)
" xmap gs <plug>(GrepperOperator)
#+end_src
** Editor config
#+begin_src vimrc
" 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
** Telescope
#+begin_src vimrc
lua <<EOF
require('telescope').load_extension('fzf')
EOF
#+end_src
* Key Bindings
** Quit
#+begin_src vimrc
" Quit
nnoremap <leader>qq :qa<cr>
" Quit - Force
nnoremap <leader>qQ :qa!<cr>
#+end_src
** Files
#+begin_src vimrc
" Fast saving
nnoremap <leader>fs :w!<cr>
" Find Files
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <leader><space> <cmd>Telescope find_files<cr>
#+end_src
** Buffers
#+begin_src vimrc
" Buffer Create
noremap <leader>bc :enew<cr>
" Buffer Delete
noremap <leader>bd :Bclose<cr>
" Buffer Next
noremap <leader>bn :bnext<cr>
" Buffer Previous
noremap <leader>bp :bprevious<cr>
" Find Buffers
nnoremap <leader>bb <cmd>Telescope buffers<cr>
#+end_src
** Tabs
#+begin_src vimrc
" Let 'tt' toggle between this and the last accessed tab
let g:lasttab = 1
au TabLeave * let g:lasttab = tabpagenr()
" Tab New
nnoremap <leader>tc :tabnew<cr>
" Tab Delete
nnoremap <leader>td :tabclose<cr>
" Tab Move Left
nnoremap <leader>tH :tabmove -1<cr>
" Tab Move Right
nnoremap <leader>tL :tabmove +1<cr>
" Tab Toggle
nnoremap <Leader>tt :exe "tabn ".g:lasttab<CR>
#+end_src
** Terminals
#+begin_src vimrc
" Quickly create a new terminal in a new tab
nnoremap <Leader>Tc :tab new<CR>:term<CR>
" Quickly create a new terminal in a vertical split
nnoremap <Leader>Tv :vsplit<CR>:term<CR>
" Quickly create a new terminal in a horizontal split
nnoremap <Leader>Th :split<CR>:term<CR>
#+end_src
** Splits / Windows
#+begin_src vimrc
" Split Horizontal
nnoremap <leader>ws :split<cr>
" Split Vertical
nnoremap <leader>wv :vsplit<cr>
" Split Maximize
nnoremap <leader>wm <C-w>o
" Split Delete
nnoremap <leader>wd <C-w>q
" Split Go Left
nnoremap <leader>wh :wincmd h<CR>
" Split Go Down
nnoremap <leader>wj :wincmd j<CR>
" Split Go Up
nnoremap <leader>wk :wincmd k<CR>
" Split Go Right
nnoremap <leader>wl :wincmd l<CR>
" Split Move Left
nnoremap <leader>wH <C-w>H
" Split Move Down
nnoremap <leader>wJ <C-w>J
" Split Move Up
nnoremap <leader>wK <C-w>K
" Split Move Right
nnoremap <leader>wL <C-w>L
#+end_src
** TODO Check Spell
#+begin_src vimrc
" CheckSpell Toggle
noremap <leader>St :setlocal spell!<cr>
" CheckSpell Correct
noremap <leader>Sc z=
" CheckSpell Do first
noremap <leader>SC 1z=
" CheckSpell Language
noremap <leader>Sl :set spelllang=
" CheckSpell Next
noremap <leader>Sn ]s
" CheckSpell Next and correct
noremap <leader>SN ]s1z=
" CheckSpell Previous
noremap <leader>Sp [s
" CheckSpell Previous and correct
noremap <leader>SP [s1z=
" CheckSpell Add to dictionnary
noremap <leader>Sa zg
#+end_src
** TODO Make
#+begin_src vimrc
" Make Make
nnoremap <leader>mm :Make -B<CR>
" Make Clean
nnoremap <leader>mc :Make clean<CR>
" Make Force
nnoremap <leader>mf :Make! -B<CR>
" Make Run
nnoremap <leader>mr :Make! run<cr>
" Make Open
nnoremap <leader>mo :make! open<cr>
#+end_src
** Search
#+begin_src vimrc
nnoremap <leader>s <cmd>Telescope live_grep<cr>
#+end_src
** GIT
#+begin_src vimrc
nnoremap <silent><leader>g :Neogit<cr>
#+end_src
** TODO Errors
#+begin_src vimrc
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 <silent><leader>ee :call ToggleLocationList()<CR>
" Error Open
nnoremap <silent><leader>eo :lopen<CR>
" Error Close
nnoremap <silent><leader>ec :lclose<CR>
" Error Next
nnoremap <silent><leader>en :lnext<CR>
" Error Previous
nnoremap <silent><leader>ep :lprevious<CR>
#+end_src
** Text
#+begin_src vimrc
" Start interactive EasyAlign in visual mode (e.g. vipga) and for a motion
xmap <leader>xa <Plug>(EasyAlign)
nmap <leader>xa <Plug>(EasyAlign)
" Indent all file
nnoremap <leader>x= mzgg=G`z
" Custom Multiple Cursor
" http://www.kevinli.co/posts/2017-01-19-multiple-cursors-in-500-bytes-of-vimscript/
let g:mc = "y/\\V\<C-r>=escape(@\", '/')\<CR>\<CR>"
" Multiple Cursor
nnoremap <leader>xm *``cgn
vnoremap <expr> <leader>xm g:mc . "``cgn"
" Multiple Cursor - reserve direction
nnoremap <leader>xM *``cgN
vnoremap <expr> <leader>xM g:mc . "``cgN"
" Delete trainling Whitespaces
fun! TrimWhitespace()
let l:save = winsaveview()
keeppatterns %s/\s\+$//e
call winrestview(l:save)
endfun
nnoremap <leader>xt :call TrimWhitespace()<CR>
#+end_src
** Config
#+begin_src vimrc
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 <leader>cs :call ToggleSyntaxH()<CR>
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 <leader>ch :call ToggleH()<CR>
" Reload vim config
noremap <Leader>cr :source $MYVIMRC<CR>
" Edit vim config
noremap <Leader>ce :e $MYVIMRC<CR>
" Disable highlight
noremap <silent> <leader>c<CR> :noh<CR>
" Theme
noremap <silent> <leader>ct :noh<CR>
#+end_src