Files
dotfiles/.vimrc
2019-09-20 20:42:19 +02:00

166 lines
4.9 KiB
VimL
Executable File

let mapleader = ","
set nocompatible " be iMproved, required
filetype off " required
let vundle_dir="~/.vim/bundle/Vundle.vim"
if filereadable(expand(vundle_dir) . "/README.md")
" set the runtime path to include Vundle and initialize
let &rtp .= "," . vundle_dir
call vundle#begin()
Plugin 'VundleVim/Vundle.vim' " let Vundle manage Vundle, required
Plugin 'scrooloose/nerdtree'
Plugin 'c.vim'
Plugin 'jeetsukumaran/vim-buffergator'
Plugin 'ericcurtin/CurtineIncSw.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-surround'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'rhysd/vim-clang-format'
" Plugin 'shougo/neocomplete'
Plugin 'godlygeek/tabular'
Plugin 'airblade/vim-gitgutter'
Plugin 'jeetsukumaran/vim-pythonsense'
Plugin 'easymotion/vim-easymotion'
Plugin 'file:///home/kuba/git/vim-indexer'
call vundle#end() " required
else
let vundle_repo="https://github.com/VundleVim/Vundle.vim.git"
echo "Vundle not installed, type :CloneVundle to clone the vundle repo and install it"
command CloneVundle execute "!git clone " . vundle_repo . " " . vundle_dir
endif
set updatetime=1000 " Default is 4s, but reduce it to make things more real time, like git gutter
highlight Search ctermbg=5
filetype plugin indent on " required
syntax on
"
" Set the filetype based on the file's extension, but only if
" 'filetype' has not already been set
au BufRead,BufNewFile *.config setfiletype conf
set tabstop=4 " show existing tab with 4 spaces width
set shiftwidth=4 " when indenting with '>', use 4 spaces width
set expandtab " On pressing tab, insert 4 spaces
set mouse=a
set hlsearch
set scrolloff=5 " Don't let cursor be within 5 lines from top or bottom
" Warn for trailing whitespace. Search with wrap (w) do not move cursor (n)
function! WhitespaceWarn()
echohl WarningMsg
echo 'Found whitespace.'
echohl None
echon ' Type :TrailWhitespace to remove it'
endfunction
function! StripTrailingWhitespace()
" Save cursor position
let l:save = winsaveview()
" Remove trailing whitespace
%s/\s\+$//e
" Move cursor to original position
call winrestview(l:save)
echo "Stripped trailing whitespace"
endfunction
autocmd BufWritePost * if search('\s\+$', 'wn') | call WhitespaceWarn() | endif
command TrailWhitespace call StripTrailingWhitespace()
" Hybrid line numbers on active buffer
set nu rnu
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set rnu
autocmd BufLeave,FocusLost,InsertEnter * set nornu
augroup END
" Do incremental searching when it's possible to timeout.
if has('reltime')
set incsearch
endif
" Copy to the end of line
noremap Y y$
" define upper case versions of :w and :q
command! -bang -range=% -complete=file -nargs=* W <line1>,<line2>write<bang> <args>
command! -bang Q quit<bang>
" fugitive.vim looks for tags in .git
" set tags +=~/tags " Recursively move upwards in tree, searching in subfolders for tags file
if exists(":NERDTree")
" Open NERDTree if no file specified
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
endif
" CtrlP
let g:ctrlp_working_path_mode = 'ra'
" Find project root
let git_dir_location=finddir('.git', ';')
let git_root_location=fnamemodify(git_dir_location, ':h')
" Simulate maximize/minimize window
nnoremap <C-w>m :call ToggleMiniMaxiWin()<CR>
nnoremap <leader>wm :call ToggleMiniMaxiWin()<CR>
function! ToggleMiniMaxiWin()
if tabpagewinnr(tabpagenr(), '$') > 1
tab split
elseif tabpagenr('$') > 1
if tabpagenr() < tabpagenr('$')
tabclose
tabprevious
else
tabclose
endif
endif
endfunction
" Key binds
"
command! Csc cscope find c <cword>
" Replace the word under cursor
nnoremap <leader>* :%s/\<<c-r><c-w>\>//g<left><left>
" Replace visual selection
vnoremap <leader>* y:%sno/<c-r>"//g<left><left>
nmap <F2> :NERDTreeToggle<CR>
nmap <F3> :NERDTreeFind<CR>
map <F5> :call CurtineIncSw()<CR>
nmap <F8> :silent !/home/efjtjkb/bin/comp<enter>
" Remap <F9> (c-vim uses this)
"nmap <F9> :silent !/home/efjtjkb/bin/run<enter>
autocmd VimEnter * noremap <F9> :silent !/home/efjtjkb/bin/run<enter>
nmap <F10> :silent !/home/efjtjkb/bin/run old<enter>
nmap <Leader>cf :cd %:p:h <CR> " Change dir to parent of current file
nmap <Leader>cg :cd $git_root_location <CR> " Change dir to git root
nmap <Leader>vs :sp $MYVIMRC <CR>
nmap <Leader>vv :vsp $MYVIMRC <CR>
nmap <Leader>vt :tabnew $MYVIMRC <CR>
nmap <Leader>vo :e $MYVIMRC <CR>
nmap <Leader>v :e $MYVIMRC <CR>
" Match git conflict markers
nmap <Leader>/g /[<=>]\{7,}.*$<CR>
" Toggle wrapping of long lines
nmap <Leader>l :set wrap!<CR>
" Scroll window while keeping cursor on same line with shift
nmap <S-j> <c-e>
nmap <S-k> <c-y>
vmap <S-j> <c-e>
vmap <S-k> <c-y>
" Misc.
map <Leader>n :noh<CR>
vmap <Leader>T :'<,'> Tabularize /
noremap <space> :