Mercurial > dotfiles
view vim/vimrc @ 408:1da269c50dca
Fix python 2/3 loading order problem in Vim.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 10 Jan 2018 00:02:16 -0800 |
parents | c175fda4aa2e |
children | 63463782d1cd |
line wrap: on
line source
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " " Ludovic Chabant's ~/.vimrc " " http://ludovic.chabant.com " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Global Setup {{{ " Use Vim settings, rather then Vi settings (much better!). " This must be first, because it changes other options as a side effect. set nocompatible " Set a variable that says we already sourced this file, for those few " settings we don't want to re-apply. if exists('g:sourced_vimrc') let g:resourcing_vimrc = 1 endif let g:sourced_vimrc = 1 " Get the platform we're running on. if has("win32") || has("win64") || has("dos32") let s:vim_platform = "windows" let s:path_sep = "\\" else let s:vim_platform = "unix" let s:path_sep = '/' endif " Get our vim directory. let s:vim_home = expand("<sfile>:h") " Local pre-override. let s:local_vimrc_pre = s:vim_home.'/vimrc-local-pre' if filereadable(s:local_vimrc_pre) execute 'source' s:local_vimrc_pre endif " Make sure `filetype` stuff is turned off before loading Pathogen. syntax off filetype off " Disable some plugins. let g:pathogen_disabled = get(g:, 'pathogen_disabled', []) call add(g:pathogen_disabled, 'vimroom') call add(g:pathogen_disabled, 'minibufexpl') call add(g:pathogen_disabled, 'ragtag') call add(g:pathogen_disabled, 'interestingwords') " Load pathogen. runtime bundle/pathogen/autoload/pathogen.vim " Add the bundle directory, and potentially add the local one if it exists. " Note that we pass absolute paths to make pathogen prepend stuff before Vim's " system files otherwise stuff like indent plugins don't work. let s:pathogen_bundles = [s:vim_home.s:path_sep.'bundle'.s:path_sep.'{}'] if isdirectory(s:vim_home.s:path_sep.'local') call add(s:pathogen_bundles, s:vim_home.s:path_sep.'local'.s:path_sep.'{}') endif call call('pathogen#infect', s:pathogen_bundles) " Hide the toolbar in MacVim/gVIM, and set a nice window size. if has("gui_running") && !exists('g:resourcing_vimrc') set guioptions=-t set lines=999 set columns=999 if has("win32") au GUIEnter * simalt ~x endif endif " }}} " General Settings {{{ " Restrict modelines. set modelines=1 " Don't unload abandoned buffers. set hidden " Show line numbers. set number " Show what mode we're in, and what command we're typing. set showmode set showcmd " Keep the cursor off the top/bottom edges. set scrolloff=3 " Smart auto-indenting. set autoindent set smartindent " Use confirmation dialog. set confirm " Don't use annoying sounds. set visualbell " Remember lots of commands. set history=1000 " Try to reduce flickering. set lazyredraw " Show matching braces but not for too long. set showmatch set matchtime=2 " Show soft-broken/wrapped lines with a prefix. set showbreak=→ " Use incremental search, with highlighting, " case-insensitive unless we actually type some " mixed-case stuff. set incsearch set hlsearch set ignorecase set smartcase " Always show window status lines. set laststatus=2 " Enable using the mouse like some everyday guy. set mouse=a " Show interesting stuff at the bottom of the window. set showcmd set ruler " Make sure splitting windows is done in a way that makes sense. set splitbelow set splitright " Don't pollute the hard-drive with *~ files. Only " create them in hidden backup/temp directories while " we edit the file, and then get rid of it. set nobackup set writebackup execute('set backupdir='.s:vim_home.'/backup') execute('set directory='.s:vim_home.'/temp') " Better command-line completion, but don't show some " stuff we don't care about. set wildmenu set wildmode=list:longest set wildignore+=.DS_Store,Thumbs.db set wildignore+=*.so,*.dll,*.exe,*.lib,*.pdb set wildignore+=*.pyc,*.pyo set wildignore+=*.swp set formatoptions=croqn1 " Always display the tab-page line. set showtabline=2 " Set the file-formats. set ffs=unix,mac,dos " Tabs and indenting are 4 characters, and tabs behave like " spaces during editing. They're smart, too, and when you " press <TAB> it actually inserts a soft-tab so everything's " indented the same. set tabstop=4 set shiftwidth=4 set softtabstop=4 set smarttab set expandtab " Default encoding set encoding=utf-8 " Clipboard buffer. set clipboard=unnamed " Smooth terminal experience. set ttyfast " Allow backspacing over anything. set backspace=indent,eol,start " Going left and right let you go to other lines. set whichwrap+=<,>,h,l " How to show invisible characters set listchars=eol:$,tab:>-,trail:-,extends:>,precedes:<,nbsp:%,conceal:. " Nice auto-complete menu. set complete=.,w,b,u,t set completeopt=longest,menuone,preview " Column indicators. set colorcolumn=72,79 " And now, for some system-dependent settings: " - font to use if s:vim_platform == "windows" set guifont=Consolas:h12 else set guifont=Hack:h12,Monaco:h12 endif " Syntax highlighting. syntax on " Change the current directory to the home directory. if !exists('g:resourcing_vimrc') cd ~/ endif " Default color scheme. if has('gui_running') set background=dark else set background=dark let g:solarized_termcolors = 256 let g:solarized_termtrans = 1 endif colorscheme solarized " Enable file type detection. filetype indent plugin on " }}} " Auto-Commands {{{ " Only show the highlighted cursor line in the current window. augroup CursorLine au! au WinLeave * set nocursorline au WinEnter * set cursorline augroup END " }}} " Plugin Settings {{{ " NERDTree {{{ let NERDTreeRespectWildIgnore = 1 " }}} " Ctrl-P {{{ " We'll set our own mappings. let g:ctrlp_map = '' " Ctrl-P should manage the working directory. let g:ctrlp_working_path_mode = 'ra' " Ctrl-P should however ignore some stuff. let g:ctrlp_custom_ignore = { \ 'dir': '\v[\/](\.git|\.hg|\.svn|venv|static|node_modules|_cache|_counter)$' \ } " Make Ctrl-P cache stuff in our temp directory. let g:ctrlp_cache_dir = s:vim_home.'/cache' " Remember things. let g:ctrlp_clear_cache_on_exit = 0 " Don't include some stuff in the most recently used list. let g:ctrlp_mruf_exclude = 'hg\-editor\-\d+\.txt' " Enable some cool extensions. let g:ctrlp_extensions = [ \'tag', 'buffertag', 'quickfix', 'mixed', 'bookmarkdir', \'autoignore' \] " Use PyMatch to go faster. if has('python3') || has('python') let g:ctrlp_match_func = {'match': 'pymatcher#PyMatch'} let g:ctrlp_max_files = 0 let g:ctrlp_lazy_update = 350 endif " }}} " Gutentags {{{ let g:gutentags_cache_dir = s:vim_home.'/tags' let g:gutentags_ctags_exclude = ['venv', 'build', 'static', 'node_modules'] let g:gutentags_ctags_extra_args = ['--options='.s:vim_home.'/ctagsrc'] " }}} " Syntastic {{{ let g:syntastic_auto_loc_list = 2 let g:syntastic_check_on_open = 1 let g:syntastic_check_on_wq = 0 " flake8 includes pyflakes, pep8, and mccabe " I could maybe replace pyflakes with frosted? let g:syntastic_python_checkers = ['flake8'] ", 'pylint'] let g:syntastic_python_python_exec = 'python3' " }}} " Supertab {{{ let g:SuperTabDefaultCompletionType = "context" let g:SuperTabLongestEnhanced = 1 let g:SuperTabLongestHighlight = 0 let g:SuperTabCrMapping = 1 " }}} " Lawrencium {{{ " Custom Mercurial commands highlighting in Lawrencium. let g:lawrencium_hg_commands_file_types = { \'clog': 'hggraphlog' \} " Make the annotate window better in Lawrencium. let g:lawrencium_annotate_width_offset = 1 " }}} " Gundo {{{ let g:gundo_map_move_older = '<Down>' let g:gundo_map_move_newer = '<Up>' " }}} " YankRing {{{ let g:yankring_replace_n_pkey = '<C-K>' let g:yankring_replace_p_pkey = '<C-J>' " }}} " Python-Mode {{{ let g:pymode = 1 let g:pymode_python = 'python3' let g:pymode_syntax = 0 let g:pymode_syntax_all = 0 let g:pymode_syntax_builtin_objs = 1 let g:pymode_syntax_print_as_function = 1 let g:pymode_syntax_space_errors = 1 let g:pymode_indent = 0 let g:pymode_run = 0 let g:pymode_lint = 0 let g:pymode_trim_whitespaces = 0 let g:pymode_folding = 1 let g:pymode_doc = 1 let g:pymode_doc_bind = 'K' let g:pymode_virtualenv = 0 let g:pymode_rope = 0 " }}} " Lightline {{{ let g:lightline = { \'colorscheme': 'solarized', \'active': { \ 'left': [ ['mode', 'paste'], \ ['fugitive', 'lawrencium', 'readonly', 'relativepath', 'modified'], \ ['ctrlpmark'] ], \ 'right': [ ['lineinfo'], \ ['percent'], \ ['fileformat', 'fileencoding', 'filetype'], \ ['gutentags', 'syntastic', 'ycm_errs', 'ycm_warns'] ] \ }, \'component_function': { \ 'fugitive': '_LightlineFugitive', \ 'lawrencium': '_LightlineLawrencium', \ 'ctrlpmark': '_LightlineCtrlPMark', \ }, \'component_expand': { \ 'syntastic': '_LightlineSyntastic', \ 'ycm_errs': '_LightlineYcmErrors', \ 'ycm_warns': '_LightlineYcmWarnings', \ 'gutentags': '_LightlineGutentags', \ }, \'component_type': { \ 'syntastic': 'error', \ 'ycm_errs': 'error', \ 'ycm_warns': 'warning', \ 'gutentags': 'warning', \ }, \} function! _LightlineFugitive() return fugitive#head() endfunction function! _LightlineLawrencium() return lawrencium#statusline() endfunction function! _LightlineCtrlPMark() if expand('%:t') =~ 'ControlP' && has_key(g:lightline, 'ctrlp_item') call lightline#link('iR'[g:lightline.ctrlp_regex]) return lightline#concatenate( \['WAT?', g:lightline.ctrlp_prev, \ g:lightline.ctrlp_item, \ g:lightline.ctrlp_next], \0) else return '' endif endfunction function! _LightlineGutentags() return gutentags#statusline() endfunction function! _LightlineSyntastic() return SyntasticStatuslineFlag() endfunction function! _LightlineYcmErrors() let l:cnt = youcompleteme#GetErrorCount() return l:cnt > 0 ? string(l:cnt) : '' endfunction function! _LightlineYcmWarnings() let l:cnt = youcompleteme#GetWarningCount() return l:cnt > 0 ? string(l:cnt) : '' endfunction " }}} " YouCompleteMe {{{ let g:ycm_always_populate_location_list = 1 " }}} " }}} " File-Specific Settings {{{ augroup VimRCFileType_markdown au! autocmd FileType text,markdown setlocal textwidth=80 autocmd FileType markdown nnoremap <buffer> <localleader>1 yypVr=:redraw<cr> autocmd FileType markdown nnoremap <buffer> <localleader>2 yypVr-:redraw<cr> autocmd FileType markdown nnoremap <buffer> <localleader>3 mzI###<space><esc>`z4l autocmd FileType markdown nnoremap <buffer> <localleader>4 mzI####<space><esc>`z5l autocmd BufRead,BufNewfile */Dropbox/Personal/SimpleNote/* set ft=markdown autocmd BufRead,BufNewFile */_content/**/*.html set ft=piecrustmarkdown augroup END augroup VimRCFileType_php au! " Who the hell changes my matchpairs? autocmd FileType php setlocal matchpairs-=<:> augroup END augroup VimRCFileType_c au! autocmd FileType c,c++,cpp,cs setlocal foldmethod=syntax autocmd FileType c,c++,cpp,cs setlocal colorcolumn=120 augroup END augroup VimRCFileType_css au! autocmd BufNewFile,BufRead *.less setlocal filetype=less autocmd Filetype less,css setlocal foldmethod=marker autocmd Filetype less,css setlocal foldmarker={,} autocmd Filetype less,css setlocal iskeyword+=- autocmd Filetype less,css setlocal omnifunc=csscomplete#CompleteCSS augroup END augroup VimRCTrailingWhitespaces au! autocmd FileType php,ruby,python,js,css,less autocmd BufWritePre <buffer> :call <SID>StripTrailingWhitespaces() augroup END " }}} " Mappings {{{ let mapleader="," " Visual line navigation noremap <up> g<up> noremap <down> g<down> noremap <home> g<home> noremap <end> g<end> noremap <S-up> 20<up> noremap <S-down> 20<down> " Tab navigation noremap <C-Tab> :tabnext<cr> noremap <C-S-Tab> :tabprevious<cr> nnoremap <leader>t :tabnew<cr> " Window navigation nnoremap <C-up> :wincmd k<cr> nnoremap <C-down> :wincmd j<cr> nnoremap <C-left> :wincmd h<cr> nnoremap <C-right> :wincmd l<cr> " Switch buffers. nnoremap <F2> :execute ("buffer " . bufname("#"))<cr> " NERDTree. nnoremap <F3> :call <SID>ToggleNERDTree()<cr> nnoremap <F4> :call <SID>FindInNERDTree()<cr> " Tagbar. nnoremap <F5> :TagbarToggle<cr> nnoremap <F6> :TagbarOpenAutoClose<cr> " Gundo. nnoremap <F7> :GundoToggle<cr> " Common typos. nnoremap ; : " Split windows nnoremap <leader>s :split<cr> nnoremap <leader>v :vsplit<cr> " Easier things to type nnoremap <leader>w :w<cr> nnoremap <leader>q :q<cr> nnoremap <leader>hh :Hg nnoremap <leader>hg :Hg! nnoremap <leader>hs :Hgstatus<cr> nnoremap <leader>hv :Hgvdiff<cr> " Make the hash-key not suck. inoremap # X<BS># " Toggle invisible characters nnoremap <leader>i :set list!<cr> " Clear search matches nnoremap <leader><space> :noh<cr>:call clearmatches()<cr> " Ctrl-P mappings. nnoremap <silent> <C-p> :CtrlP<cr> nnoremap <silent> <C-o> :CtrlPBuffer<cr> nnoremap <silent> <C-u> :CtrlPTag<cr> nnoremap <silent> <C-y> :CtrlPBufTag<cr> nnoremap <silent> <Tab> :CtrlPMRUFiles<cr> nnoremap <silent> <F8> :CtrlPBookmarkDir<cr> " Switch between FR and US keyboard layouts. nnoremap <C-l>f :setlocal keymap=french<cr> nnoremap <C-l>u :setlocal keymap=<cr> " Toggle spell check according to current keyboard layout. nnoremap <C-l>s :call <SID>ToggleSpellCheck()<cr> " Simple way to close a buffer without closing the window. nnoremap <leader>d :bprevious<cr>:bdelete #<cr> " Use sane regexes. nnoremap / /\v vnoremap / /\v " Next/previous quickfix and location messages. " This is meant to be similar to ]c and [c for the diff navigation. nnoremap ]q :cnext<cr>zvzz nnoremap [q :cprevious<cr>zvzz nnoremap ]l :lnext<cr>zvzz nnoremap [l :lprevious<cr>zvzz " Same with change and jump lists. nnoremap ]e g,zz nnoremap [e g;zz nnoremap ]j <C-I> nnoremap [j <C-O> " Copy the current buffer's info. nnoremap <leader>cp :let @+ = expand('%:p')<cr>:echo @+<cr> nnoremap <leader>cf :let @+ = expand('%:h')<cr>:echo @+<cr> nnoremap <leader>cw :let @+ = getcwd()<cr>:echo @+<cr> " Make the diff navigation also center things. nnoremap ]c ]czvzz nnoremap [c [czvzz " Quick search and replace. function! s:VSetSearch() let temp = @@ norm! gvy let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g') let @@ = temp endfunction vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR><c-o> vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR><c-o> nnoremap <leader>fa :vimgrep /<C-R><C-W>/ vnoremap <leader>fa "zy:vimgrep /<C-R>z/ " Jump to tags by keeping things better in view. Option for jumping to a tag " in a split window where everything is folded except what you need to see. " Note that if a tag search yield multiple possible results, we will still run " some of that `zvzz` stuff, but that's OK, the main point is to not mess up " the result selection window either. nnoremap <F9> :pop<cr> nnoremap <F10> g<C-]>zvzz nnoremap <s-F10> <c-w>vg<C-]>zMzvzz nnoremap <c-F9> :tprevious nnoremap <c-F10> :tnext " Keep search matches in the middle of the window. nnoremap n nzvzz nnoremap N Nzvzz " YCM mappings. nnoremap <Leader>jj :YcmCompleter GoToImprecise<cr>zv nnoremap <Leader>jd :YcmCompleter GoToDefinition<cr>zv nnoremap <Leader>jh :YcmCompleter GoToDeclaration<cr>zv nnoremap <Leader>ji :YcmCompleter GoToInclude<cr> nnoremap <Leader>jc :YcmCompleter GetDoc<cr> " }}} " Folding {{{ " Start with one level of open. set foldlevel=1 " Don't fold too much. set foldnestmax=2 " Folds are defined by markers in the text. set foldmethod=marker " Toggle folds with <space>. nnoremap <space> za " Create folds with <space> (in visual mode). vnoremap <space> zf " }}} " Abbreviations {{{ iabbrev @@ ludovic@chabant.com iabbrev ccopy Copyright ©2011 Ludovic Chabant, all rights reserved. iabbrev ssig --<cr>l u d o .<cr>. 8 0 17 80 " }}} " Functions {{{ function! s:ToggleSpellCheck() abort if &spell ==? 'nospell' if &keymap ==? 'french' setlocal spell spelllang=fr_fr else setlocal spell spelllang=en_us,en_ca endif else setlocal spell nospell endif endfunction function! s:StripTrailingWhitespaces() abort let l = line(".") let c = col(".") %s/\s\+$//e call cursor(l, c) endfunction function! s:ToggleNERDTree() abort NERDTreeToggle endfunction function! s:FindInNERDTree() abort NERDTreeFind normal zz endfunction " }}} " Local override {{{ let s:local_vimrc = s:vim_home.'/vimrc-local' if filereadable(s:local_vimrc) execute 'source' s:local_vimrc endif " }}}