Skip to content
This repository
Browse code

Add option togglers

  • Loading branch information...
commit 728535be8d2a689f2d83de09ac36e0c73a5053c9 1 parent 7a887dd
Tim Pope authored January 28, 2013
7  README.markdown
Source Rendered
... ...
@@ -1,7 +1,7 @@
1 1
 # unimpaired.vim
2 2
 
3 3
 Much of unimpaired.vim was extracted from my vimrc when I noticed a
4  
-pattern: complementary pairs of mappings.  They mostly fall into three
  4
+pattern: complementary pairs of mappings.  They mostly fall into four
5 5
 categories.
6 6
 
7 7
 There are mappings which are simply short normal mode aliases for
@@ -13,6 +13,11 @@ There are linewise mappings. `[<Space>` and `]<Space>` add newlines
13 13
 before and after the cursor line. `[e` and `]e` exchange the current
14 14
 line with the one above or below it.
15 15
 
  16
+There are mappings for toggling options. `[os`, `]os`, and `cos` perform
  17
+`:set spell`, `:set nospell`, and `:set invspell`, respectively.  There's also
  18
+`l` (`list`), `n` (`number`), `w` (`wrap`), `x` (`cursorline cursorcolumn`),
  19
+and several others.  Consult the documentation.
  20
+
16 21
 There are mappings for encoding and decoding. `[x` and `]x` encode and
17 22
 decode XML (and HTML). `[u` and `]u` encode and decode URLs. `[y` and
18 23
 `]y` do C String style escaping.
15  doc/unimpaired.txt
@@ -70,6 +70,21 @@ LINE OPERATIONS                                 *unimpaired-lines*
70 70
                                                 *]e* *v_]e*
71 71
 ]e                      Exchange the current line with [count] lines below it.
72 72
 
  73
+OPTION TOGGLING                                 *unimpaired-toggling*
  74
+
  75
+On	Off	Toggle	Option
  76
+*[oc*	*]oc*	*coc*	'cursorline'
  77
+*[od*	*]od*	*cod*	'diff' (actually |:diffthis| / |:diffoff|)
  78
+*[oh*	*]oh*	*coh*	'hlsearch'
  79
+*[oi*	*]oi*	*coi*	'ignorecase'
  80
+*[ol*	*]ol*	*col*	'list'
  81
+*[on*	*]on*	*con*	'number'
  82
+*[or*	*]or*	*cor*	'relativenumber'
  83
+*[os*	*]os*	*cos*	'spell'
  84
+*[ou*	*]ou*	*cou*	'cursorcolumn'
  85
+*[ow*	*]ow*	*cow*	'wrap'
  86
+*[ox*	*]ox*	*cox*	'cursorline' 'cursorcolumn' (mnemonic: crosshairs)
  87
+
73 88
 ENCODING AND DECODING                           *unimpaired-encoding*
74 89
 
75 90
 Each of these operations has a map that takes a motion, a map that
31  plugin/unimpaired.vim
@@ -182,6 +182,37 @@ xmap [e <Plug>unimpairedMoveUp
182 182
 xmap ]e <Plug>unimpairedMoveDown
183 183
 
184 184
 " }}}1
  185
+" Option toggling {{{1
  186
+
  187
+function! s:toggle(op)
  188
+  return eval('&'.a:op) ? 'no'.a:op : a:op
  189
+endfunction
  190
+
  191
+function! s:option_map(letter, option)
  192
+  exe 'nnoremap [o'.a:letter.' :set '.a:option.'<CR>'
  193
+  exe 'nnoremap ]o'.a:letter.' :set no'.a:option.'<CR>'
  194
+  exe 'nnoremap co'.a:letter.' :set <C-R>=<SID>toggle("'.a:option.'")<CR><CR>'
  195
+endfunction
  196
+
  197
+call s:option_map('c', 'cursorline')
  198
+call s:option_map('u', 'cursorcolumn')
  199
+nnoremap [od :diffthis<CR>
  200
+nnoremap ]od :diffoff<CR>
  201
+nnoremap cod :<C-R>=&diff ? 'diffoff' : 'diffthis'<CR><CR>
  202
+call s:option_map('h', 'hlsearch')
  203
+call s:option_map('i', 'ignorecase')
  204
+call s:option_map('l', 'list')
  205
+nnoremap [on :set <C-R>=(exists('+rnu') && &rnu ? 'norelativenumber ' : '')<CR>number<CR>
  206
+nnoremap ]on :set <C-R>=(exists('+rnu') && &rnu ? 'norelativenumber ' : '')<CR>nonumber<CR>
  207
+nnoremap con :set <C-R>=(exists('+rnu') && &rnu ? 'norelativenumber ' : '').<SID>toggle('number')<CR><CR>
  208
+call s:option_map('r', 'relativenumber')
  209
+call s:option_map('s', 'spell')
  210
+call s:option_map('w', 'wrap')
  211
+nnoremap [ox :set cursorline cursorcolumn<CR>
  212
+nnoremap ]ox :set nocursorline nocursorcolumn<CR>
  213
+nnoremap cox :set <C-R>=&cursorline && &cursorcolumn ? 'nocursorline nocursorcolumn' : 'cursorline cursorcolumn'<CR><CR>
  214
+
  215
+" }}}1
185 216
 " Encoding and decoding {{{1
186 217
 
187 218
 function! s:string_encode(str)

0 notes on commit 728535b

Please sign in to comment.
Something went wrong with that request. Please try again.