" 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.
" Undo anything the operating system's vimrc may have broken
runtime system.vim
" Load filetype settings, plugins, and maps
if has('autocmd')
let g:maplocalleader = '\\'
filetype plugin indent on
endif
" Options dependent on the syntax feature
if has('syntax') && !exists('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
endif
" If not sahara, then default with dark background
if !exists('g:colors_name')
set background=dark
endif
endif
" 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 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 'shiftwidth' if supported
else
set softtabstop=4 " Otherwise just four spaces
endif
" 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
else
set visualbell t_vb=
endif
" 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
else
set display=lastline " Just let it run off the screen if not
endif
" Don't wait for a key after Escape in insert mode
if exists('+esckeys') " Not in Neovim
set noesckeys
endif
" Delete comment leaders when joining lines, if supported
if v:version > 703 || v:version == 703 && has('patch541')
set formatoptions+=j
endif
" Keep more command and search history
set history=500
" 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
endif
" 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
endif
" 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
" 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]
" Clear default 'comments' value, let the filetype handle it
if has('comments')
set comments=
endif
" 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
endif
" More sensible language-agnostic setting for gf/:find
if has('file_in_path')
set path=.,,**
endif
" Don't load GUI menus; set here before GUI starts
if has('gui_running')
set guioptions+=M
endif
" Line break behaviour settings for 'wrap'
if has('linebreak')
set linebreak " Break lines at word boundaries
set showbreak=... " Prefix wrapped rows with three dots
if exists('+breakindent')
set breakindent " Indent wrapped lines, if supported
endif
endif
" Let me move beyond buffer text in visual block mode
if has('virtualedit')
set virtualedit+=block
endif
" Nicer completion for command mode
if has('wildmenu')
set wildmenu " Use wildmenu
set wildmode=list:longest " Tab press completes and lists
if exists('+wildignorecase')
set wildignorecase " Case insensitive, if supported
endif
endif
" New windows go below or to the right of a split
if has('windows')
set splitbelow
if has('vertsplit')
set splitright
endif
endif
" Stack normal/visual/select Ctrl-L to clear search highlight
nnoremap <silent> <C-L> :<C-U>nohlsearch<CR><C-L>
vnoremap <silent> <C-L> :<C-U>nohlsearch<CR>gv<C-L>
" Remap insert Ctrl-C to undo the escaped insert operation
" Default to not-quite-correct vim-tiny-compatible map if no plugin
inoremap <Plug>InsertCancel <Esc>u
imap <C-C> <Plug>InsertCancel
" Remap normal J to stay in place while joining lines
" Default to not-quite-correct vim-tiny-compatible map if no plugin
nnoremap <Plug>FixedJoin mzJ`z
nmap J <Plug>FixedJoin
" Remap normal/visual <Space> to scroll down a page, and <Backspace> to scroll
" back up
nnoremap <Space> <C-F>
nnoremap <Backspace> <C-B>
if v:version >= 700
xnoremap <Space> <C-F>
xnoremap <Backspace> <C-B>
endif
" Remap normal/visual & to preserve substitution flags
nnoremap <silent> & :&&<CR>
if v:version >= 700
xnoremap <silent> & :&&<CR>
endif
" 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
" Normal leader maps; use <Bslash> not <Leader> for vim-tiny
" \a toggles 'formatoptions' 'a' flag using a plugin
nnoremap <Bslash>a :<C-U>ToggleOptionFlagLocal formatoptions a<CR>
" \b toggles copy-pasteable linebreak settings
nmap <Bslash>b <Plug>CopyLinebreakToggle
" \c toggles 'cursorline'
nnoremap <Bslash>c :<C-U>set cursorline! cursorline?<CR>
" \C toggles 'cursorcolumn'
nnoremap <Bslash>C :<C-U>set cursorcolumn! cursorcolumn?<CR>
" \d inserts the local date (POSIX date)
nnoremap <Bslash>d :read !date<CR>
" \D inserts the UTC date (POSIX date)
nnoremap <Bslash>D :read !date -u<CR>
" \e forces a buffer to be editable
nnoremap <Bslash>e :set modifiable noreadonly<CR>
" \f shows the current 'formatoptions' at a glance
nnoremap <Bslash>f :<C-U>set formatoptions?<CR>
" \g changes directory to the current file's location
nnoremap <Bslash>g :<C-U>cd %:h<CR>:pwd<CR>
" \h toggles highlighting search results
nnoremap <Bslash>h :<C-U>set hlsearch! hlsearch?<CR>
" \i toggles showing matches as I enter my pattern
nnoremap <Bslash>i :<C-U>set incsearch! incsearch?<CR>
" \j jumps to buffers (jetpack)
nnoremap <Bslash>j :<C-U>buffers<CR>:buffer<Space>
" \k shows my marks
nnoremap <Bslash>k :<C-U>marks<CR>
" \l toggles showing tab, end-of-line, and trailing whitespace
nnoremap <Bslash>l :<C-U>set list! list?<CR>
" \m shows all maps
nnoremap <Bslash>m :<C-U>map<CR>
" \M shows buffer-local maps
nnoremap <Bslash>M :<C-U>map <buffer><CR>
" \n toggles line numbers
nnoremap <Bslash>n :<C-U>set number! number?<CR>
" \N toggles 'ruler'
nnoremap <Bslash>N :<C-U>set ruler! ruler?<CR>
" \o opens a line below in paste mode
nmap <Bslash>o <Plug>PasteOpenBelow
" \o opens a line above in paste mode
nmap <Bslash>O <Plug>PasteOpenAbove
" \p toggles paste mode
nnoremap <Bslash>p :<C-U>set paste! paste?<CR>
" \q formats the current paragraph
nnoremap <Bslash>q gqap
" \r reloads .vimrc
nnoremap <Bslash>r :<C-U>source $MYVIMRC<CR>
" \s toggles spell checking
nnoremap <Bslash>s :<C-U>setlocal spell! spell?<CR>
" \t shows current filetype
nnoremap <Bslash>t :<C-U>set filetype?<CR>
" \u sets US English spelling (compare \z)
nnoremap <Bslash>u :<C-U>setlocal spelllang=en_us<CR>
" \v shows all global variables
nnoremap <Bslash>v :<C-U>let g: v:<CR>
" \V shows all local variables
nnoremap <Bslash>V :<C-U>let b: t: w:<CR>
" \w toggles wrapping
nnoremap <Bslash>w :<C-U>set wrap! wrap?<CR>
" \x strips trailing whitespace via a custom plugin
nmap <Bslash>x <Plug>StripTrailingWhitespace
" \y shows all registers
nnoremap <Bslash>y :<C-U>registers<CR>
" \z sets NZ English spelling (compare \u)
nnoremap <Bslash>z :<C-U>setlocal spelllang=en_nz<CR>
" \DEL deletes the current buffer
nnoremap <Bslash><Delete> :<C-U>bdelete<CR>
" \INS edits a new buffer
nnoremap <Bslash><Insert> :<C-U>enew<CR>
" Source any .vim files from ~/.vim/config
runtime! config/*.vim