path: root/vim/vimrc
blob: 1067d09a4ac6831e039907d2c45665e794bf6e33 (plain) (tree)





















































" Tom Ryder (tejr)'s vimrc: <https://sanctum.geek.nz/cgit/dotfiles.git>
" This file is not truly self-contained. It should run without errors on its
" own without the accompanying plugins to which it refers near its end, but
" you'll get errors for some of the leader maps.

" Load filetype settings, plugins, and maps
if has('autocmd')
  let g:maplocalleader = '_'
  filetype plugin indent on

" Options dependent on the syntax feature
if has('syntax') && !has('g:syntax_on')

  " Use syntax highlighting
  syntax enable

  " Use my colorscheme if using the GUI or if we have 256 colors
  if has('gui_running') || &t_Co >= 256
    silent! colorscheme sahara

  " If not sahara, then default with dark background
  if !exists('g:colors_name')
    set background=dark


" The all-important default indent settings; filetypes to tweak
set autoindent    " Use indent of previous line on new lines
set expandtab     " Use spaces instead of tabs
set shiftround    " Round indenting to multiples of 'shiftwidth'
set shiftwidth=4  " Indent with four spaces

" Spaces to insert on Tab key insert
if v:version > 703 || v:version == 703 && has('patch693')
  set softtabstop=-1  " Refer to 'shifwidth' if supported
  set softtabstop=4   " Otherwise just four spaces

" Let me backspace over pretty much anything
set backspace+=eol     " Line breaks
set backspace+=indent  " Spaces from 'autoindent'
set backspace+=start   " The start of current insertion

" Never use any kind of bell, visual or not
if exists('+belloff')
  set belloff=all
  set visualbell t_vb=

" How to deal with lines wrapping beyond the last screen row
if v:version > 704 || v:version == 704 && has('patch2109')
  set display=truncate  " Show '@@@' on the last line, if supported
  set display=lastline  " Just let it run off the screen if not

" Don't wait for a key after Escape in insert mode
if exists('+esckeys')  " Not in Neovim
  set noesckeys

" Delete comment leaders when joining lines, if supported
if v:version > 703 || v:version == 703 && has('patch541')
  set formatoptions+=j

" Don't assume I'm editing C; let the filetype set this
set include=

" Don't join lines with two spaces at the end of sentences
set nojoinspaces

" Don't show a statusline if there's only one window
if has('nvim')  " Neovim changed the default to 2
  set laststatus=1

" Don't redraw the screen during batch execution
set lazyredraw

" Define extra 'list' display characters
set listchars+=extends:>   " Unwrapped text to screen right
set listchars+=precedes:<  " Unwrapped text to screen left
set listchars+=tab:>-      " Tab characters, preserve width
set listchars+=trail:_     " Trailing spaces
if v:version >= 700
  set listchars+=nbsp:+    " Non-breaking spaces

" Add angle brackets to pairs of matched characters
set matchpairs+=<:>

" Don't allow setting options via buffer content
set nomodeline

" Treat numbers with a leading zero as decimal, not octal
set nrformats-=octal

" Always tell me the number of lines changed by a command
set report=0

" Abbreviate some more regularly displayed messages
set shortmess+=I  " Don't show startup splash screen
set shortmess+=m  " [Modified] -> [+]
set shortmess+=r  " [readonly] -> [RO]
set shortmess+=w  " written -> [w], appended -> [a]

" Show my current position in the status bar
if has('cmdline_info')
  set ruler

" Clear default 'comment' value, let the filetype handle it
if has('comments')
  set comments=

" Highlight settings for search
if has('extra_search')
  set hlsearch   " Highlight completed searches...
  nohlsearch     " ...but clear it on startup or after re-sourcing
  set incsearch  " Show matches as I type

" More sensible language-agnostic setting for gf/:find
if has('file_in_path')
  set path=.,,**

" Don't load GUI menus; set here before GUI starts
if has('gui_running')
  set guioptions+=M

" Line break behaviour settings for 'wrap'
if has('linebreak')
  set linebreak      " Break lines at word boundaries
  set showbreak=...  " Prefix wrapped rows with three dots

  " Indent wrapped lines, if supported
  if exists('+breakindent')
    set breakindent


" Let me move beyond buffer text in visual block mode
if has('virtualedit')
  set virtualedit+=block

" Nicer completion for command mode
if has('wildmenu')
  set wildmenu               " Use wildmenu
  set wildmode=list:longest  " Tab press completes and lists

  " Complete files without case sensitivity, if supported
  if exists('+wildignorecase')
    set wildignorecase


" New windows go below or to the right of a split
if has('windows')
  set splitbelow
  if has('vertsplit')
    set splitright

" Rebind normal, visual <Space> to scroll down a page
nnoremap <Space> <C-F>
if v:version >= 700
  xnoremap <Space> <C-F>

" Rebind normal, visual & to preserve substitution flags
nnoremap <silent> & :<C-U>&&<CR>
if v:version >= 700
  xnoremap <silent> & :&&<CR>

" Stack insert Ctrl-C to undo the escaped insert operation
inoremap <C-C> <C-C>u

" Stack normal, visual Ctrl-L to clear search highlight before redraw
nnoremap <silent> <C-L> :<C-U>nohlsearch<CR><C-L>
if v:version >= 700
  xnoremap <silent> <C-L> :<C-U>nohlsearch<CR>gv<C-L>

" Cycle through argument list
nnoremap [a :<C-U>previous<CR>
nnoremap ]a :<C-U>next<CR>
" Cycle through buffers
nnoremap [b :<C-U>bprevious<CR>
nnoremap ]b :<C-U>bnext<CR>
" Cycle through quicklist/:helpgrep items
nnoremap [c :<C-U>cprevious<CR>
nnoremap ]c :<C-U>cnext<CR>
" Cycle through location list items
nnoremap [l :<C-U>lprevious<CR>
nnoremap ]l :<C-U>lnext<CR>
" Cycle through tabs
nnoremap [t :<C-U>tabprevious<CR>
nnoremap ]t :<C-U>tabnext<CR>

" Insert blank lines around current line
nmap [<Space> <Plug>PutBlankLinesAbove
nmap ]<Space> <Plug>PutBlankLinesBelow

" Remap normal J to stay in place while joining lines
if &loadplugins
  nmap J <Plug>FixedJoin

" Remap normal Y to yank to end of line (consistent with C, D)
nnoremap Y y$

" ZA unconditionally writes all buffers
nnoremap ZA :<C-U>wall!<CR>
" ZW unconditionally writes current buffer
nnoremap ZW :<C-U>write!<CR>

" Normal mode leader mappings below; use a literal backslash rather than
" <Leader> on the non-plugin maps so that they work on vim-tiny

" \a toggles 'formatoptions' 'a' flag using a plugin
nnoremap <Leader>a :<C-U>ToggleOptionFlagLocal formatoptions a<CR>
" \b toggles copy-pasteable linebreak settings
nmap <Leader>b <Plug>CopyLinebreakToggle
" \c toggles 'cursorcolumn', \C toggles 'cursorline'
nnoremap \c :<C-U>set cursorcolumn! cursorcolumn?<CR>
nnoremap \C :<C-U>set cursorline! cursorline?<CR>
" Current date and time insertion commands, requiring POSIX date(1)
if has('unix')
  " \d inserts the local date
  nnoremap \d :<C-U>read !date<CR>
  " \D inserts the UTC date
  nnoremap \D :<C-U>read !date -u<CR>
" \f shows the current 'formatoptions' at a glance
nnoremap \f :<C-U>set formatoptions?<CR>
" \g changes directory to the current file's location
nnoremap \g :<C-U>cd %:h<CR>:pwd<CR>
" \h toggles highlighting search results
nnoremap \h :<C-U>set hlsearch! hlsearch?<CR>
" \i toggles showing matches as I enter my pattern
nnoremap \i :<C-U>set incsearch! incsearch?<CR>
" \j jumps to buffers (jetpack)
nnoremap \j :<C-U>ls<CR>:buffer<Space>
" \l toggles showing tab, end-of-line, and trailing whitespace
nnoremap \l :<C-U>set list! list?<CR>
" \n toggles line numbers
nnoremap \n :<C-U>set number! number?<CR>
" \o and \O open 'pasted insert' lines
nmap <Leader>o <Plug>PasteOpenBelow
nmap <Leader>O <Plug>PasteOpenAbove
" \p toggles paste mode
nnoremap \p :<C-U>set paste! paste?<CR>
" \r reloads .vimrc
nnoremap \r :<C-U>source $MYVIMRC<CR>
" \s toggles spell checking
nnoremap \s :<C-U>setlocal spell! spell?<CR>
" \t shows current filetype
nnoremap \t :<C-U>set filetype?<CR>
" \u sets US English spelling (compare \z)
nnoremap \u :<C-U>setlocal spelllang=en_us spelllang?<CR>
" \w toggles wrapping
nnoremap \w :<C-U>set wrap! wrap?<CR>
" \x strips trailing whitespace via a custom plugin
nmap <Leader>x <Plug>StripTrailingWhitespace
" \z sets NZ English spelling (compare \u)
nnoremap \z :<C-U>setlocal spelllang=en_nz spelllang?<CR>

" Custom digraphs
if has('digraphs')
  digraph ./ 8230  " HORIZONTAL ELLIPSIS U+2026
  digraph %% 8984  " PLACE OF INTEREST SIGN U+2318 (Mac command key)
  digraph 8: 9731  " SNOWMAN U+2603

" Settings for plugins
if &loadplugins

  " Add packaged matchit.vim, if supported
  if has('packages') && !has('nvim')
    packadd! matchit

  " Skip loading some plugins:
  " I manage plugins myself with Git and a Makefile
  let g:loaded_getscriptPlugin = 1
  let g:loaded_vimballPlugin = 1
  " Vim is the wrong tool for reading archives or compressed text
  let g:loaded_gzip = 1
  let g:loaded_tarPlugin = 1
  let g:loaded_zipPlugin = 1
  " I prefer filtering text with Unix tools
  let g:loaded_logiPat = 1
  " The shell, tab completion, and 'wildmenu' are good enough
  let g:loaded_netrwPlugin = 1
  " I don't use Vim servers
  let g:loaded_rrhelper = 1
  " I don't need extra spelling files
  let g:loaded_spellfile_plugin = 1


" Source any .vim files from ~/.vim/config
runtime! config/*.vim