scriptencoding 'utf-8'

" Enable visually highlighting listchars
set list
" Non breaking space:
" * Circled Reverse Solidus (U+29B8, utf-8: E2 A6 B8)
set listchars=nbsp:⦸
" Trailing space:
" * Middle Dot (U+00B7, utf-8: C2 B7)
set listchars+=trail:·
" Tab stop:
" * White Right-Pointing Small Triangle (U+25B9, utf-8: E2 96 B9)
" * Box Drawings Light Triple Dash Horizontal (U+2504, utf-8: E2 94 84)
set listchars+=tab:▹┄
" Line extended beyond screen when nowrap:
" * Right-Pointing Double Angle Quotation Mark (U+00BB, utf-8: C2 BB)
set listchars+=extends:»
" Line preceded beyond screen when nowrap:
" * Left-Pointing Double Angle Quotation Mark (U+00AB, utf-8: C2 AB)
set listchars+=precedes:«

" Wrap lines which are longer than screen width
set wrap
if has('linebreak')
  " Break wrapped lines at a character in breakat
  set linebreak
  " Downwards Arrow With Tip Rightwards (U+21B3, utf-8: E2 86 B3)
  let &showbreak='↳ '
  " Use same highlight group as listchars for showbreak
  set highlight+=@:SpecialKey
endif

" Don't add 2 spaces after end of sentence
set nojoinspaces

" Enable all mouse features
set mouse=a

" TODO: spellcapcheck
" TODO: virtualedit=block
" TODO: whichwrap=b,h,l,s,<,>,[,],~

" Don't show completeopt preview buffer
if has('insert_expand')
  set completeopt-=preview
endif

" Set window title to titlestring
if has('title')
  set title
endif

" Don't show mode in command line
set noshowmode

" Show relative line numbers & current line number
set number
if has('relativenumber')
  set relativenumber
endif

" Keep cursor from buffer edges
set scrolloff=8

" Turn backup off
set nobackup noswapfile
if has('writebackup')
  set nowritebackup
endif

" Use Unix as standard file type
set fileformats=unix,mac,dos

" Allow : in filenames to allow gf to specify line numbers
set isfname-=:

" Highlight search matches & show search matches while typing
set hlsearch

" Set ignore search case unless mixed
set ignorecase smartcase

" Allow buffers with changes to be hidden
set hidden

" Open new splits on the other side of the axis
if has('windows')
  set splitbelow
endif
if has('vertsplit')
  set splitright
endif

" Use existing windows and tabs when jumping to errors
set switchbuf=usetab

" Indicates a fast terminal connection
set ttyfast

" Set syntax as default fold method
if has('folding')
  set foldmethod=syntax foldlevel=20
endif

" Automatically write changes to files
set autowrite

" Format text
"   r - insert comment leader on 'o' and 'O'
"   q - allow formatting with 'gq'
set formatoptions+=rq

" Enable modeline
set modeline

" Don't redraw during execution macros, registers, commands, etc.
set lazyredraw

" Change cursor dependant on current mode
if has('cursorshape') && has('unix') && !has('gui_running')
  if $ITERM_SESSION_ID !=# ''
    let &t_SI = "\<Esc>]50;CursorShape=1\x7"
    let &t_SR = "\<Esc>]50;CursorShape=2\x7"
    let &t_EI = "\<Esc>]50;CursorShape=0\x7"
  else
    let &t_SI = "\<Esc>[6 q"
    let &t_SR = "\<Esc>[4 q"
    let &t_EI = "\<Esc>[2 q"
  endif
  if $TMUX !=# ''
    let &t_SI = "\<Esc>Ptmux;\<Esc>".&t_SI."\<Esc>\\"
    let &t_SR = "\<Esc>Ptmux;\<Esc>".&t_SR."\<Esc>\\"
    let &t_EI = "\<Esc>Ptmux;\<Esc>".&t_EI."\<Esc>\\"
  endif
endif