blob: 759b5110e700bd53e6329b4c460b266720b03096 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
" 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
" 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)
"
"
if has('eval') && has('user_commands')
" 'c' and 't' have both been around since at least 6.1
nnoremap <silent>
\ <Leader>c
\ :<C-U>ToggleOptionFlagLocal formatoptions c<CR>
nnoremap <silent>
\ <Leader>t
\ :<C-U>ToggleOptionFlagLocal formatoptions t<CR>
" '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>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
|