[vim] vimrc overhaul

After learning a little of VimL, the vimrc file could be organized a bit
better. This should provide a better basis for future improvements.
This commit is contained in:
Fernando Schauenburg 2016-03-29 21:19:56 +02:00
parent 50feda4f85
commit 82058ae59d

242
vimrc
View file

@ -1,151 +1,107 @@
set nocompatible set nocompatible
let mapleader = ","
" Vim options {{{ " Options {{{
set background=dark " use dark background set autoindent
set backspace=indent,eol,start " allow backspace over everything set autoread
set clipboard=unnamed " use system clipboard for yank/put/delete let &background = $BACKGROUND ==# 'light' ? 'light' : 'dark'
set colorcolumn=80 " highlight column 80 set backspace=indent,eol,start
set cursorline " highlight current line set nobackup
set encoding=utf8 " use UTF-8 by default set clipboard=unnamed
set expandtab " expand <Tab> to spaces in Insert mode set colorcolumn=80
set foldenable " enable folding set cursorline
set foldlevelstart=100 " open all folds when opening set encoding=utf8
set foldmethod=syntax " fold based on syntax by default set expandtab
set foldnestmax=10 " avoid folds too deeply nested set foldenable
set formatoptions-=t " don't auto wrap when typing set foldlevelstart=100
set hidden " allow switch away from buffer w/o writing set foldmethod=syntax
set history=1000 " remember 1000 commnand lines set foldnestmax=10
set hlsearch " highlight matches for last search pattern set formatoptions-=t
set incsearch " show match for partly typed search command set hidden
set laststatus=2 " always show the status line set history=1000
set lazyredraw " don't redraw when executing macros set hlsearch
set listchars=tab:▸\ ,trail,eol set incsearch
set nobackup " don't keep a backup after overwriting a file set laststatus=2
set noshowmode " hide mode since it's shown in airline set lazyredraw
set noswapfile " don't use swap files set listchars=tab:\ ,trail
set number " show line numbers set number
set scrolloff=7 " number of screen lines to show around the cursor set scrolloff=5
set shiftwidth=4 " number of spaces used for each step of (auto)indent set shiftwidth=4
set showmatch " show matching brackets let &showbreak = '↪ '
set smartindent " do clever autoindenting set showmatch
set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces set noshowmode
set splitbelow " new horizontal splits go below current set sidescrolloff=5
set splitright " new vertical splits to the right of current set nrformats-=octal
set tabstop=4 " number of spaces a <Tab> in the text stands for set smartindent
set textwidth=79 " break lines at 79 characters set smarttab
set timeoutlen=1000 " timeout of 1s for key combinations set splitbelow
set ttimeoutlen=100 " timeout of 100ms for <esc> set splitright
set ttyfast " fast terminal connection set noswapfile
set tabstop=4
set textwidth=79
set timeoutlen=1000
set ttimeoutlen=100
set ttyfast
set wildignore=*.o,*.obj,*.pyc,*.exe,*.so,*.dll set wildignore=*.o,*.obj,*.pyc,*.exe,*.so,*.dll
set wildmenu " enhanced command-line completion set wildmenu
set wrap " wrap long lines set wrap
set writebackup " make a backup before writing a file set writebackup
if has('multi_byte')
let &showbreak='↳'
else
let &showbreak=' '
endif
" }}} " }}}
" Plugins {{{ " Plugins {{{
filetype off filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#rc()
Plugin 'altercation/vim-colors-solarized' Plugin 'altercation/vim-colors-solarized'
Plugin 'benmills/vimux' Plugin 'benmills/vimux'
Plugin 'bling/vim-airline'
Plugin 'bronson/vim-trailing-whitespace' Plugin 'bronson/vim-trailing-whitespace'
Plugin 'kien/ctrlp.vim'
Plugin 'majutsushi/tagbar'
Plugin 'scrooloose/nerdtree'
Plugin 'davidoc/taskpaper.vim' Plugin 'davidoc/taskpaper.vim'
Plugin 'scrooloose/syntastic'
Plugin 'tpope/vim-endwise'
Plugin 'tpope/vim-commentary'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-surround'
Plugin 'terryma/vim-multiple-cursors'
Plugin 'junegunn/vim-easy-align'
Plugin 'junegunn/rainbow_parentheses.vim'
Plugin 'elzr/vim-json' Plugin 'elzr/vim-json'
Plugin 'godlygeek/tabular' " must come before vim-markdown Plugin 'godlygeek/tabular' " must come before vim-markdown
Plugin 'gmarik/Vundle.vim'
Plugin 'junegunn/rainbow_parentheses.vim'
Plugin 'junegunn/vim-easy-align'
Plugin 'kien/ctrlp.vim'
Plugin 'majutsushi/tagbar'
Plugin 'plasticboy/vim-markdown' Plugin 'plasticboy/vim-markdown'
Plugin 'scrooloose/nerdtree'
Plugin 'tpope/vim-commentary'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
call vundle#end()
filetype plugin indent on filetype plugin indent on
syntax enable syntax enable
" ctrlp {{{
let g:ctrlp_match_window = 'bottom,order:ttb' let g:ctrlp_match_window = 'bottom,order:ttb'
let g:ctrlp_switch_buffer = 0 " open files in new buffer let g:ctrlp_switch_buffer = 0 " open files in new buffer
let g:ctrlp_working_path_mode = 0 " use the current working directory let g:ctrlp_working_path_mode = 0 " use the current working directory
" }}}
" nerdtree {{{
nmap <leader>n :NERDTreeToggle<cr>
" }}}
" rainbow_parentheses {{{
let g:rainbow#pairs = [['(',')'], ['[',']'], ['{','}']] let g:rainbow#pairs = [['(',')'], ['[',']'], ['{','}']]
nnoremap <leader>r :RainbowParentheses!!<cr> " toggle rainbow parens
" }}}
" tagbar {{{ highlight link taskpaperDone Comment
nnoremap <leader>g :TagbarToggle<cr> highlight link taskpaperCancelled Comment
" }}} highlight link taskpaperComment Normal
" taskpaper {{{
" relink some of the default highlight groups for visual improvement
hi link taskpaperDone Comment
hi link taskpaperCancelled Comment
hi link taskpaperComment Normal
" }}}
" vim-airline {{{
let g:airline_theme="solarized" let g:airline_theme="solarized"
let g:airline_powerline_fonts = 1 let g:airline_powerline_fonts = 1
" }}}
" vim-colors-solarized {{{
if $BACKGROUND == 'light' " use background from bash if available
set background=light
else
set background=dark " default is dark
endif
silent! colorscheme solarized silent! colorscheme solarized
" }}} " }}}
" vim-trailing-whitespace {{{ " Mappings {{{
nnoremap <leader>w :FixWhitespace<cr> let mapleader = "\<space>"
" }}} let maplocalleader = ","
" vim-easy-align {{{ " Start interactive EasyAlign
nmap ga <Plug>(EasyAlign)
xmap ga <Plug>(EasyAlign) xmap ga <Plug>(EasyAlign)
xmap ga <Plug>(EasyAlign)
" }}}
" }}}
augroup vimrc " {{{ " better navigation for wrapped lines
autocmd! noremap j gj
au BufNewFile,BufRead bash_profile,bashrc set ft=sh noremap k gk
au BufNewFile,BufRead gitconfig set ft=gitconfig
au BufNewFile,BufRead rcrc set ft=sh
au FileType vim setl foldmethod=marker " quickly exit insert mode
au FileType python setl foldmethod=indent inoremap jk <esc>
au FileType markdown,text setl formatoptions+=t | setl spell
au FileType gitcommit setl formatoptions+=t | setl spell | setl textwidth=72
augroup END " }}}
" Key mappings {{{
" window resizing similar to the way I have tmux set up
nnoremap <c-w><c-k> 5<c-w>+
nnoremap <c-w><c-j> 5<c-w>-
nnoremap <c-w><c-h> 5<c-w><
nnoremap <c-w><c-l> 5<c-w>>
" retain selection when indenting/unindenting in visual mode " retain selection when indenting/unindenting in visual mode
vnoremap > ><cr>gv vnoremap > ><cr>gv
@ -155,30 +111,48 @@ augroup END " }}}
nnoremap // /\c nnoremap // /\c
nnoremap ?? ?\c nnoremap ?? ?\c
" quickly exit insert mode " window resizing similar to the way I have tmux set up
inoremap jk <esc> nnoremap <c-w><c-k> 5<c-w>+
nnoremap <c-w><c-j> 5<c-w>-
nnoremap <c-w><c-h> 5<c-w><
nnoremap <c-w><c-l> 5<c-w>>
" better navigation for wrapped lines " easier tab navigation
noremap j gj nnoremap <c-j> :tabprevious<cr>
noremap k gk nnoremap <c-k> :tabnext<cr>
nnoremap <c-h> :tabfirst<cr>
" space opens/closes folds nnoremap <c-l> :tablast<cr>
nnoremap <space> za
" turn off search highlight
nnoremap <leader><leader> :nohlsearch<cr>
" switch between last two files
nnoremap <leader><space> <c-^>
" quickly change background " quickly change background
nnoremap <leader>bd :set background=dark<cr> nnoremap <leader>bg
nnoremap <leader>bl :set background=light<cr> \ :let &background = &background ==# 'light' ? 'dark' : 'light'<cr>
" Execute macro in q " toggle tagbar
nnoremap Q @q nnoremap <leader>g :TagbarToggle<cr>
" }}}
if filereadable(expand("~/.vimrc.local")) " turn off search highlight
source ~/.vimrc.local nnoremap <leader>h :nohlsearch<cr>
endif
" toggle NERDTree
nnoremap <leader>n :NERDTreeToggle<cr>
" toggle rainbow parens
nnoremap <leader>r :RainbowParentheses!!<cr>
" fix whitespace
nnoremap <leader>w :FixWhitespace<cr>
" }}}"
augroup vimrc " {{{
autocmd!
autocmd BufNewFile,BufRead bash_profile,bashrc set filetype=sh
autocmd BufNewFile,BufRead gitconfig set filetype=gitconfig
autocmd BufNewFile,BufRead rcrc set filetype=sh
autocmd FileType vim setlocal foldmethod=marker
autocmd FileType python setlocal foldmethod=indent foldignore=
autocmd FileType markdown,text,gitcommit setlocal formatoptions+=t spell
autocmd FileType gitcommit setlocal textwidth=72
augroup END " }}}
if filereadable(expand("~/.vimrc.local")) | source ~/.vimrc.local | endif