My .vimrc
" vim: fdm=marker ts=2 sts=2 sw=2 fdl=0
" Variables {{{
let mapleader = "\<Space>"
let s:is_windows = has('win32') || has('win64')
let s:is_nvim = has('nvim')
"}}}
" Setting up vim-plug as the package manager {{{
if !filereadable(expand("~/.vim/autoload/plug.vim"))
echo "Installing vim-plug and plugins. Restart vim after finishing the process."
silent call mkdir(expand("~/.vim/autoload", 1), 'p')
execute "!curl -fLo ".expand("~/.vim/autoload/plug.vim", 1)." https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
autocmd VimEnter * PlugInstall
endif
if s:is_windows
set rtp+=~/.vim
endif
call plug#begin('~/.vim/plugged')
let g:plug_url_format = 'https://github.com/%s.git'
"}}}
" Plugin settings {{{
Plug 'haya14busa/incsearch.vim' "{{{
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
"}}}
Plug 'konfekt/fastfold'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'raimondi/delimitmate' "{{{
let delimitMate_expand_cr = 1
"}}}
Plug 'terryma/vim-multiple-cursors' "{{{
let g:multi_cursor_exit_from_insert_mode = 0
"}}}
Plug 'sirver/ultisnips', { 'on': [] } "{{{
let g:UltiSnipsSnippetsDir = '~/.vim/plugged/vim-snippets/UltiSnips'
let g:UltiSnipsExpandTrigger="<c-j>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-k>"
let g:UltiSnipsListSnippets="<c-l>"
inoremap <silent> <C-j> <C-r>=LoadUltiSnips()<cr>
" This function only runs when UltiSnips is not loaded
function! LoadUltiSnips()
let l:curpos = getcurpos()
execute plug#load('ultisnips')
call cursor(l:curpos[1], l:curpos[2])
call UltiSnips#ExpandSnippet()
return ""
endfunction
"}}}
Plug 'saaguero/vim-snippets'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } "{{{
nnoremap <silent> <F4> :NERDTreeToggle<CR>
nnoremap <silent> <F5> :NERDTreeFind<CR>
"}}}
Plug 'sjl/badwolf'
Plug 'morhetz/gruvbox'
Plug 'bling/vim-airline'
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
Plug 'vasconcelloslf/vim-interestingwords'
Plug 'kien/ctrlp.vim' "{{{
nnoremap <leader>e :CtrlP<cr>
nnoremap <leader>E :CtrlPMRUFiles<cr>
nnoremap <leader>a :CtrlPBuffer<cr>
nnoremap <leader>A :CtrlPCurFile<cr>
nnoremap <leader>t :CtrlPBufTag<cr>
nnoremap <leader>T :CtrlPTag<cr>
nnoremap <leader>r :CtrlPRTS<cr>
call plug#end()
"}}}
" Vim sensible settings {{{
set nocompatible
set encoding=utf-8
set listchars=trail:.,tab:>\ ,eol:$
set lazyredraw
set laststatus=2
set statusline=%-4m%f\ %y\ \ %=%{&ff}\ \|\ %{&fenc}\ [%l:%c]
set incsearch hlsearch
set number
set backspace=indent,eol,start
set nostartofline
set autoread
set scrolloff=3
set wildmenu wildignorecase wildmode=list:longest,full
set cursorline
set ignorecase smartcase
set showmode showcmd
set shortmess+=I
set hidden
set history=1000
set complete-=i completeopt=menu
set splitright splitbelow
set display+=lastline
set foldenable foldmethod=syntax foldlevelstart=99
set ttimeoutlen=50
set switchbuf=useopen
set mouse=a
set breakindent
filetype plugin indent on
syntax on
" better backup, swap and undo storage {{{
set noswapfile
set backup
set undofile
set backupdir=~/.vim/dirs/backup
set undodir=~/.vim/dirs/undo
if !isdirectory(&backupdir)
call mkdir(&backupdir, "p")
endif
if !isdirectory(&undodir)
call mkdir(&undodir, "p")
endif
"}}}
"}}}
" GUI & Terminal setttings {{{
if has("gui_running")
if has("gui_macvim")
set guifont=Consolas:h15
elseif has("gui_win32")
autocmd GUIEnter * simalt ~x " open maximize in Windows
set guifont=Consolas:h11
endif
set guioptions= " disable all UI options
set guicursor+=a:blinkon0 " disable blinking cursor
set ballooneval
autocmd GUIEnter * set visualbell t_vb=
else
set noerrorbells visualbell t_vb=
if !s:is_nvim
set term=xterm
endif
set t_ut= " setting for looking properly in tmux
set t_ti= t_te= " prevent vim from clobbering the scrollback buffer
let &t_Co = 256
if s:is_windows " trick to support 256 colors and scroll in conemu
let &t_AF="\e[38;5;%dm"
let &t_AB="\e[48;5;%dm"
inoremap <esc>[62~ <c-x><c-e>
inoremap <esc>[63~ <c-x><c-y>
nnoremap <esc>[62~ 3<c-e>
nnoremap <esc>[63~ 3<c-y>
endif
endif
colorscheme gruvbox
set bg=dark
"}}}
" Spaces and Filetype settings {{{
set autoindent
set expandtab smarttab
set tabstop=4 softtabstop=4 shiftwidth=4
augroup CustomFiletype
autocmd!
autocmd BufNewFile,BufRead *.html set filetype=html.htmldjango
autocmd BufNewFile,BufRead *.wxs set filetype=wxs.xml
autocmd BufNewFile,BufRead *.wxi set filetype=wxi.xml
autocmd BufNewFile,BufRead *.md set filetype=markdown
autocmd BufNewFile,BufRead *.gradle set filetype=groovy
autocmd FileType html,xml,javascript,json set tabstop=2 softtabstop=2 shiftwidth=2
autocmd FileType python,vim setlocal foldmethod=indent
autocmd FileType vim setlocal keywordprg=:help omnifunc=syntaxcomplete#Complete
autocmd Filetype text setlocal textwidth=80
augroup END
"}}}
" Custom utils/mappings {{{
" rsi mappings
inoremap <C-a> <Home>
cnoremap <C-a> <Home>
inoremap <C-e> <End>
cnoremap <C-e> <End>
" Filter command history the same way as <Up> <Down> do
cnoremap <C-p> <Up>
cnoremap <C-n> <Down>
" avoid common typos
command! -bang Q q<bang>
command! -bang W w<bang>
" replace ex mode map and use it for repeating 'q' macro
nnoremap Q @q
" save as sudo
cabbrev w!! w !sudo tee "%"
" easy system clipboard copy/paste
noremap <Leader>y "*y
noremap <Leader>Y "*Y
noremap <Leader>p "*p
noremap <Leader>P "*P
" copy full file path to clipboard
nnoremap <silent><Leader>gp :let @+ = expand("%:p")<cr>
" easy window navigation
nnoremap <silent> <c-l> <c-w>l
nnoremap <silent> <c-j> <c-w>j
nnoremap <silent> <c-h> <c-w>h
nnoremap <silent> <c-k> <c-w>k
nnoremap <silent> <leader>\ <c-^>
nnoremap <silent> <leader>q :botright copen<cr>
" easy terminal navigation (for nvim)
if s:is_nvim
tnoremap <esc><esc> <C-\><C-n>
endif
" cd to directory of current file
nnoremap <silent> <leader>cd :lcd %:p:h<CR>
augroup CustomUtils
autocmd!
" Open the file placing the cursor where it was
autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal! g'\"" | endif
" Use xmllint for xml formatting if availabe
if executable('xmllint')
autocmd FileType xml setlocal equalprg=xmllint\ --format\ --recover\ -\ 2>/dev/null
endif
" Close preview window when leaving insert mode http://stackoverflow.com/a/3107159/854676
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
augroup END
" clear the search buffer when hitting return
nnoremap <silent> <leader><cr> :nohlsearch<cr>
" Use Ag as default grep if available
if executable('ag')
set grepprg=ag\ --nogroup\ --nocolor\ --column
set grepformat=%f:%l:%c:%m
command! -nargs=+ -bang Ag silent! grep! <args> | redraw! | botright copen
endif
" source private vimrc file if available
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif
"}}}