set nocompatible

" Enable line numbering
set number

" Configure backspace so it acts as it should act
set backspace=eol,start,indent

" Allow arrow keys to wrap onto the previous/next line.
set whichwrap+=<,>,h,l

" Enable syntax highlighting if available
if has("syntax")
	syntax on
endif

" Highlight search results
set hlsearch

" Show “invisible” characters
set list lcs=tab:→\ ,space:·,nbsp:␣
"eol:¶
highlight SpecialKey ctermfg=darkgray
highlight Nontext ctermfg=darkgray

" Set utf8 as standard encoding
set encoding=utf8

"filetype detection, language-specific plugins, and automatic indentation
filetype plugin indent on

" Make tabs as wide as two spaces
set tabstop=2 shiftwidth=0 softtabstop=2 noexpandtab

" Use two spaces instead of tabs in yaml files.
autocmd FileType yaml,yml setlocal ts=2 sts=2 sw=2 expandtab

" Copy indentation from previous line
set autoindent nosmartindent nocindent indentexpr=

" Show the current mode
set showmode

" Show the filename in the window titlebar
set title

" Show the (partial) command as it’s being typed
set showcmd

" Centralize backups, swapfiles and undo history;
" double slashes enable collision-avoidance.
set backupdir=~/.vim/backups//
set directory=~/.vim/swaps//
if exists("&undodir")
	set undodir=~/.vim/undo//
endif

" :W sudo saves the file (useful for handling the permission-denied error)
command! W execute 'w !sudo tee % > /dev/null' <bar> edit!

" Likewise :S saves the file as the service user when in subdirs of
" /srv/$SERVICE_USER
command! S execute "w !sudo -u $(pwd | cut -d '/' -f3) tee % > /dev/null" <bar> edit!
