config/.vimrc

593 lines
16 KiB
VimL
Raw Normal View History

"""""""""""""
" SHORTCUTS "
"""""""""""""
" F1 help
" F2 open file in a new tab
" S-F2 Split and open file
" F3 autotags Update
" S-F3 autotags Add
" F4 open include file
" F5 find C symbol
" F6 go to definition
" F7 go to calls
" F8 view tag list
" S-F8 build ctags/cscope databases
" M-F8 build kernel ctags/cscope databases
2015-07-06 14:26:11 +02:00
" F9 Open NerdTree
" M-F9 Show diff line
2014-04-08 14:26:26 +02:00
" S-F9 Highlight diff line
" F10 folding
" S-F10 unfolding
" F11 unhighlight search
" F12 paste mode
" C-left/right switch tab
" C-up/down switch window
" M-left/right horizontal size
" M-up/down vertical size
2015-02-27 15:56:40 +01:00
" gc comment/uncomment
" C-K indent selection
2015-09-02 10:35:23 +02:00
" \-k Set Kernel Coding style
" Use snippets with tab e.g : for <tab> (see .vim/bundle/vim-snippets/snippets for available
2010-05-04 15:32:13 +02:00
" snippets)
"""""""""""
" GENERAL "
"""""""""""
" disable vi-compatible mode
set nocompatible
" Switch syntax highlighting on when the terminal has colors or when using the
" GUI (which always has colors).
if &t_Co > 2 || has("gui_running")
2018-07-11 17:33:17 +02:00
" Revert with ":syntax off".
syntax on
2018-07-11 17:33:17 +02:00
" I like highlighting strings inside C comments.
" Revert with ":unlet c_comment_strings".
let c_comment_strings=1
endif
2015-07-07 15:02:12 +02:00
filetype plugin on
" enable file type detection and do language-dependent indenting
filetype plugin indent on
2015-02-27 15:56:40 +01:00
"set clipboard=unnamed
""""""""
" SAVE "
""""""""
" disable backup
set nobackup
" save before compilation
set autowrite
" Put these in an autocmd group, so that you can revert them with:
" ":augroup vimStartup | au! | augroup END"
augroup vimStartup
2018-07-11 17:33:17 +02:00
au!
2018-07-11 17:33:17 +02:00
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") >= 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
" command line history
set history=200
2011-12-09 10:28:56 +01:00
" Check that file have not been changed
" CursorHold : after cursor move
" WinEnter or BufWinEnter
au WinEnter * checktime
au BufWinEnter * checktime
"""""""""
" INPUT "
"""""""""
" allow backspacing in insert mode
set backspace=indent,eol,start
" don't use Ex mode, use Q for formatting
map Q gq
2015-12-07 12:05:07 +01:00
" Enable mouse for 'a'll mode
2014-02-27 17:24:24 +01:00
set mouse=a
" key combination timeout
set notimeout
"set timeoutlen=4000
" set timeout for multicharacter keys codes (like <F1>)
set ttimeout
" set timeout to tenth of a second (could be increased for slow terminals)
set ttimeoutlen=100
" key event timeout
set updatetime=1000
2017-08-16 14:41:36 +02:00
" Use hjkl-movement between rows when soft wrapping.
nnoremap j gj
nnoremap k gk
vnoremap j gj
vnoremap k gk
"""""""""""
" DISPLAY "
"""""""""""
" highlight the cursor line
set cursorline
" show the cursor position
set ruler
" show mode
set showmode
" display incomplete commands
set showcmd
" display line number"
set number
2011-05-26 14:01:52 +02:00
" set status line
set statusline=%<%f\ %h%w%m%r%3.(\ %)%{fugitive#statusline()}%=%([%{Tlist_Get_Tagname_By_Line()}]%)%3.(\ %)%-14.(%l,%c%V%)\ %P
" always display status line
set laststatus=2
set showcmd " display incomplete commands
set wildmenu " display completion matches in a status line
" show bad white spaces
let c_space_errors = 1
let python_space_error_highlight = 1
highlight link cSpaceError SpaceError
highlight link pythonSpaceError SpaceError
highlight SpaceError ctermfg=235 cterm=reverse
"""""""""""""""
" INDENTATION "
"""""""""""""""
2011-05-26 14:01:52 +02:00
" use tabs at the start of a line, spaces elsewhere
set smarttab
set smartindent
set autoindent
2014-03-24 19:27:29 +01:00
"" tab=4
"set tabstop=4
"set softtabstop=4
"set shiftwidth=4
" tab=8
2014-03-24 17:46:29 +01:00
set tabstop=8
set softtabstop=8
set shiftwidth=8
" real tabs
2011-10-20 14:52:04 +02:00
" set noexpandtab
2011-05-26 14:01:52 +02:00
2018-03-07 17:15:11 +01:00
"filetype specific action
if has("autocmd")
2018-03-07 17:15:11 +01:00
au Filetype markdown set tabstop=4 shiftwidth=4 softtabstop=4
au BufRead,BufNewFile *.iris set ft=python
au BufRead,BufNewFile *.ino set tabstop=4 shiftwidth=4 softtabstop=4
au BufRead,BufNewFile *.asm set ft=nasm
" python
" autocmd FileType python set tabstop=4|set shiftwidth=4|set expandtab
2016-03-02 18:20:03 +01:00
autocmd Filetype python set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
2018-03-07 17:15:11 +01:00
autocmd Filetype python set tabstop=4 shiftwidth=4 softtabstop=4
2016-03-02 18:20:03 +01:00
autocmd Filetype python set expandtab
autocmd Filetype python set modeline
2016-03-02 17:27:17 +01:00
" Indentation with = for python need autopep8
2016-03-02 18:20:03 +01:00
autocmd Filetype python set equalprg=autopep8\ -
2017-08-16 14:13:29 +02:00
iab sefl self
iab slef self
2016-03-02 18:20:03 +01:00
endif
" vim -b : edit binary using xxd-format!
augroup Binary
au!
au BufReadPre *.bin let &bin=1
au BufReadPost *.bin if &bin | %!xxd
au BufReadPost *.bin set ft=xxd | endif
au BufWritePre *.bin if &bin | %!xxd -r
au BufWritePre *.bin endif
au BufWritePost *.bin if &bin | %!xxd
au BufWritePost *.bin set nomod | endif
augroup END
" detect indentation see http://www.freehackers.org/Indent_Finder
if &expandtab
autocmd BufReadPost /* execute system ('python2 ~/.vim/indent_finder/indent_finder.py --vim-output --default space --default-size ' . &tabstop .' "' . expand('%') . '"' )
2018-07-11 17:26:53 +02:00
autocmd BufReadPost /* let b:clang_style="{BasedOnStyle: LLVM, AlignConsecutiveAssignments: true, AllowShortFunctionsOnASingleLine: Empty, BreakBeforeBraces: Linux, BreakStringLiterals: false, ColumnLimit: 95, IndentCaseLabels: true, IndentWidth: " .&shiftwidth .", TabWidth: " .&tabstop .", UseTab: Never}"
else
autocmd BufReadPost /* execute system ('python2 ~/.vim/indent_finder/indent_finder.py --vim-output --default tab --default-size ' .&tabstop .' "' . expand('%') . '"' )
2018-07-11 17:26:53 +02:00
autocmd BufReadPost /* let b:clang_style="{BasedOnStyle: LLVM, AlignConsecutiveAssignments: true, AllowShortFunctionsOnASingleLine: Empty, BreakBeforeBraces: Linux, BreakStringLiterals: false, ColumnLimit: 95, IndentCaseLabels: true, IndentWidth: " .&shiftwidth .", TabWidth: " .&tabstop .", UseTab: ForContinuationAndIndentation}"
endif
map <C-K> :pyf ~/.vim/syntax/clang-format.py<CR>
imap <C-K> <ESC>:pyf ~/.vim/syntax/clang-format.py<CR>i
let g:clang_rename_path="clang-rename-4.0"
noremap <leader>cr :pyf ~/.vim/syntax/clang-rename.py<cr>
set wildignore+=*.o,*.d,*.dex,*.class,*.png,*.jpeg,*.jpg,*.pdf
""""""""""
" SEARCH "
""""""""""
" highlight search
set hlsearch
" unhighlight current search
map <silent> <F11> :nohlsearch<CR>
imap <F11> <ESC><F11>a
" highlight search while typing
set incsearch
" show matching brackets -> key %
set showmatch
" tenths of a second before blink matching brackets
set mat=5
" search word and list lines to jump with F3
2014-07-18 23:21:55 +02:00
" map <F3> [I:let nr = input("Which one: ") <Bar>execute "normal " . nr ."[\t"<CR>
" go to declaration with F5
" map <silent> <F5> gd:nohlsearch<CR>
" imap <F5> <ESC><F5>i
2011-05-26 14:01:52 +02:00
" plugin taglist
let Tlist_Ctags_Cmd = '/usr/bin/ctags'
let Tlist_Process_File_Always = 1
let Tlist_Exit_OnlyWindow = 1
"let Tlist_Close_On_Select = 1
let Tlist_Auto_Highlight_Tag = 1
let Tlist_Display_Prototype = 0
let Tlist_Display_Tag_Scope = 0
let Tlist_Show_One_File = 1
let Tlist_Compact_Format = 1
let Tlist_Enable_Fold_Column = 0
2013-03-04 17:05:25 +01:00
" sort by name or order ?
let Tlist_Sort_Type = "name"
"let Tlist_File_Fold_Auto_Close = 1
let Tlist_Inc_Winwidth = 0
"let Tlist_Use_Horiz_Window = 1
let Tlist_Use_Right_Window = 1
" open/close tag list window with F8
"map <silent> <F8> :TlistToggle<CR>
nmap <F8> :TagbarToggle<CR>
2011-05-26 14:01:52 +02:00
" close preview window after a completion
if has("autocmd")
autocmd CursorMovedI *.{[hc],cpp} if pumvisible() == 0|pclose|endif
autocmd InsertLeave *.{[hc],cpp} if pumvisible() == 0|pclose|endif
endif
function! TagInNewTab()
let word = expand("<cword>")
redir => tagsfiles
silent execute 'set tags'
redir END
tabe
execute 'setlocal' . strpart(tagsfiles, 2)
execute 'tag ' . word
endfunction
map <C-I> :call TagInNewTab()<CR>
"""""""""
" PASTE "
"""""""""
" set/unset paste mode with F12/shift+F12
map <F12> :set paste<CR>
map <S-F12> :set nopaste<CR>
imap <F12> <C-O>:set paste<CR>
imap <S-F12> <nop>
set pastetoggle=<S-F12>
" paste with reindent with Esc prefix
nnoremap <Esc>P P'[v']=
nnoremap <Esc>p p'[v']=
""""""""""
" WINDOW "
""""""""""
" create window below or at right of the current one
set splitbelow
set splitright
" if multiple windows
if bufwinnr(1)
" vertically increase/decrease window size with alt+up/alt+down
map <M-Up> <C-W>+
map <M-Down> <C-W>-
imap <M-Up> <ESC><M-Up>a
imap <M-Down> <ESC><M-Down>a
" horizontally increase/decrease window size with alt+right/alt+left
map <M-Right> <C-W>>
map <M-Left> <C-W><
imap <M-Right> <ESC><M-Right>a
imap <M-Left> <ESC><M-Left>a
" switch to next/previous tab with ctrl+right/ctrl+left
map <C-Right> gt
map <C-Left> gT
imap <C-Right> <ESC><C-Right>a
imap <C-Left> <ESC><C-Left>a
" switch to next/previous window with ctrl+down/ctrl+up
map <C-Down> <C-W>w
map <C-Up> <C-W>W
imap <C-Down> <ESC><C-Down>a
imap <C-Up> <ESC><C-Up>a
endif
" open automatically quickfix window
if has("autocmd")
2018-07-11 17:33:17 +02:00
autocmd QuickFixCmdPost * cw
endif
" open a file in the same directory as the current file with F2 and split with shift+F2
map <F2> :tabe <C-R>=expand("%:h") . "/"<CR>
nmap <S-F2> :split <C-R>=expand("%:h") . "/"<CR>
""""""""
" HELP "
""""""""
" allow embedded man page
runtime! ftplugin/man.vim
" show vimrc with shift+F1
nmap <silent> <S-F1> :tabe ~/.vimrc<CR>gg
2014-04-08 14:26:26 +02:00
imap <S-F1> <Esc><S-F1>
" show contextual help with F1
function Help()
try
2018-07-11 17:33:17 +02:00
if exists('b:current_syntax') && b:current_syntax == "python"
:call ShowPyDoc(expand("<cword>"), 1)
else
execute "Man " . expand("<cword>")
endif
catch /:E149:/
execute "help " . expand("<cword>")
endtry
endfunction
nmap <silent> <F1> :call Help()<CR>
2010-09-21 10:59:10 +02:00
imap <F1> <Esc><F1>
" show VIM help with alt+shift+F1
nmap <silent> <M-S-F1> :help <C-R>=expand("<cword>")<CR><CR>
imap <M-S-F1> <Esc><M-S-F1>
"""""""""
" TOOLS "
"""""""""
" show git diff when committing
let g:git_diff_spawn_mode = 1
" zf#j creates a fold from the cursor down # lines.
"zf/string creates a fold from the cursor to string .
"zj moves the cursor to the next fold.
"zk moves the cursor to the previous fold.
"zo opens a fold at the cursor.
"zO opens all folds at the cursor.
"zm increases the foldlevel by one.
"zM closes all open folds.
"zr decreases the foldlevel by one.
"zR decreases the foldlevel to zero -- all folds will be open.
"zd deletes the fold at the cursor.
"zE deletes all folds.
"[z move to start of open fold.
"]z move to end of open fold.
" fold form this bracket
nmap <F10> zfa{<CR><CR>
" unfold or use End
nmap <S-F10> zo<CR><CR>
" Autosave folding
"au BufWinLeave * mkview
" Autoload folding
"au BufWinEnter * silent loadview
2010-11-30 16:30:39 +01:00
""""""""""""""""""""""""""""""""""""""""""""""""""
"Omni-completion par CTRL-X_CTRL-O
"""""""""""""""""""""""""""""""""""""""""""""""""""
set omnifunc=syntaxcomplete#Complete
" Enable omnicppcompletion
let OmniCpp_ShowAccess = 0
let OmniCpp_LocalSearchDecl=1
let OmniCpp_MayCompleteDot = 1 " autocomplete after .
let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
set path=.,..,/usr/local/include,/usr/include
2011-01-27 00:06:07 +01:00
"""""""""""""
" Latex "
"""""""""""""
" package vim-latexsuite
" Insert the following line in your ~/.vim/ftplugin/tex.vim file:
" imap <buffer> <leader>it <Plug>Tex_InsertItemOnThisLine
" compile with \ll
set grepprg=grep\ -nH\ $*
let g:tex_flavor = "pdflatex"
imap <buffer> <leader>it <Plug>Tex_InsertItemOnThisLine
let g:Tex_DefaultTargetFormat="pdf"
2015-12-07 12:05:58 +01:00
if has('gui_running')
colorscheme darkblue
else
colorscheme mycolor
endif
2014-03-24 17:46:29 +01:00
cnoremap sudow w !sudo tee % >/dev/null
2018-07-11 17:33:17 +02:00
" Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! w !sudo tee > /dev/null %
2014-04-07 16:29:15 +02:00
2014-04-08 14:26:26 +02:00
"""""""""""
2015-07-06 14:26:11 +02:00
" NerdTree
2014-04-08 14:26:26 +02:00
"""""""""""
2015-07-06 14:26:11 +02:00
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
map <F9> :NERDTreeToggle<CR>
"""""""""""
" GitGutter
"""""""""""
map <M-F9> :GitGutterSignsToggle <CR>
2014-04-08 14:26:26 +02:00
map <S-F9> :GitGutterLineHighlightsToggle <CR>
2015-09-02 10:35:23 +02:00
""""""""""
" KernelFormatting
""""""""""
nnoremap <silent> <leader>k :SetLinuxFormatting<cr><cr>
2015-12-08 15:00:03 +01:00
""""""""""
" LocalConfig
""""""""""
if filereadable(expand('~/.vimrc.local'))
2018-07-11 17:33:17 +02:00
" Plugins list and settings should be loaded
" only once. Load local_settings block
let g:local_plugins = 0
let g:local_settings = 1
source ~/.vimrc.local
2015-12-08 15:00:03 +01:00
endif
2016-06-03 11:02:06 +02:00
""""""""""
" W3m
""""""""""
let g:w3m#external_browser = 'firefox'
""""""""""
" Kernel
""""""""""
let g:linuxsty_patterns = [ "/usr/src/", "/linux" ]
nnoremap <silent> <leader>a :LinuxCodingStyle<cr>
""""""""""
" Debug
""""""""""
"Or start vim with -V[VERBOSENUMBER][FILE]
function! ToggleVerbose()
2018-07-11 17:33:17 +02:00
if !&verbose
set verbosefile=~/.log/vim/verbose.log
set verbose=15
else
set verbose=0
set verbosefile=
endif
endfunction
2014-04-07 16:29:15 +02:00
"""""""""
" Plugin"
"""""""""
2018-03-27 14:03:57 +02:00
" for autotags plugin
let g:autotags_pycscope_cmd = '/usr/local/bin/pycscope'
2014-04-07 16:29:15 +02:00
"Using vundle
"cf. https://github.com/gmarik/Vundle.vim
":PluginInstall to install them
2014-06-06 11:53:43 +02:00
set rtp+=~/.vim/bundle/Vundle.vim/
call vundle#begin()
2014-04-07 16:29:15 +02:00
" let Vundle manage Vundle, required
2015-06-05 16:40:47 +02:00
Plugin 'gmarik/Vundle.vim'
2014-04-07 16:29:15 +02:00
2015-07-07 14:15:38 +02:00
" Show current modified line
2014-04-07 16:29:15 +02:00
Plugin 'airblade/vim-gitgutter'
2015-07-07 14:15:38 +02:00
" Communication with git
2014-04-07 16:29:15 +02:00
Plugin 'tpope/vim-fugitive'
2015-12-15 11:29:21 +01:00
" Support for Gbrowse
Plugin 'tpope/vim-rhubarb'
2015-07-07 14:15:38 +02:00
" Comment block of code
2014-08-13 13:39:55 +02:00
Plugin 'tpope/vim-commentary'
2015-12-08 14:59:32 +01:00
" Make terminal vim and tmux work better together.
Plugin 'tmux-plugins/vim-tmux-focus-events'
2014-08-13 13:39:55 +02:00
" language pack
Plugin 'sheerun/vim-polyglot'
" color even for terminal without gui...
" Plugin 'vim-scripts/CSApprox'
2014-04-08 14:26:26 +02:00
" Same as gitgutter but for other cvs
"Plugin mhinz/vim-signify
2014-04-07 16:29:15 +02:00
2015-07-06 13:56:02 +02:00
" echofunc -> what is the current function
Plugin 'mbbill/echofunc'
2014-08-13 13:39:55 +02:00
" What to test some color ?
Plugin 'vim-scripts/Colour-Sampler-Pack.git'
2015-07-06 14:15:29 +02:00
"More VCS Management
Plugin 'vim-scripts/vcscommand.vim'
2014-08-13 13:39:55 +02:00
" More Snippets :
Plugin 'tomtom/tlib_vim'
Plugin 'MarcWeber/vim-addon-mw-utils'
Plugin 'honza/vim-snippets'
Plugin 'garbas/vim-snipmate'
2014-08-13 13:39:55 +02:00
2015-07-06 14:26:11 +02:00
" Filesystem exploration
Plugin 'scrooloose/nerdtree'
2014-06-06 11:53:43 +02:00
" Python completion
"Plugin 'klen/python-mode'
"" Python Bundle
"Plugin 'davidhalter/jedi-vim'
"Plugin 'scrooloose/syntastic'
"Plugin 'majutsushi/tagbar'
"Plugin 'Yggdroot/indentLine'
" Omni completion for cpp
Plugin 'vim-scripts/OmniCppComplete'
2015-07-07 14:15:38 +02:00
" List current file function
2016-03-02 17:32:37 +01:00
" let $GIT_SSL_NO_VERIFY = 'true'
Plugin 'gitlab@gitlab.mathux.org:Mathieu/taglist.git'
" Tagbar look like a maintened taglist
Plugin 'majutsushi/tagbar'
2015-07-07 14:15:38 +02:00
2017-08-16 14:14:28 +02:00
if v:version >= 800
" Async lint
Plugin 'w0rp/ale'
else
"Syntax checking | Install flake8 or pylint for python
2018-03-01 16:39:58 +01:00
" Install shellcheck for bash
2017-08-16 14:14:28 +02:00
Plugin 'vim-syntastic/syntastic'
let g:syntastic_c_checkers = ['gcc', 'cppcheck']
2018-03-01 16:39:58 +01:00
"let g:syntastic_cpp_compiler = 'clang++'
"let g:syntastic_cpp_compiler_options = '-std=c++14'
2017-08-16 14:14:28 +02:00
endif
"Completion (need more configuration for python, c# ...)
"Plugin 'Valloric/YouCompleteMe'
2014-06-06 11:53:43 +02:00
" VimWiki
Plugin 'vimwiki/vimwiki'
let g:vimwiki_list=[{'path':'~/.vim/vimwiki'}]
2014-11-16 23:39:34 +01:00
" Align
" eg. to align on the "=" do :'<,'>Align =
Plugin 'vim-scripts/Align'
" open file at the given line with the file.txt:20 syntax
" But it's screw up the git commit message
"Plugin 'bogado/file-line'
2015-09-02 10:35:23 +02:00
2015-12-07 12:05:07 +01:00
" % match if/then/else/html ...
Plugin 'tmhedberg/matchit'
2015-09-02 10:35:23 +02:00
" Kernel Formatting
Plugin 'gregkh/kernel-coding-style.git'
2016-06-03 11:02:06 +02:00
" Web browsing
2016-09-26 13:50:15 +02:00
"Plugin 'yuratomo/w3m.vim'
2016-09-01 10:11:55 +02:00
" Recognize Key in screen/tmux
2016-09-26 13:50:15 +02:00
"Plugin 'drmikehenry/vim-fixkey'
2016-10-17 11:35:57 +02:00
2017-08-16 14:14:28 +02:00
Plugin 'tpope/vim-surround'
" Maps ss to surround word. e.g. ss] to add [] around word
nmap ss ysiw
" Maps sl to surround line
nmap sl yss
" Surround Visual selection
vmap s S
2017-09-20 15:39:40 +02:00
"Grammar Checking
Plugin 'rhysd/vim-grammarous'
2017-08-16 14:14:28 +02:00
Plugin 'junegunn/goyo.vim'
2016-10-17 11:35:57 +02:00
"Complete delimiters
Plugin 'Raimondi/delimitMate.git'
2017-08-16 14:14:28 +02:00
Plugin 'Yggdroot/LeaderF'
2017-11-03 16:12:14 +01:00
"Vim session
Plugin 'tpope/vim-obsession'
Plugin 'mhinz/vim-startify'
let g:startify_commands = [
\ ['Plugin Update', 'PluginUpdate'],
\ ['Plugin Install', 'PluginInstall'],
\]
2017-11-06 10:50:41 +01:00
let g:startify_custom_header = []
2014-06-06 11:53:43 +02:00
call vundle#end()