dotfiles/.vimrc

156 lines
3.9 KiB
VimL

" Visual settings
set t_Co=16
set bg=dark
set number
highlight LineNr ctermfg=darkgrey
" Syntax highlighting
syntax on
set hlsearch
" Case insensitive search (except for when explicitly using uppercase letters)
set ignorecase
set smartcase
" Indentation options (yeah let's switch to spaces instead of tabs I guess...)
set autoindent
set expandtab
set smarttab
set shiftwidth=4
set tabstop=4
set softtabstop=4
" Activate filetype plugin (e.g. for automatically using tabs instead of spaces in Makefiles)
filetype plugin on
" Syntax rules for custom file extensions/patterns
autocmd BufNewFile,BufRead *.gitconfig set syntax=gitconfig
autocmd BufNewFile,BufRead *.rasi set syntax=scss
" Indentation for Python (use 4 spaces)
"autocmd FileType python setlocal expandtab shiftwidth=4 softtabstop=4
autocmd FileType yml,yaml setlocal ts=2 sts=2 sw=2 expandtab
" Indentation (don't remove tabs from empty lines)
"inoremap <CR> <CR>x<BS>
"nnoremap o ox<BS>
"nnoremap O Ox<BS>
" Mouse settings
set mouse=a
" Disable beeping on console
set belloff=all
" Do not insert comment leader when entering insert mode with 'o'/'O' in comment line
autocmd BufNewFile,BufRead * set formatoptions-=o
" clang autocomplete: do not open completion box automatically
let g:clang_complete_auto=0
" Disable middle mouse button paste when in normal mode
map <MiddleMouse> <Nop>
map <2-MiddleMouse> <Nop>
map <3-MiddleMouse> <Nop>
map <4-MiddleMouse> <Nop>
" Keyboard mappings
" -----------------
nnoremap <C-L> :nohl<CR>:diffupdate<CR><C-L>
set pastetoggle=<F2>
" Toggle line numbers
nnoremap <F3> :set number!<CR>
" If the current buffer has never been saved, it will have no name,
" call the file browser to save it, otherwise just save it.
command! -nargs=0 -bar Update if &modified
\| if empty(bufname('%'))
\| browse confirm write
\| else
\| confirm write
\| endif
\|endif
" Bind <C-S> to save
nnoremap <silent> <C-s> :<C-u>Update<CR>
inoremap <C-s> <C-o>:Update<CR>
" sudo-write with :w!!
cnoremap w!! w !sudo tee >/dev/null %
" Edit (\ev) and reload (\rv) .vimrc (reload .gvimrc if running gvim)
nnoremap <leader>ev :split $MYVIMRC<CR>
if has('gui_running')
nnoremap <leader>rv :source $MYVIMRC<CR>:source $MYGVIMRC<CR>
else
nnoremap <leader>rv :source $MYVIMRC<CR>
endif
" Split line at cursor with <C-J> (as opposite of <Shift-J> for join lines)
nnoremap <C-J> i<CR><Esc>k$
" Easier buffer switching
" -----------------------
" Mappings to access buffers (don't use "\p" because a
" delay before pressing "p" would accidentally paste).
" \l : list buffers
" \b \n \g : go back/forward/last-used
" \1 \2 \3 : go to buffer 1/2/3 etc
nnoremap <Leader>l :ls<CR>
nnoremap <Leader>b :bp<CR>
nnoremap <Leader>n :bn<CR>
nnoremap <Leader>g :e#<CR>
nnoremap <Leader>1 :1b<CR>
nnoremap <Leader>2 :2b<CR>
nnoremap <Leader>3 :3b<CR>
nnoremap <Leader>4 :4b<CR>
nnoremap <Leader>5 :5b<CR>
nnoremap <Leader>6 :6b<CR>
nnoremap <Leader>7 :7b<CR>
nnoremap <Leader>8 :8b<CR>
nnoremap <Leader>9 :9b<CR>
nnoremap <Leader>0 :10b<CR>
" Compiling and making
nnoremap <F9> :up<CR>:make<CR>:redraw! \| cw<CR>
nnoremap <F10> :up<CR>:make run<CR>:redraw! \| cw<CR>
" Tab buffers
nnoremap <F12> :tab ball<CR>
" Tab movement
noremap <A-[> :-tabmove<CR>
noremap <A-]> :+tabmove<CR>
" -- Shortcuts for insert mode
" Exit insert mode
imap ,, <ESC>
imap jk <ESC>
inoremap <A-,> <ESC>
" Quick movement with Alt-h/j/k/l
inoremap <A-h> <C-o>h
inoremap <A-j> <C-o>j
inoremap <A-k> <C-o>k
inoremap <A-l> <C-o>l
" Unindent with Shift-Tab
inoremap <S-Tab> <C-o><<
" Copy and to X clipboard (Ctrl-C in visual mode and Ctrl-V in insert mode)
vmap <C-C> "+y
imap <C-V> <C-\><C-O>"+P
" Undo in insert mode with Ctrl-U
imap <C-U> <C-O>u
" Quick exit
map Q :qa<CR>
" Because I always type q: too fast, which opens the command history...
map q: :q