486 lines
14 KiB
VimL
486 lines
14 KiB
VimL
|
"
|
||
|
" Basics
|
||
|
"
|
||
|
set nocompatible " be iMproved, required
|
||
|
filetype off " required
|
||
|
filetype plugin indent on " required
|
||
|
|
||
|
"
|
||
|
" Install plugins
|
||
|
"
|
||
|
call plug#begin('~/.vim/vimplug-plugins')
|
||
|
Plug 'Raimondi/delimitMate' " Autoclose quotes, parenthesis, brackets, etc.
|
||
|
Plug 'airblade/vim-gitgutter' " Git-indicators on the left
|
||
|
Plug 'altercation/vim-colors-solarized' " Colortheme
|
||
|
Plug 'dhruvasagar/vim-table-mode' " Nice ascii tables
|
||
|
Plug 'itchyny/lightline.vim' " Status-line
|
||
|
Plug 'junegunn/vim-easy-align' " Align at any chars
|
||
|
Plug 'ntpeters/vim-better-whitespace' " Complain on evil eol whitespace
|
||
|
Plug 'scrooloose/nerdtree' " Nerdtree...
|
||
|
Plug 'tpope/vim-fugitive' " git integration
|
||
|
call plug#end()
|
||
|
|
||
|
|
||
|
"
|
||
|
" Settings
|
||
|
"
|
||
|
set noerrorbells " No beeps
|
||
|
set number " Show line numbers
|
||
|
set backspace=indent,eol,start " Makes backspace key more powerful.
|
||
|
set showcmd " Show me what I'm typing
|
||
|
set showmode " Show current mode.
|
||
|
|
||
|
set noswapfile " Don't use swapfile
|
||
|
set nobackup " Don't create annoying backup files
|
||
|
set nowritebackup
|
||
|
set splitright " Split vertical windows right to the current windows
|
||
|
set splitbelow " Split horizontal windows below to the current windows
|
||
|
set encoding=utf-8 " Set default encoding to UTF-8
|
||
|
set autowrite " Automatically save before :next, :make etc.
|
||
|
set autoread " Automatically reread changed files without asking me anything
|
||
|
set laststatus=2
|
||
|
set hidden
|
||
|
|
||
|
set ruler " Show the cursor position all the time
|
||
|
au FocusLost * :wa " Set vim to save the file on focus out.
|
||
|
|
||
|
set fileformats=unix,dos,mac " Prefer Unix over Windows over OS 9 formats
|
||
|
|
||
|
set showmatch " Show matching brackets by flickering
|
||
|
set noshowmode " We show the mode with airlien or lightline
|
||
|
set incsearch " Shows the match while typing
|
||
|
set hlsearch " Highlight found searches
|
||
|
set ignorecase " Search case insensitive...
|
||
|
set smartcase " ... but not when search pattern contains upper case characters
|
||
|
set ttyfast
|
||
|
set lazyredraw " Wait to redraw "
|
||
|
|
||
|
" speed up syntax highlighting
|
||
|
set nocursorcolumn
|
||
|
set nocursorline
|
||
|
|
||
|
syntax sync minlines=256
|
||
|
set synmaxcol=300
|
||
|
set re=1
|
||
|
|
||
|
" open help vertically
|
||
|
command! -nargs=* -complete=help Help vertical belowright help <args>
|
||
|
autocmd FileType help wincmd L
|
||
|
|
||
|
" Make Vim to handle long lines nicely.
|
||
|
set wrap
|
||
|
set textwidth=79
|
||
|
set formatoptions=qrn1
|
||
|
|
||
|
" mail line wrapping
|
||
|
au BufRead /tmp/mutt-* set tw=72
|
||
|
|
||
|
set autoindent
|
||
|
set complete-=i
|
||
|
set smarttab
|
||
|
|
||
|
set tabstop=4
|
||
|
set shiftwidth=4
|
||
|
set expandtab
|
||
|
|
||
|
set nrformats-=octal
|
||
|
set shiftround
|
||
|
|
||
|
|
||
|
" Time out on key codes but not mappings.
|
||
|
" Basically this makes terminal Vim work sanely.
|
||
|
set notimeout
|
||
|
set ttimeout
|
||
|
set ttimeoutlen=10
|
||
|
|
||
|
" Different Cursorshapes for the modes
|
||
|
let &t_SI = "\<Esc>[6 q"
|
||
|
let &t_SR = "\<Esc>[4 q"
|
||
|
let &t_EI = "\<Esc>[2 q"
|
||
|
|
||
|
" Better Completion
|
||
|
set complete=.,w,b,u,t
|
||
|
set completeopt=longest,menuone
|
||
|
|
||
|
if &history < 1000
|
||
|
set history=50
|
||
|
endif
|
||
|
|
||
|
if &tabpagemax < 50
|
||
|
set tabpagemax=50
|
||
|
endif
|
||
|
|
||
|
if !empty(&viminfo)
|
||
|
set viminfo^=!
|
||
|
endif
|
||
|
|
||
|
if !&scrolloff
|
||
|
set scrolloff=1
|
||
|
endif
|
||
|
if !&sidescrolloff
|
||
|
set sidescrolloff=5
|
||
|
endif
|
||
|
set display+=lastline
|
||
|
|
||
|
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
|
||
|
" so that you can undo CTRL-U after inserting a line break.
|
||
|
inoremap <C-U> <C-G>u<C-U>
|
||
|
|
||
|
" Only do this part when compiled with support for autocommands.
|
||
|
if has("autocmd")
|
||
|
|
||
|
" Enable file type detection.
|
||
|
" Use the default filetype settings, so that mail gets 'tw' set to 72,
|
||
|
" 'cindent' is on in C files, etc.
|
||
|
" Also load indent files, to automatically do language-dependent indenting.
|
||
|
filetype plugin indent on
|
||
|
|
||
|
" Put these in an autocmd group, so that we can delete them easily.
|
||
|
augroup vimrcEx
|
||
|
au!
|
||
|
|
||
|
" For all text files set 'textwidth' to 78 characters.
|
||
|
autocmd FileType text setlocal textwidth=78
|
||
|
|
||
|
" 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).
|
||
|
" Also don't do it when the mark is in the first line, that is the default
|
||
|
" position when opening a file.
|
||
|
autocmd BufReadPost *
|
||
|
\ if line("'\"") > 1 && line("'\"") <= line("$") |
|
||
|
\ exe "normal! g`\"" |
|
||
|
\ endif
|
||
|
|
||
|
augroup END
|
||
|
else
|
||
|
endif " has("autocmd")
|
||
|
|
||
|
|
||
|
syntax enable
|
||
|
if has('gui_running')
|
||
|
"set transparency=3
|
||
|
" fix js regex syntax
|
||
|
set regexpengine=1
|
||
|
syntax enable
|
||
|
endif
|
||
|
" set background=dark # set by Xresources
|
||
|
let g:solarized_termcolors=256
|
||
|
let g:solarized_termtrans=1
|
||
|
" let g:hybrid_use_Xresources = 1
|
||
|
" let g:rehash256 = 1
|
||
|
colorscheme solarized
|
||
|
set guifont=Inconsolata:h15
|
||
|
set guioptions-=L
|
||
|
|
||
|
" This comes first, because we have mappings that depend on leader
|
||
|
" With a map leader it's possible to do extra key combinations
|
||
|
" i.e: <leader>w saves the current file
|
||
|
let mapleader = ","
|
||
|
let g:mapleader = ","
|
||
|
let maplocalleader = ";"
|
||
|
|
||
|
" This trigger takes advantage of the fact that the quickfix window can be
|
||
|
" easily distinguished by its file-type, qf. The wincmd J command is
|
||
|
" equivalent to the Ctrl+W, Shift+J shortcut telling Vim to move a window to
|
||
|
" the very bottom (see :help :wincmd and :help ^WJ).
|
||
|
autocmd FileType qf wincmd J
|
||
|
|
||
|
" Dont show me any output when I build something
|
||
|
" Because I am using quickfix for errors
|
||
|
"nmap <leader>m :make<CR><enter>
|
||
|
|
||
|
" Some useful quickfix shortcuts
|
||
|
":cc see the current error
|
||
|
":cn next error
|
||
|
":cp previous error
|
||
|
":clist list all errors
|
||
|
map <C-n> :cn<CR>
|
||
|
map <C-m> :cp<CR>
|
||
|
|
||
|
nnoremap <silent> <leader>q :Sayonara<CR>
|
||
|
|
||
|
" Replace the current buffer with the given new file. That means a new file
|
||
|
" will be open in a buffer while the old one will be deleted
|
||
|
com! -nargs=1 -complete=file Breplace edit <args>| bdelete #
|
||
|
|
||
|
function! DeleteInactiveBufs()
|
||
|
"From tabpagebuflist() help, get a list of all buffers in all tabs
|
||
|
let tablist = []
|
||
|
for i in range(tabpagenr('$'))
|
||
|
call extend(tablist, tabpagebuflist(i + 1))
|
||
|
endfor
|
||
|
|
||
|
"Below originally inspired by Hara Krishna Dara and Keith Roberts
|
||
|
"http://tech.groups.yahoo.com/group/vim/message/56425
|
||
|
let nWipeouts = 0
|
||
|
for i in range(1, bufnr('$'))
|
||
|
if bufexists(i) && !getbufvar(i,"&mod") && index(tablist, i) == -1
|
||
|
"bufno exists AND isn't modified AND isn't in the list of buffers open in windows and tabs
|
||
|
silent exec 'bwipeout' i
|
||
|
let nWipeouts = nWipeouts + 1
|
||
|
endif
|
||
|
endfor
|
||
|
echomsg nWipeouts . ' buffer(s) wiped out'
|
||
|
endfunction
|
||
|
|
||
|
command! Ball :call DeleteInactiveBufs()
|
||
|
|
||
|
" Toggle line numbers
|
||
|
nmap <leader>ll :set number!<cr>
|
||
|
nmap <leader>lr :set relativenumber!<cr>
|
||
|
|
||
|
" Close quickfix easily
|
||
|
nnoremap <leader>a :cclose<CR>
|
||
|
|
||
|
" Remove search highlight
|
||
|
nnoremap <leader><space> :nohlsearch<CR>
|
||
|
|
||
|
" Better split switching
|
||
|
map <C-j> <C-W>j
|
||
|
map <C-k> <C-W>k
|
||
|
map <C-h> <C-W>h
|
||
|
map <C-l> <C-W>l
|
||
|
|
||
|
" Center the screen
|
||
|
nnoremap <space> zz
|
||
|
|
||
|
" Move up and down on splitted lines (on small width screens)
|
||
|
map <Up> gk
|
||
|
map <Down> gj
|
||
|
map k gk
|
||
|
map j gj
|
||
|
|
||
|
nnoremap <F6> :setlocal spell! spell?<CR>
|
||
|
|
||
|
" Search mappings: These will make it so that going to the next one in a
|
||
|
" search will center on the line it's found in.
|
||
|
nnoremap n nzzzv
|
||
|
nnoremap N Nzzzv
|
||
|
|
||
|
"nnoremap <leader>. :lcd %:p:h<CR>
|
||
|
autocmd BufEnter * silent! lcd %:p:h
|
||
|
|
||
|
" trim all whitespaces away
|
||
|
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
|
||
|
|
||
|
" Do not show stupid q: window
|
||
|
map q: :q
|
||
|
|
||
|
" dont save .netrwhist history
|
||
|
let g:netrw_dirhistmax=0
|
||
|
|
||
|
" Allow saving of files as sudo when I forgot to start vim using sudo.
|
||
|
cmap w!! w !sudo tee > /dev/null %
|
||
|
|
||
|
" never do this again --> :set paste <ctrl-v> :set no paste
|
||
|
let &t_SI .= "\<Esc>[?2004h"
|
||
|
let &t_EI .= "\<Esc>[?2004l"
|
||
|
|
||
|
inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
|
||
|
|
||
|
function! XTermPasteBegin()
|
||
|
set pastetoggle=<Esc>[201~
|
||
|
set paste
|
||
|
return ""
|
||
|
endfunction
|
||
|
|
||
|
" set 80 character line limit
|
||
|
"if exists('+colorcolumn')
|
||
|
" set colorcolumn=80
|
||
|
"else
|
||
|
" au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
|
||
|
"endif
|
||
|
|
||
|
" ----------------------------------------- "
|
||
|
" File Type settings "
|
||
|
" ----------------------------------------- "
|
||
|
|
||
|
au BufNewFile,BufRead *.vim setlocal noet ts=4 sw=4 sts=4
|
||
|
au BufNewFile,BufRead *.txt setlocal noet ts=4 sw=4
|
||
|
au BufNewFile,BufRead *.md setlocal noet ts=4 sw=4
|
||
|
au BufNewFile,BufRead *.yml,*.yaml setlocal expandtab ts=2 sw=2
|
||
|
au BufNewFile,BufRead *.cpp setlocal expandtab ts=2 sw=2
|
||
|
au BufNewFile,BufRead *.hpp setlocal expandtab ts=2 sw=2
|
||
|
au BufNewFile,BufRead *.json setlocal expandtab ts=2 sw=2
|
||
|
|
||
|
augroup filetypedetect
|
||
|
au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux
|
||
|
au BufNewFile,BufRead .nginx.conf*,nginx.conf* setf nginx
|
||
|
augroup END
|
||
|
|
||
|
au FileType nginx setlocal noet ts=4 sw=4 sts=4
|
||
|
|
||
|
" Go settings
|
||
|
au BufNewFile,BufRead *.go setlocal noet ts=4 sw=4 sts=4
|
||
|
|
||
|
" scala settings
|
||
|
autocmd BufNewFile,BufReadPost *.scala setl shiftwidth=2 expandtab
|
||
|
|
||
|
" Markdown Settings
|
||
|
autocmd BufNewFile,BufReadPost *.md setl ts=4 sw=4 sts=4 expandtab
|
||
|
|
||
|
" lua settings
|
||
|
autocmd BufNewFile,BufRead *.lua setlocal noet ts=4 sw=4 sts=4
|
||
|
|
||
|
" Dockerfile settings
|
||
|
autocmd FileType dockerfile set noexpandtab
|
||
|
|
||
|
" shell/config/systemd settings
|
||
|
autocmd FileType fstab,systemd set noexpandtab
|
||
|
autocmd FileType gitconfig,sh,toml set noexpandtab
|
||
|
|
||
|
" python indent
|
||
|
autocmd BufNewFile,BufRead *.py setlocal tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80 smarttab expandtab
|
||
|
|
||
|
" toml settings
|
||
|
au BufRead,BufNewFile MAINTAINERS set ft=toml
|
||
|
|
||
|
" Wildmenu completion {{{
|
||
|
set wildmenu
|
||
|
" set wildmode=list:longest
|
||
|
set wildmode=list:full
|
||
|
|
||
|
set wildignore+=.hg,.git,.svn " Version control
|
||
|
set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
|
||
|
set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
|
||
|
set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
|
||
|
set wildignore+=*.spl " compiled spelling word lists
|
||
|
set wildignore+=*.sw? " Vim swap files
|
||
|
set wildignore+=*.DS_Store " OSX bullshit
|
||
|
set wildignore+=*.luac " Lua byte code
|
||
|
set wildignore+=migrations " Django migrations
|
||
|
set wildignore+=go/pkg " Go static files
|
||
|
set wildignore+=go/bin " Go bin files
|
||
|
set wildignore+=go/bin-vagrant " Go bin-vagrant files
|
||
|
set wildignore+=*.pyc " Python byte code
|
||
|
set wildignore+=*.orig " Merge resolution files
|
||
|
|
||
|
|
||
|
" ----------------------------------------- "
|
||
|
" Plugin configs "
|
||
|
" ----------------------------------------- "
|
||
|
|
||
|
" ==================== Fugitive ====================
|
||
|
nnoremap <leader>ga :Git add %:p<CR><CR>
|
||
|
nnoremap <leader>gs :Gstatus<CR>
|
||
|
nnoremap <leader>gp :Gpush<CR>
|
||
|
vnoremap <leader>gb :Gblame<CR>
|
||
|
|
||
|
" ==================== Lightline ====================
|
||
|
"
|
||
|
let g:lightline = {
|
||
|
\ 'active': {
|
||
|
\ 'left': [ [ 'mode', 'paste'],
|
||
|
\ [ 'fugitive', 'filename', 'modified', 'ctrlpmark' ],
|
||
|
\ ],
|
||
|
\ 'right': [ [ 'lineinfo' ],
|
||
|
\ [ 'percent' ],
|
||
|
\ [ 'fileformat', 'fileencoding', 'filetype' ] ]
|
||
|
\ },
|
||
|
\ 'inactive': {
|
||
|
\ },
|
||
|
\ 'component_function': {
|
||
|
\ 'lineinfo': 'LightLineInfo',
|
||
|
\ 'percent': 'LightLinePercent',
|
||
|
\ 'modified': 'LightLineModified',
|
||
|
\ 'filename': 'LightLineFilename',
|
||
|
\ 'fileformat': 'LightLineFileformat',
|
||
|
\ 'filetype': 'LightLineFiletype',
|
||
|
\ 'fileencoding': 'LightLineFileencoding',
|
||
|
\ 'mode': 'LightLineMode',
|
||
|
\ 'fugitive': 'LightLineFugitive',
|
||
|
\ 'ctrlpmark': 'CtrlPMark',
|
||
|
\ },
|
||
|
\ }
|
||
|
|
||
|
function! LightLineModified()
|
||
|
if &filetype == "help"
|
||
|
return ""
|
||
|
elseif &modified
|
||
|
return "+"
|
||
|
elseif &modifiable
|
||
|
return ""
|
||
|
else
|
||
|
return ""
|
||
|
endif
|
||
|
endfunction
|
||
|
|
||
|
function! LightLineFileformat()
|
||
|
return winwidth(0) > 70 ? &fileformat : ''
|
||
|
endfunction
|
||
|
|
||
|
function! LightLineFiletype()
|
||
|
return winwidth(0) > 70 ? (strlen(&filetype) ? &filetype : 'no ft') : ''
|
||
|
endfunction
|
||
|
|
||
|
function! LightLineFileencoding()
|
||
|
return winwidth(0) > 70 ? (strlen(&fenc) ? &fenc : &enc) : ''
|
||
|
endfunction
|
||
|
|
||
|
function! LightLineInfo()
|
||
|
return winwidth(0) > 60 ? printf("%3d:%-2d", line('.'), col('.')) : ''
|
||
|
endfunction
|
||
|
|
||
|
function! LightLinePercent()
|
||
|
return &ft =~? 'vimfiler' ? '' : (100 * line('.') / line('$')) . '%'
|
||
|
endfunction
|
||
|
|
||
|
function! LightLineFugitive()
|
||
|
return exists('*fugitive#head') ? fugitive#head() : ''
|
||
|
endfunction
|
||
|
|
||
|
function! LightLineMode()
|
||
|
let fname = expand('%:t')
|
||
|
return fname == 'ControlP' ? 'CtrlP' :
|
||
|
\ &ft == 'vimfiler' ? 'VimFiler' :
|
||
|
\ winwidth(0) > 60 ? lightline#mode() : ''
|
||
|
endfunction
|
||
|
|
||
|
function! LightLineFilename()
|
||
|
let fname = expand('%:t')
|
||
|
if mode() == 't'
|
||
|
return ''
|
||
|
endif
|
||
|
|
||
|
return fname == 'ControlP' ? g:lightline.ctrlp_item :
|
||
|
\ &ft == 'vimfiler' ? vimfiler#get_status_string() :
|
||
|
\ ('' != LightLineReadonly() ? LightLineReadonly() . ' ' : '') .
|
||
|
\ ('' != fname ? fname : '[No Name]')
|
||
|
endfunction
|
||
|
|
||
|
function! LightLineReadonly()
|
||
|
return &ft !~? 'help' && &readonly ? 'RO' : ''
|
||
|
endfunction
|
||
|
|
||
|
function! CtrlPMark()
|
||
|
if expand('%:t') =~ 'ControlP'
|
||
|
call lightline#link('iR'[g:lightline.ctrlp_regex])
|
||
|
return lightline#concatenate([g:lightline.ctrlp_prev, g:lightline.ctrlp_item
|
||
|
\ , g:lightline.ctrlp_next], 0)
|
||
|
else
|
||
|
return ''
|
||
|
endif
|
||
|
endfunction
|
||
|
|
||
|
let g:ctrlp_status_func = {
|
||
|
\ 'main': 'CtrlPStatusFunc_1',
|
||
|
\ 'prog': 'CtrlPStatusFunc_2',
|
||
|
\ }
|
||
|
|
||
|
" ==================== NerdTree ====================
|
||
|
" For toggling
|
||
|
nmap <C-n> :NERDTreeToggle<CR>
|
||
|
noremap <Leader>n :NERDTreeToggle<cr>
|
||
|
noremap <Leader>f :NERDTreeFind<cr>
|
||
|
|
||
|
let NERDTreeShowHidden=1
|
||
|
|
||
|
let NERDTreeIgnore=['\.vim$', '\~$', '\.git$', '.DS_Store']
|
||
|
|
||
|
" Close nerdtree and vim on close file
|
||
|
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
|
||
|
|
||
|
|
||
|
" vim:ts=2:sw=2:et
|