aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-11-05 00:41:40 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-11-05 00:41:40 +1300
commit2044d97b03c31083cc0bb47a3f65d729d98f558b (patch)
treef41874a69203faf1f1e5780925b06e84310a9eeb
parentMerge branch 'release/v0.7.0' (diff)
parentBump version number to 0.8.0 (diff)
downloaddotfiles-2044d97b03c31083cc0bb47a3f65d729d98f558b.tar.gz
dotfiles-2044d97b03c31083cc0bb47a3f65d729d98f558b.zip
Merge branch 'release/v0.8.0'v0.8.0
* release/v0.8.0: Bump version number to 0.8.0 Use BufReadPost hook for big_file_options.vim Limit search highlighting hooks to Vim >= 7.1 Add explanatory note for choosing imperfect remap Set 'guioptions' flag by flag Use variable setting approach for 'guifont' Add short-circuit boilerplate to plugins Simplify shell linting code with single vars Use spaces around concat dots in VimL consistently Remove vim/bundle/html5 submodule Remove vim/bundle/targets submodule Adjust plugin code layout a lot
-rw-r--r--.gitmodules6
-rw-r--r--VERSION4
-rw-r--r--vim/autoload/detect_background.vim15
-rw-r--r--vim/config/file.vim8
-rw-r--r--vim/config/format.vim12
-rw-r--r--vim/config/list.vim4
-rw-r--r--vim/config/number.vim4
-rw-r--r--vim/config/search.vim22
-rw-r--r--vim/config/spell.vim12
-rw-r--r--vim/config/substitution.vim11
-rw-r--r--vim/config/swapfile.vim2
-rw-r--r--vim/config/undo.vim2
-rw-r--r--vim/config/viminfo.vim2
-rw-r--r--vim/config/whitespace.vim2
-rw-r--r--vim/config/wrap.vim6
-rw-r--r--vim/doc/big_file_options.txt (renamed from vim/doc/big_file.txt)2
-rw-r--r--vim/ftplugin/html.vim15
-rw-r--r--vim/ftplugin/perl.vim15
-rw-r--r--vim/ftplugin/sh.vim22
-rw-r--r--vim/ftplugin/vim.vim5
-rw-r--r--vim/gvimrc15
-rw-r--r--vim/indent/_GLOBAL.vim6
-rw-r--r--vim/plugin/big_file.vim59
-rw-r--r--vim/plugin/big_file_options.vim65
-rw-r--r--vim/plugin/command_typos.vim44
-rw-r--r--vim/plugin/copy_linebreak.vim49
-rw-r--r--vim/plugin/fixed_join.vim36
-rw-r--r--vim/plugin/strip_trailing_whitespace.vim90
-rw-r--r--vim/plugin/toggle_option_flag.vim78
29 files changed, 363 insertions, 250 deletions
diff --git a/.gitmodules b/.gitmodules
index 5f908d04..998180ec 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -4,9 +4,6 @@
[submodule "vim/bundle/commentary"]
path = vim/bundle/commentary
url = https://sanctum.geek.nz/clone/vim-commentary.git
-[submodule "vim/bundle/html5"]
- path = vim/bundle/html5
- url = https://sanctum.geek.nz/clone/html5.vim.git
[submodule "vim/bundle/juvenile"]
path = vim/bundle/juvenile
url = https://sanctum.geek.nz/code/juvenile.git
@@ -25,9 +22,6 @@
[submodule "vim/bundle/surround"]
path = vim/bundle/surround
url = https://sanctum.geek.nz/clone/vim-surround.git
-[submodule "vim/bundle/targets"]
- path = vim/bundle/targets
- url = https://sanctum.geek.nz/clone/targets.vim.git
[submodule "vim/bundle/unimpaired"]
path = vim/bundle/unimpaired
url = https://sanctum.geek.nz/clone/vim-unimpaired.git
diff --git a/VERSION b/VERSION
index 2de1dcdb..8ecd9176 100644
--- a/VERSION
+++ b/VERSION
@@ -1,2 +1,2 @@
-tejr dotfiles v0.7.0
-Sat Nov 4 05:45:33 UTC 2017
+tejr dotfiles v0.8.0
+Sat Nov 4 11:40:39 UTC 2017
diff --git a/vim/autoload/detect_background.vim b/vim/autoload/detect_background.vim
index 89e5d19e..168640c3 100644
--- a/vim/autoload/detect_background.vim
+++ b/vim/autoload/detect_background.vim
@@ -6,16 +6,27 @@
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
"
+if exists('g:loaded_detect_background')
+ \ || &compatible
+ finish
+endif
+let g:loaded_detect_background = 1
+
+" Declare autoload function for 'background' set
function! detect_background#DetectBackground()
" Split up the value of $COLORFGBG (if any) by semicolons
let l:colorfgbg = split($COLORFGBG, ';')
" Get the background color value, or an empty string if none
- let l:bg = len(l:colorfgbg) ? l:colorfgbg[-1] : ''
+ let l:bg = len(l:colorfgbg)
+ \ ? l:colorfgbg[-1]
+ \ : ''
" Choose the background setting based on this value
- if l:bg ==# 'default' || l:bg ==# '7' || l:bg ==# '15'
+ if l:bg ==# 'default'
+ \ || l:bg ==# '7'
+ \ || l:bg ==# '15'
set background=light
else
set background=dark
diff --git a/vim/config/file.vim b/vim/config/file.vim
index 07c20cd5..4bf1f86b 100644
--- a/vim/config/file.vim
+++ b/vim/config/file.vim
@@ -27,5 +27,9 @@ set nomodeline
" I really like ZZ and ZQ, so I wrote a couple more mappings; ZW forces a
" write of the current buffer, but doesn't quit, and ZA forces a write of all
" buffers but doesn't quit
-nnoremap ZW :w!<CR>
-nnoremap ZA :wa!<CR>
+nnoremap <silent>
+ \ ZW
+ \ :<C-U>write!<CR>
+nnoremap <silent>
+ \ ZA
+ \ :<C-U>wall!<CR>
diff --git a/vim/config/format.vim b/vim/config/format.vim
index 572e9877..688b60c9 100644
--- a/vim/config/format.vim
+++ b/vim/config/format.vim
@@ -1,6 +1,7 @@
" If we can, add j to the format options to get rid of comment leaders when
" joining lines
-if v:version > 703 || v:version ==# 703 && has('patch541')
+if v:version > 703
+ \ || v:version ==# 703 && has('patch541')
set formatoptions+=j
endif
@@ -17,10 +18,13 @@ endif
" t - Automatically wrap text at 'textwidth' (as above)
"
if has('eval') && has('user_commands')
- nnoremap <silent> <leader>a
+ nnoremap <silent>
+ \ <Leader>a
\ :<C-U>ToggleOptionFlagLocal formatoptions a<CR>
- nnoremap <silent> <leader>c
+ nnoremap <silent>
+ \ <Leader>c
\ :<C-U>ToggleOptionFlagLocal formatoptions c<CR>
- nnoremap <silent> <leader>t
+ nnoremap <silent>
+ \ <Leader>t
\ :<C-U>ToggleOptionFlagLocal formatoptions t<CR>
endif
diff --git a/vim/config/list.vim b/vim/config/list.vim
index 209bb4ec..1cb4345b 100644
--- a/vim/config/list.vim
+++ b/vim/config/list.vim
@@ -1,7 +1,9 @@
" Don't show whitespace characters or end-of-line characters visually by
" default, but make \l toggle between them
set nolist
-nnoremap <Leader>l :setlocal list! list?<CR>
+nnoremap <silent>
+ \ <Leader>l
+ \ :<C-U>setlocal list! list?<CR>
" Clearly show when the start or end of the row does not correspond to the
" start and end of the line
diff --git a/vim/config/number.vim b/vim/config/number.vim
index d7d9919c..becc20f1 100644
--- a/vim/config/number.vim
+++ b/vim/config/number.vim
@@ -1,3 +1,5 @@
" Don't show line numbers by default, but \n toggles them
set nonumber
-nnoremap <Leader>n :setlocal number! number?<CR>
+nnoremap <silent>
+ \ <Leader>n
+ \ :<C-U>setlocal number! number?<CR>
diff --git a/vim/config/search.vim b/vim/config/search.vim
index 0f10eea5..ff243116 100644
--- a/vim/config/search.vim
+++ b/vim/config/search.vim
@@ -3,24 +3,34 @@ if has('extra_search')
" Searching as I enter my pattern, \i toggles this
set incsearch
- nnoremap <Leader>i :setlocal incsearch! incsearch?<CR>
+ nnoremap <silent>
+ \ <Leader>i
+ \ :<C-U>setlocal incsearch! incsearch?<CR>
" Highlight search results, \h toggles this
set hlsearch
- nnoremap <Leader>h :setlocal hlsearch! hlsearch?<CR>
+ nnoremap <silent>
+ \ <Leader>h
+ \ :<C-U>setlocal hlsearch! hlsearch?<CR>
" Pressing ^L will clear highlighting until the next search-related
" operation; quite good because the highlighting gets distracting after
" you've found what you wanted
- nnoremap <silent> <C-l> :nohlsearch<CR><C-l>
+ nnoremap <silent>
+ \ <C-L>
+ \ :<C-U>nohlsearch<CR><C-L>
" Clear search highlighting as soon as I enter insert mode, and restore it
" once I leave it
- if has('autocmd')
+ if has('autocmd') && v:version >= 701
augroup dotfiles_highlight
autocmd!
- silent! autocmd InsertEnter * setlocal nohlsearch
- silent! autocmd InsertLeave * setlocal hlsearch
+ autocmd InsertEnter
+ \ *
+ \ setlocal nohlsearch
+ autocmd InsertLeave
+ \ *
+ \ setlocal hlsearch
augroup END
endif
endif
diff --git a/vim/config/spell.vim b/vim/config/spell.vim
index 6a0167d0..7775ade9 100644
--- a/vim/config/spell.vim
+++ b/vim/config/spell.vim
@@ -3,12 +3,18 @@ if has('spell')
" Don't check spelling by default, but bind \s to toggle this
set nospell
- nnoremap <Leader>s :setlocal spell! spell?<CR>
+ nnoremap <silent>
+ \ <Leader>s
+ \ :<C-U>setlocal spell! spell?<CR>
" Use New Zealand English for spelling by default (it's almost identical
" to British English), but bind \u to switch to US English and \z to
" switch back
set spelllang=en_nz
- nnoremap <Leader>u :setlocal spelllang=en_us spelllang?<CR>
- nnoremap <Leader>z :setlocal spelllang=en_nz spelllang?<CR>
+ nnoremap <silent>
+ \ <Leader>u
+ \ :<C-U>setlocal spelllang=en_us spelllang?<CR>
+ nnoremap <silent>
+ \ <Leader>z
+ \ :<C-U>setlocal spelllang=en_nz spelllang?<CR>
endif
diff --git a/vim/config/substitution.vim b/vim/config/substitution.vim
index da9eb47e..415665ef 100644
--- a/vim/config/substitution.vim
+++ b/vim/config/substitution.vim
@@ -1,4 +1,11 @@
" Preserve the flags for a pattern when repeating a substitution with &; I
" don't really understand why this isn't a default, but there it is
-nnoremap & :&&<CR>
-vnoremap & :&&<CR>
+nnoremap <silent>
+ \ &
+ \ :<C-U>&&<CR>
+
+" Same again for visual mode; we use vnoremap rather than xnoremap to stay
+" compatible with old Vims without doing eval() dances
+vnoremap <silent>
+ \ &
+ \ :<C-U>&&<CR>
diff --git a/vim/config/swapfile.vim b/vim/config/swapfile.vim
index f118eabd..778ae2f0 100644
--- a/vim/config/swapfile.vim
+++ b/vim/config/swapfile.vim
@@ -20,7 +20,7 @@ if !strlen($SUDO_USER) && has('unix')
if has('autocmd')
augroup dotfiles_swap_skip
autocmd!
- silent! autocmd BufNewFile,BufReadPre
+ autocmd BufNewFile,BufReadPre
\ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/*
\ setlocal noswapfile
augroup END
diff --git a/vim/config/undo.vim b/vim/config/undo.vim
index 872578f7..c9539665 100644
--- a/vim/config/undo.vim
+++ b/vim/config/undo.vim
@@ -24,7 +24,7 @@ if !strlen($SUDO_USER) && has('unix') && has('persistent_undo')
if has('autocmd')
augroup dotfiles_undo_skip
autocmd!
- silent! autocmd BufWritePre
+ autocmd BufWritePre
\ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/*
\ setlocal noundofile
augroup END
diff --git a/vim/config/viminfo.vim b/vim/config/viminfo.vim
index ce5d539d..9b01adc3 100644
--- a/vim/config/viminfo.vim
+++ b/vim/config/viminfo.vim
@@ -4,7 +4,7 @@
if has('viminfo') && has('autocmd')
augroup dotfiles_viminfo_skip
autocmd!
- silent! autocmd BufNewFile,BufReadPre
+ autocmd BufNewFile,BufReadPre
\ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/*
\ setlocal viminfo=
augroup END
diff --git a/vim/config/whitespace.vim b/vim/config/whitespace.vim
index 75ab7173..24cda107 100644
--- a/vim/config/whitespace.vim
+++ b/vim/config/whitespace.vim
@@ -1,2 +1,2 @@
" \x strips trailing whitespace via a custom plugin
-nmap <leader>x <Plug>StripTrailingWhitespace
+nmap <Leader>x <Plug>StripTrailingWhitespace
diff --git a/vim/config/wrap.vim b/vim/config/wrap.vim
index 5da843ce..a3fccbba 100644
--- a/vim/config/wrap.vim
+++ b/vim/config/wrap.vim
@@ -1,6 +1,8 @@
" Don't wrap by default, but use \w to toggle it on or off quickly
set nowrap
-nnoremap <Leader>w :setlocal wrap! wrap?<CR>
+nnoremap <silent>
+ \ <Leader>w
+ \ :<C-U>setlocal wrap! wrap?<CR>
" When wrapping text, if a line is so long that not all of it can be shown on
" the screen, show as much as possible anyway; by default Vim fills the left
@@ -29,6 +31,6 @@ if has('linebreak')
endif
" \b toggles copy-pasteable linebreak settings
- nmap <leader>b <Plug>CopyLinebreak
+ nmap <Leader>b <Plug>CopyLinebreak
endif
diff --git a/vim/doc/big_file.txt b/vim/doc/big_file_options.txt
index aea0ee79..706ba5a7 100644
--- a/vim/doc/big_file.txt
+++ b/vim/doc/big_file_options.txt
@@ -1,4 +1,4 @@
-*big_file.txt* Disable slow options for big files to speed things up
+*big_file_options.txt* Disable slow options for big files for faster load
Author: Tom Ryder <tom@sanctum.geek.nz>
License: Same terms as Vim itself (see |license|)
diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim
index c756eb80..3db5dcca 100644
--- a/vim/ftplugin/html.vim
+++ b/vim/ftplugin/html.vim
@@ -1,10 +1,12 @@
" Run `tidy -errors -quiet` over buffer
-nnoremap <buffer> <silent> <LocalLeader>c
- \ :write !tidy -errors -quiet<CR>
+nnoremap <buffer> <silent>
+ \ <LocalLeader>c
+ \ :<C-U>write !tidy -errors -quiet<CR>
" Filter buffer through `tidy`
-nnoremap <buffer> <silent> <LocalLeader>t
- \ :%!tidy -quiet<CR>
+nnoremap <buffer> <silent>
+ \ <LocalLeader>t
+ \ :<C-U>%!tidy -quiet<CR>
" Make a bare URL into a link to itself
function! s:UrlLink()
@@ -21,5 +23,8 @@ function! s:UrlLink()
normal! a</a>
endfunction
-nnoremap <buffer> <silent> <LocalLeader>r
+
+" Mapping for the function above
+nnoremap <buffer> <silent>
+ \ <LocalLeader>r
\ :<C-U>call <SID>UrlLink()<CR>
diff --git a/vim/ftplugin/perl.vim b/vim/ftplugin/perl.vim
index 2ea4676b..07cf9a1f 100644
--- a/vim/ftplugin/perl.vim
+++ b/vim/ftplugin/perl.vim
@@ -1,11 +1,14 @@
" Run `perl -c` over buffer
-nnoremap <buffer> <silent> <LocalLeader>c
- \ :write !perl -c<CR>
+nnoremap <buffer> <silent>
+ \ <LocalLeader>c
+ \ :<C-U>write !perl -c<CR>
" Run `perlcritic` over buffer
-nnoremap <buffer> <silent> <LocalLeader>l
- \ :write !perlcritic<CR>
+nnoremap <buffer> <silent>
+ \ <LocalLeader>l
+ \ :<C-U>write !perlcritic<CR>
" Filter buffer through `perltidy`
-nnoremap <buffer> <silent> <LocalLeader>t
- \ :%!perltidy<CR>
+nnoremap <buffer> <silent>
+ \ <LocalLeader>t
+ \ :<C-U>%!perltidy<CR>
diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim
index c09e4fe8..d13f34da 100644
--- a/vim/ftplugin/sh.vim
+++ b/vim/ftplugin/sh.vim
@@ -27,22 +27,24 @@ endif
" Map checker based on shell family
if exists('b:is_bash') && b:is_bash
- let b:check = 'bash -n'
+ let b:check = 'write !bash -n'
elseif exists('b:is_ksh') && b:is_ksh
- let b:check = 'ksh -n'
+ let b:check = 'write !ksh -n'
else
- let b:check = 'sh -n'
+ let b:check = 'write !sh -n'
endif
-nnoremap <buffer> <silent> <LocalLeader>c
- \ :<C-U>execute ':write !' . b:check<CR>
+nnoremap <buffer> <silent>
+ \ <LocalLeader>c
+ \ :<C-U>execute b:check<CR>
" Map linter based on shell family
if exists('b:is_bash') && b:is_bash
- let b:lint = 'shellcheck -s bash -'
+ let b:lint = 'write shellcheck -s bash -'
elseif exists('b:is_ksh') && b:is_ksh
- let b:lint = 'shellcheck -s ksh -'
+ let b:lint = 'write !shellcheck -s ksh -'
else
- let b:lint = 'shellcheck -s sh -'
+ let b:lint = 'write !shellcheck -s sh -'
endif
-nnoremap <buffer> <silent> <LocalLeader>l
- \ :<C-U>execute ':write !' . b:lint<CR>
+nnoremap <buffer> <silent>
+ \ <LocalLeader>l
+ \ :<C-U>execute b:lint<CR>
diff --git a/vim/ftplugin/vim.vim b/vim/ftplugin/vim.vim
index e023553e..d4e55ace 100644
--- a/vim/ftplugin/vim.vim
+++ b/vim/ftplugin/vim.vim
@@ -1,5 +1,6 @@
" Run `vint` over buffer
" /dev/stdin is not optimal here; it's widely implemented, but not POSIX.
" `vint` does not seem to have another way to parse standard input.
-nnoremap <buffer> <silent> <LocalLeader>l
- \ :write !vint -s /dev/stdin<CR>
+nnoremap <buffer> <silent>
+ \ <LocalLeader>l
+ \ :<C-U>write !vint -s /dev/stdin<CR>
diff --git a/vim/gvimrc b/vim/gvimrc
index 286b84ba..128a396a 100644
--- a/vim/gvimrc
+++ b/vim/gvimrc
@@ -2,14 +2,19 @@
" these are both workable monospace fonts, but Ubuntu Mono doesn't render very
" nicely on Windows a lot of the time
if has('unix')
- silent! set guifont=Ubuntu\ Mono\ 12
+ silent! let &guifont = 'Ubuntu Mono 12'
else
- silent! set guifont=Consolas:h11
+ silent! let &guifont = 'Consolas:h11'
endif
-" Use the system GUI clipboard; use console dialogs instead of popup windows;
-" use the gVim icon
-set guioptions=aci
+" Reset guioptions
+set guioptions=
+" Use the system GUI clipboard
+set guioptions+=a
+" Use console dialogs instead of popup windows
+set guioptions+=c
+" Use the gVim icon
+set guioptions+=i
" When the GUI starts, t_vb is reset to its default value, so it's necessary
" to repeat this line from my .vimrc file that turns off visual bells
diff --git a/vim/indent/_GLOBAL.vim b/vim/indent/_GLOBAL.vim
index 4461f36d..d0bdea26 100644
--- a/vim/indent/_GLOBAL.vim
+++ b/vim/indent/_GLOBAL.vim
@@ -7,6 +7,6 @@ setlocal expandtab<
" Unfortunately, older versions of Vim (6.2 is known) accept neither the
" `option<` nor `option=` syntax for resetting these numeric values, so we do
" it this clunkier way.
-execute 'setlocal shiftwidth='.&g:shiftwidth
-execute 'setlocal softtabstop='.&g:softtabstop
-execute 'setlocal tabstop='.&g:tabstop
+execute 'setlocal shiftwidth=' . &g:shiftwidth
+execute 'setlocal softtabstop=' . &g:softtabstop
+execute 'setlocal tabstop=' . &g:tabstop
diff --git a/vim/plugin/big_file.vim b/vim/plugin/big_file.vim
deleted file mode 100644
index ec30158a..00000000
--- a/vim/plugin/big_file.vim
+++ /dev/null
@@ -1,59 +0,0 @@
-"
-" big_file.vim: When opening a large file, take some measures to keep things
-" loading quickly.
-"
-" Author: Tom Ryder <tom@sanctum.geek.nz>
-" License: Same as Vim itself
-"
-if has('eval') && has('autocmd')
-
- " Default threshold is 10 MiB
- if !exists('g:big_file_size')
- let g:big_file_size = 10 * 1024 * 1024
- endif
-
- " Default to leaving syntax highlighting off
- if !exists('g:big_file_syntax')
- let g:big_file_syntax = 0
- endif
-
- " Cut 'synmaxcol' down to this or smaller for big files
- if !exists('g:big_file_synmaxcol')
- let g:big_file_synmaxcol = 256
- endif
-
- " Declare function for turning off slow options
- function! s:BigFileOptions(name, size)
-
- " Don't do anything if the file is under the threshold
- if getfsize(a:name) <= a:size
- return
- endif
-
- " Turn off backups, swap files, and undo files
- setlocal nobackup
- setlocal nowritebackup
- setlocal noswapfile
- if has('persistent_undo')
- setlocal noundofile
- endif
-
- " Limit the number of columns of syntax highlighting
- if exists('&synmaxcol') && &synmaxcol > g:big_file_synmaxcol
- execute 'setlocal synmaxcol=' . g:big_file_synmaxcol
- endif
-
- " Disable syntax highlighting if configured to do so
- if !g:big_file_syntax
- setlocal syntax=OFF
- endif
-
- endfunction
-
- " Define autocmd for calling to check filesize
- augroup big_file_options_bufreadpre
- autocmd!
- autocmd BufReadPre * call s:BigFileOptions(expand('<afile>'), g:big_file_size)
- augroup end
-
-endif
diff --git a/vim/plugin/big_file_options.vim b/vim/plugin/big_file_options.vim
new file mode 100644
index 00000000..bbbedc96
--- /dev/null
+++ b/vim/plugin/big_file_options.vim
@@ -0,0 +1,65 @@
+"
+" big_file_options.vim: When opening a large file, take some measures to keep
+" things loading quickly.
+"
+" Author: Tom Ryder <tom@sanctum.geek.nz>
+" License: Same as Vim itself
+"
+if exists('g:loaded_big_file_options')
+ \ || !has('autocmd')
+ \ || &compatible
+ finish
+endif
+let g:loaded_big_file_options = 1
+
+" Default threshold is 10 MiB
+if !exists('g:big_file_size')
+ let g:big_file_size = 10 * 1024 * 1024
+endif
+
+" Default to leaving syntax highlighting off
+if !exists('g:big_file_syntax')
+ let g:big_file_syntax = 0
+endif
+
+" Cut 'synmaxcol' down to this or smaller for big files
+if !exists('g:big_file_synmaxcol')
+ let g:big_file_synmaxcol = 256
+endif
+
+" Declare function for turning off slow options
+function! s:BigFileOptions()
+
+ " Don't do anything if the buffer size is under the threshold
+ if line2byte(line('$') + 1) <= g:big_file_size
+ return
+ endif
+
+ " Turn off backups, swap files, and undo files
+ setlocal nobackup
+ setlocal nowritebackup
+ setlocal noswapfile
+ if has('persistent_undo')
+ setlocal noundofile
+ endif
+
+ " Limit the number of columns of syntax highlighting
+ if exists('&synmaxcol')
+ \ && &synmaxcol > g:big_file_synmaxcol
+ execute 'setlocal synmaxcol=' . g:big_file_synmaxcol
+ endif
+
+ " Disable syntax highlighting if configured to do so
+ if !g:big_file_syntax
+ setlocal syntax=OFF
+ endif
+
+endfunction
+
+" Define autocmd for calling to check filesize
+augroup big_file_options_bufreadpost
+ autocmd!
+ autocmd BufReadPost
+ \ *
+ \ call s:BigFileOptions()
+augroup end
diff --git a/vim/plugin/command_typos.vim b/vim/plugin/command_typos.vim
index 32d194fb..16ba654d 100644
--- a/vim/plugin/command_typos.vim
+++ b/vim/plugin/command_typos.vim
@@ -6,14 +6,38 @@
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
"
-if has('eval') && has('user_commands')
- command! -bang -complete=file -nargs=? E e<bang> <args>
- command! -bang -complete=file -nargs=? W w<bang> <args>
- command! -bang -complete=file -nargs=? WQ wq<bang> <args>
- command! -bang -complete=file -nargs=? Wq wq<bang> <args>
- command! -bang Q q<bang>
- command! -bang Qa qa<bang>
- command! -bang QA qa<bang>
- command! -bang Wa wa<bang>
- command! -bang WA wa<bang>
+if exists('g:loaded_command_typos')
+ \ || !has('user_commands')
+ \ || &compatible
+ finish
endif
+let g:loaded_command_typos = 1
+
+" Define commands
+command! -bang -complete=file -nargs=?
+ \ E
+ \ edit<bang> <args>
+command! -bang -complete=file -nargs=?
+ \ W
+ \ write<bang> <args>
+command! -bang -complete=file -nargs=?
+ \ WQ
+ \ wq<bang> <args>
+command! -bang -complete=file -nargs=?
+ \ Wq
+ \ wq<bang> <args>
+command! -bang
+ \ Q
+ \ quit<bang>
+command! -bang
+ \ Qa
+ \ qall<bang>
+command! -bang
+ \ QA
+ \ qall<bang>
+command! -bang
+ \ Wa
+ \ wall<bang>
+command! -bang
+ \ WA
+ \ wa<bang>
diff --git a/vim/plugin/copy_linebreak.vim b/vim/plugin/copy_linebreak.vim
index 1dc537d4..faeb1617 100644
--- a/vim/plugin/copy_linebreak.vim
+++ b/vim/plugin/copy_linebreak.vim
@@ -6,31 +6,36 @@
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
"
-if has('eval')
+if exists('g:loaded_copy_linebreak')
+ \ || !has('linebreak')
+ \ || &compatible
+ finish
+endif
+let g:loaded_copy_linebreak = 1
- " Define function
- function! s:CopyLinebreak()
+" Define function
+function! s:CopyLinebreak()
- " If linebreak is on, turn it off
- if &l:linebreak
- setlocal nolinebreak linebreak?
- setlocal showbreak=
- if exists('&breakindent')
- setlocal nobreakindent
- endif
+ " If linebreak is on, turn it off
+ if &l:linebreak
+ setlocal nolinebreak linebreak?
+ setlocal showbreak=
+ if exists('&breakindent')
+ setlocal nobreakindent
+ endif
- " If it's off, turn it on
- else
- setlocal linebreak linebreak?
- setlocal showbreak<
- if exists('&breakindent')
- setlocal breakindent
- endif
+ " If it's off, turn it on
+ else
+ setlocal linebreak linebreak?
+ setlocal showbreak<
+ if exists('&breakindent')
+ setlocal breakindent
endif
+ endif
- endfunction
+endfunction
- " Provide mapping proxy to the function just defined
- noremap <Plug>CopyLinebreak
- \ :<C-U>call <SID>CopyLinebreak()<CR>
-endif
+" Provide mapping proxy to the function just defined
+noremap <silent> <unique>
+ \ <Plug>CopyLinebreak
+ \ :<C-U>call <SID>CopyLinebreak()<CR>
diff --git a/vim/plugin/fixed_join.vim b/vim/plugin/fixed_join.vim
index c002f667..18f563f3 100644
--- a/vim/plugin/fixed_join.vim
+++ b/vim/plugin/fixed_join.vim
@@ -5,25 +5,29 @@
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
"
-if has('eval')
+if exists('g:loaded_fixed_join')
+ \ || &compatible
+ finish
+endif
+let g:loaded_fixed_join = 1
- " Declare function
- function! s:FixedJoin()
+" Declare function
+function! s:FixedJoin()
- " Save current cursor position
- let l:lc = line('.')
- let l:cc = col('.')
+ " Save current cursor position
+ let l:lc = line('.')
+ let l:cc = col('.')
- " Build and execute join command
- let l:command = '.,+' . v:count1 . 'join'
- execute l:command
+ " Build and execute join command
+ let l:command = '.,+' . v:count1 . 'join'
+ execute l:command
- " Restore cursor position
- call cursor(l:lc, l:cc)
+ " Restore cursor position
+ call cursor(l:lc, l:cc)
- endfunction
+endfunction
- " Create mapping proxy to the function just defined
- noremap <Plug>FixedJoin
- \ :<C-U>call <SID>FixedJoin()<CR>
-endif
+" Create mapping proxy to the function just defined
+noremap <silent> <unique>
+ \ <Plug>FixedJoin
+ \ :<C-U>call <SID>FixedJoin()<CR>
diff --git a/vim/plugin/strip_trailing_whitespace.vim b/vim/plugin/strip_trailing_whitespace.vim
index 17fff33f..9a9d3d95 100644
--- a/vim/plugin/strip_trailing_whitespace.vim
+++ b/vim/plugin/strip_trailing_whitespace.vim
@@ -4,59 +4,65 @@
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
"
-if has('eval')
+if exists('g:loaded_strip_trailing_whitespace')
+ \ || &compatible
+ finish
+endif
+let g:loaded_strip_trailing_whitespace = 1
- " Define function for stripping whitespace
- function! s:StripTrailingWhitespace()
+" Define function for stripping whitespace
+function! s:StripTrailingWhitespace()
- " Iterating line number
- let l:li = 1
+ " Iterating line number
+ let l:li = 1
- " Line number of last line that had non-whitespace characters on it
- let l:lw = 0
+ " Line number of last line that had non-whitespace characters on it
+ let l:lw = 0
- " Line number of the file's last line
- let l:ll = line('$')
+ " Line number of the file's last line
+ let l:ll = line('$')
- " Iterate over the lines
- while l:li <= l:ll
+ " Iterate over the lines
+ while l:li <= l:ll
- " Get the line text
- let l:line = getline(l:li)
+ " Get the line text
+ let l:line = getline(l:li)
- " Replace the line with a subsitution of its text stripping extraneous
- " whitespace
- call setline(l:li, substitute(l:line, '\m\C\s\+$', '', 'g'))
+ " Replace the line with a subsitution of its text stripping extraneous
+ " whitespace
+ call setline(l:li, substitute(l:line, '\m\C\s\+$', '', 'g'))
- " If this line has any non-whitespace characters on it, update l:lw with
- " its index
- if l:line =~# '\m\C\S'
- let l:lw = l:li
- endif
+ " If this line has any non-whitespace characters on it, update l:lw with
+ " its index
+ if l:line =~# '\m\C\S'
+ let l:lw = l:li
+ endif
- " Increment the line counter for the next iteration
- let l:li = l:li + 1
- endwhile
+ " Increment the line counter for the next iteration
+ let l:li = l:li + 1
- " If the last non-whitespace line was before the last line proper, we can
- " delete all lines after it
- if l:lw < l:ll
+ endwhile
- " Get the current line and column so we can return to it
- " (Yes I know about winsaveview() and winrestview(); I want this to work
- " even on very old versions of Vim if possible)
- let l:lc = line('.')
- let l:cc = col('.')
+ " If the last non-whitespace line was before the last line proper, we can
+ " delete all lines after it
+ if l:lw < l:ll
- " Delete the lines, which will move the cursor
- execute l:lw + 1.',$ delete'
+ " Get the current line and column so we can return to it
+ " (Yes I know about winsaveview() and winrestview(); I want this to work
+ " even on very old versions of Vim if possible)
+ let l:lc = line('.')
+ let l:cc = col('.')
- " Return the cursor to the saved position
- call cursor(l:lc, l:cc)
- endif
- endfunction
+ " Delete the lines, which will move the cursor
+ execute l:lw + 1 . ',$ delete'
- " Create mapping proxy to the function just defined
- noremap <Plug>StripTrailingWhitespace
- \ :<C-U>call <SID>StripTrailingWhitespace()<CR>
-endif
+ " Return the cursor to the saved position
+ call cursor(l:lc, l:cc)
+ endif
+
+endfunction
+
+" Create mapping proxy to the function just defined
+noremap <silent> <unique>
+ \ <Plug>StripTrailingWhitespace
+ \ :<C-U>call <SID>StripTrailingWhitespace()<CR>
diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim
index 10b4fe7a..ad89d080 100644
--- a/vim/plugin/toggle_option_flag.vim
+++ b/vim/plugin/toggle_option_flag.vim
@@ -7,38 +7,48 @@
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
"
-if has('eval') && has('user_commands')
-
- " Internal function to do the toggling
- function! s:Toggle(option, flag, local)
-
- " Check for weird options, we don't want to eval() anything funny
- if a:option =~# '[^a-z]'
- echoerr 'Illegal option name'
- return
- endif
-
- " Weird flags, too; should be a single inoffensive char
- if a:flag !~# '^[a-z0-9.]$'
- echoerr 'Illegal flag'
- return
- endif
-
- " Choose which set command to use
- let l:set = a:local ? 'setlocal' : 'set'
-
- " Use eval() to assign -= or += to l:op for the option toggle
- " (I couldn't get {curly braces} indirection to work)
- let l:op = ''
- execute 'let l:op = &'.a:option.' =~# a:flag ? "-=" : "+="'
-
- " Use eval() to perform the option toggle and then print the value
- execute l:set . ' ' . a:option . l:op . a:flag . ' ' . a:option . '?'
-
- endfunction
-
- " User commands wrapping around calls to the above function
- command! -nargs=+ ToggleOptionFlag :call <SID>Toggle(<f-args>, 0)
- command! -nargs=+ ToggleOptionFlagLocal :call <SID>Toggle(<f-args>, 1)
-
+if exists('g:loaded_toggle_option_flag')
+ \ || !has('user_commands')
+ \ || &compatible
+ finish
endif
+let g:loaded_toggle_option_flag = 1
+
+" Internal function to do the toggling
+function! s:Toggle(option, flag, local)
+
+ " Check for weird options, we don't want to eval() anything funny
+ if a:option =~# '[^a-z]'
+ echoerr 'Illegal option name'
+ return
+ endif
+
+ " Weird flags, too; should be a single inoffensive char
+ if a:flag !~# '^[a-z0-9.]$'
+ echoerr 'Illegal flag'
+ return
+ endif
+
+ " Choose which set command to use
+ let l:set = a:local
+ \ ? 'setlocal'
+ \ : 'set'
+
+ " eval() to assign -= or += to l:op for the option toggle
+ " (I couldn't get {curly braces} indirection to work)
+ let l:op = ''
+ execute 'let l:op = &' . a:option . ' =~# a:flag ? "-=" : "+="'
+
+ " eval() to perform the option toggle and then print the value
+ execute l:set . ' ' . a:option . l:op . a:flag
+ execute l:set . ' ' . a:option . '?'
+
+endfunction
+
+" User commands wrapping around calls to the above function
+command! -nargs=+
+ \ ToggleOptionFlag
+ \ call <SID>Toggle(<f-args>, 0)
+command! -nargs=+
+ \ ToggleOptionFlagLocal
+ \ call <SID>Toggle(<f-args>, 1)