aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-11-05 01:49:01 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-11-05 01:49:01 +1300
commit3191b9632c1156f84ab18fc70b622693bdc8d858 (patch)
tree5368b5e72ad7d01f2ed201d41e9148907f74f1d6
parentMerge branch 'feature/fo-a-vim7' into develop (diff)
parentRestructure 'format' flag logic around vim-tiny (diff)
downloaddotfiles-3191b9632c1156f84ab18fc70b622693bdc8d858.tar.gz
dotfiles-3191b9632c1156f84ab18fc70b622693bdc8d858.zip
Merge branch 'feature/vim-fo-opt-toggle' into develop
* feature/vim-fo-opt-toggle: Restructure 'format' flag logic around vim-tiny Map <leader>j to toggle 'fo'-'j' flag in Vim Use :echoerr not :echomsg for 'fo'-'a' absence Use simpler error message for 'fo'-'a' absence Keep script var cache of 'a' 'fo' flag support Keep script var cache of 'j' 'fo' flag support
-rw-r--r--vim/config/format.vim70
1 files changed, 45 insertions, 25 deletions
diff --git a/vim/config/format.vim b/vim/config/format.vim
index fe6da87c..61222164 100644
--- a/vim/config/format.vim
+++ b/vim/config/format.vim
@@ -1,26 +1,35 @@
-" 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')
- set formatoptions+=j
-endif
+" All of this variable logic requires 'eval', and I can't just short-circuit
+" it due to a quirk in the way vim-tiny evaluates these expressions
+if has('eval')
+
+ " Figure out if we have the 'j' flag for 'formatoptions', to automatically
+ " delete comment leaders when joining lines; keep it in a script variable
+ let s:formatoptions_has_j = v:version > 703
+ \ || v:version ==# 703 && has('patch541')
+
+ " If we do have 'j', default to setting it
+ if s:formatoptions_has_j
+ set formatoptions+=j
+ endif
+
+ "
+ " Use toggle_option_flag.vim plugin to bind quick toggle actions for some
+ " 'formatoptions' flags; both of the above, plus:
+ "
+ " c - Automatically wrap comments at 'textwidth' (which I allow the filetypes
+ " to set for me)
+ " t - Automatically wrap text at 'textwidth' (as above)
+ "
+ " We need user-defined commands to do this.
+ "
+ if !has('user_commands')
+ finish
+ endif
-"
-" Use toggle_option_flag.vim plugin to bind quick toggle actions for some
-" 'formatoptions' flags:
-"
-" c - Automatically wrap comments at 'textwidth' (which I allow the filetypes
-" to set for me)
-" t - Automatically wrap text at 'textwidth' (as above)
-"
-" Only in Vim >= 7.0 (I think):
-"
-" a - Automatically format paragraphs, reapplying the wrap on every text
-" insertion or deletion; sometimes I want this and sometimes I
-" don't, it particularly varies when typing prose in Markdown that
-" includes headings and code
-"
-if has('eval') && has('user_commands')
+ " Figure out if we have the 'a' flag for 'formatoptions', to reapply
+ " 'textwidth' wrapping to the current paragraph on every insertion or
+ " deletion; keep in a script variable
+ let s:formatoptions_has_a = v:version > 700
" 'c' and 't' have both been around since at least 6.1
nnoremap <silent>
@@ -30,15 +39,26 @@ if has('eval') && has('user_commands')
\ <Leader>t
\ :<C-U>ToggleOptionFlagLocal formatoptions t<CR>
- " 'a' is newer
- if v:version >= 700
+ " 'a' needs testing
+ if s:formatoptions_has_a
nnoremap <silent>
\ <Leader>a
\ :<C-U>ToggleOptionFlagLocal formatoptions a<CR>
else
nnoremap <silent>
\ <Leader>a
- \ :<C-U>echomsg 'No "formatoptions" "a" flag in Vim < 7.0'<CR>
+ \ :<C-U>echoerr 'No formatoptions a-flag'<CR>
+ endif
+
+ " 'j' needs testing
+ if s:formatoptions_has_j
+ nnoremap <silent>
+ \ <Leader>j
+ \ :<C-U>ToggleOptionFlagLocal formatoptions j<CR>
+ else
+ nnoremap <silent>
+ \ <Leader>j
+ \ :<C-U>echoerr 'No formatoptions j-flag'<CR>
endif
endif