aboutsummaryrefslogtreecommitdiff
path: root/vim/config
diff options
context:
space:
mode:
Diffstat (limited to 'vim/config')
-rw-r--r--vim/config/command.vim15
-rw-r--r--vim/config/format.vim37
-rw-r--r--vim/config/join.vim25
-rw-r--r--vim/config/syntax.vim27
-rw-r--r--vim/config/whitespace.vim59
-rw-r--r--vim/config/wrap.vim38
6 files changed, 21 insertions, 180 deletions
diff --git a/vim/config/command.vim b/vim/config/command.vim
index 2a60bab3..f339635f 100644
--- a/vim/config/command.vim
+++ b/vim/config/command.vim
@@ -25,18 +25,3 @@ set shellpipe=>
if exists('+shellslash')
set shellslash
endif
-
-" Tolerate typos like :Wq, :Q, or :Qa and do what I mean, including any
-" arguments or modifiers; I fat-finger these commands a lot because I type
-" them so rapidly, and they don't correspond to any other commands I use
-if 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>
-endif
diff --git a/vim/config/format.vim b/vim/config/format.vim
index b0de7621..572e9877 100644
--- a/vim/config/format.vim
+++ b/vim/config/format.vim
@@ -5,8 +5,8 @@ if v:version > 703 || v:version ==# 703 && has('patch541')
endif
"
-" Quick way to toggle flags in 'formatoptions' that I often want to change;
-" specifically:
+" Use toggle_option_flag.vim plugin to bind quick toggle actions for some
+" 'formatoptions' flags:
"
" a - Automatically format paragraphs, reapplying the wrap on every text
" insertion or deletion; sometimes I want this and sometimes I
@@ -16,30 +16,11 @@ endif
" to set for me)
" t - Automatically wrap text at 'textwidth' (as above)
"
-" So I just have to type e.g. \a to toggle the auto-format flag on and off;
-" very handy
-"
-if has('eval')
-
- " Declare function
- function! s:ToggleFormatFlag(flag)
-
- " Decide on whether we're adding or removing the flag
- if &l:formatoptions =~# a:flag
- let l:command = 'setlocal formatoptions-=' . a:flag
- else
- let l:command = 'setlocal formatoptions+=' . a:flag
- endif
-
- " Execute the command we determined and show the result
- silent! execute l:command
- setlocal formatoptions?
-
- endfunction
-
- " Map leader-letters to corresponding format option flags
- nnoremap <silent> <Leader>a :<C-U>call <SID>ToggleFormatFlag('a')<CR>
- nnoremap <silent> <Leader>c :<C-U>call <SID>ToggleFormatFlag('c')<CR>
- nnoremap <silent> <Leader>t :<C-U>call <SID>ToggleFormatFlag('t')<CR>
-
+if has('eval') && has('user_commands')
+ nnoremap <silent> <leader>a
+ \ :<C-U>ToggleOptionFlagLocal formatoptions a<CR>
+ nnoremap <silent> <leader>c
+ \ :<C-U>ToggleOptionFlagLocal formatoptions c<CR>
+ nnoremap <silent> <leader>t
+ \ :<C-U>ToggleOptionFlagLocal formatoptions t<CR>
endif
diff --git a/vim/config/join.vim b/vim/config/join.vim
index 7d764dce..ebf42a8b 100644
--- a/vim/config/join.vim
+++ b/vim/config/join.vim
@@ -2,26 +2,9 @@
" despite the noble Steve Losh's exhortations
set nojoinspaces
-" Keep my cursor in place when I join lines
+" Rebind normal J to run plugin-defined join that doesn't jump around, but
+" only if we have the eval feature, because otherwise this mapping won't exist
+" and we should keep the default behaviour
if has('eval')
-
- " Declare function
- function! s:StableNormalJoin()
-
- " 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
-
- " Restore cursor position
- call cursor(l:lc, l:cc)
-
- endfunction
-
- " Remap J to the above function
- nnoremap <silent> J :<C-U>call <SID>StableNormalJoin()<CR>
-
+ nmap J <Plug>FixedJoin
endif
diff --git a/vim/config/syntax.vim b/vim/config/syntax.vim
index e7d94b1b..8cb1228b 100644
--- a/vim/config/syntax.vim
+++ b/vim/config/syntax.vim
@@ -5,32 +5,9 @@ if has('syntax')
silent! syntax enable
silent! syntax sync minlines=100
- " Invert Vim's built-in logic for choosing dark or light backgrounds; we'll
- " default to choosing a dark background unless we find some reason *not* to.
+ " If we can, detect a light background, but default to a dark one
if has('eval') && v:version >= 701
-
- " Wrap all this logic in a function
- function! s: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] : ''
-
- " Choose the background setting based on this value
- if l:bg ==# 'default' || l:bg ==# '7' || l:bg ==# '15'
- set background=light
- else
- set background=dark
- endif
-
- endfunction
-
- " Call the function just defined directly
- call s:DetectBackground()
-
- " Ancient or cut-down Vim? Just go dark
+ silent! call detect_background#DetectBackground()
else
set background=dark
endif
diff --git a/vim/config/whitespace.vim b/vim/config/whitespace.vim
index bfe2663d..75ab7173 100644
--- a/vim/config/whitespace.vim
+++ b/vim/config/whitespace.vim
@@ -1,57 +1,2 @@
-" Strip trailing whitespace with \x in the whole document
-if has('eval')
-
- " Define function for stripping whitespace
- function! s:StripTrailingWhitespace()
-
- " 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 the file's last line
- let l:ll = line('$')
-
- " Iterate over the lines
- while l:li <= l:ll
-
- " 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'))
-
- " 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
-
- " If the last non-whitespace line was before the last line proper, we can
- " delete all lines after it
- if l:lw < l:ll
-
- " 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('.')
-
- " Delete the lines, which will move the cursor
- execute l:lw + 1.',$ delete'
-
- " Return the cursor to the saved position
- call cursor(l:lc, l:cc)
- endif
- endfunction
-
- " Map \x to the function just defined
- nnoremap <silent> <Leader>x :<C-U>call <SID>StripTrailingWhitespace()<CR>
-
-endif
+" \x strips trailing whitespace via a custom plugin
+nmap <leader>x <Plug>StripTrailingWhitespace
diff --git a/vim/config/wrap.vim b/vim/config/wrap.vim
index 7a442e89..5da843ce 100644
--- a/vim/config/wrap.vim
+++ b/vim/config/wrap.vim
@@ -23,42 +23,12 @@ if has('linebreak')
" Precede continued lines with '...'
set showbreak=...
- " If we have the option, indent wrapped lines as much as the first line;
- " keep the value as a script variable for the toggle function.
- let s:breakindent = v:version > 704
- \ || v:version ==# 704 && has('patch338')
- if s:breakindent
+ " If we have the option, indent wrapped lines as much as the first line
+ if has('&breakindent')
set breakindent
endif
- " Bind \b to turn off linebreak and toggle the showbreak characters on and
- " off for convenience of copypasting multiple lines from terminal emulators.
- if has('eval')
+ " \b toggles copy-pasteable linebreak settings
+ nmap <leader>b <Plug>CopyLinebreak
- " Define function
- function! s:ToggleBreak()
-
- " If linebreak is on, turn it off
- if &l:linebreak
- setlocal nolinebreak linebreak?
- setlocal showbreak=
- if s:breakindent
- setlocal nobreakindent
- endif
-
- " If it's off, turn it on
- else
- setlocal linebreak linebreak?
- setlocal showbreak=...
- if s:breakindent
- setlocal breakindent
- endif
- endif
-
- endfunction
-
- " Map \b to defined function
- nnoremap <silent> <Leader>b :<C-U>call <SID>ToggleBreak()<CR>
-
- endif
endif