" Visual settings
set t_Co=16
set bg=dark
highlight LineNr ctermfg=darkgrey

" Disable beeping on console
set belloff=all

" Mouse settings
set mouse=a

" Line numbers
set number
set relativenumber

" Amount of screen lines that should be visible above/below the cursor
set scrolloff=5

" Wrap lines at word boundaries
set linebreak

" Syntax highlighting
syntax on
set hlsearch

" Case insensitive search (except for when explicitly using uppercase letters)
set ignorecase
set smartcase

" Indentation settings
set smartindent
set expandtab
set shiftwidth=4
set softtabstop=-1

" 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 YAML (use 2 spaces)
autocmd FileType yml,yaml setlocal sts=2 sw=2

" Do not insert comment leader when entering insert mode with 'o'/'O' in comment line
autocmd BufNewFile,BufRead * set formatoptions-=o


" Keyboard mappings
" -----------------

nnoremap <C-l> :nohl<CR>:diffupdate<CR><C-l>
set pastetoggle=<F2>

" Exit insert mode with jk
inoremap jk <Esc>

" Quick exit with Ctrl-q
nnoremap <C-q> :q<CR>
nnoremap Q <Nop>

" Quick save all open buffers with Ctrl-S
nnoremap <C-s> :wall<CR>
inoremap <C-s> <C-o>:wall<CR>

" Simple copy and paste to/from system clipboard with Ctrl-c in visual mode
" and Ctrl-v in insert mode
vnoremap <C-c> "+y
inoremap <C-v> <C-\><C-o>"+P

" sudo-write with :w!!
cnoremap w!! w !sudo tee >/dev/null %

" Tab movement
noremap <A-[> :-tabmove<CR>
noremap <A-]> :+tabmove<CR>

" Use comma (,) as a "modifier prefix" for alternative functions of regular
" commands (e.g. yank to system clipboard) or for random shortcuts.
noremap , <Nop>

" Prefix yank/delete/change/paste commands with "," to use system clipboard
noremap ,y "+y
noremap ,Y "+y$
noremap ,d "+d
noremap ,D "+D
noremap ,c "+c
noremap ,C "+C
noremap ,p "+p
noremap ,P "+P
