Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Add option togglers

  • Loading branch information...
1 parent 7a887dd commit 728535be8d2a689f2d83de09ac36e0c73a5053c9 @tpope committed
Showing with 52 additions and 1 deletion.
  1. +6 −1 README.markdown
  2. +15 −0 doc/unimpaired.txt
  3. +31 −0 plugin/unimpaired.vim
7 README.markdown
@@ -1,7 +1,7 @@
# unimpaired.vim
Much of unimpaired.vim was extracted from my vimrc when I noticed a
-pattern: complementary pairs of mappings. They mostly fall into three
+pattern: complementary pairs of mappings. They mostly fall into four
There are mappings which are simply short normal mode aliases for
@@ -13,6 +13,11 @@ There are linewise mappings. `[<Space>` and `]<Space>` add newlines
before and after the cursor line. `[e` and `]e` exchange the current
line with the one above or below it.
+There are mappings for toggling options. `[os`, `]os`, and `cos` perform
+`:set spell`, `:set nospell`, and `:set invspell`, respectively. There's also
+`l` (`list`), `n` (`number`), `w` (`wrap`), `x` (`cursorline cursorcolumn`),
+and several others. Consult the documentation.
There are mappings for encoding and decoding. `[x` and `]x` encode and
decode XML (and HTML). `[u` and `]u` encode and decode URLs. `[y` and
`]y` do C String style escaping.
15 doc/unimpaired.txt
@@ -70,6 +70,21 @@ LINE OPERATIONS *unimpaired-lines*
*]e* *v_]e*
]e Exchange the current line with [count] lines below it.
+OPTION TOGGLING *unimpaired-toggling*
+On Off Toggle Option
+*[oc* *]oc* *coc* 'cursorline'
+*[od* *]od* *cod* 'diff' (actually |:diffthis| / |:diffoff|)
+*[oh* *]oh* *coh* 'hlsearch'
+*[oi* *]oi* *coi* 'ignorecase'
+*[ol* *]ol* *col* 'list'
+*[on* *]on* *con* 'number'
+*[or* *]or* *cor* 'relativenumber'
+*[os* *]os* *cos* 'spell'
+*[ou* *]ou* *cou* 'cursorcolumn'
+*[ow* *]ow* *cow* 'wrap'
+*[ox* *]ox* *cox* 'cursorline' 'cursorcolumn' (mnemonic: crosshairs)
ENCODING AND DECODING *unimpaired-encoding*
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
xmap ]e <Plug>unimpairedMoveDown
" }}}1
+" Option toggling {{{1
+function! s:toggle(op)
+ return eval('&'.a:op) ? 'no'.a:op : a:op
+function! s:option_map(letter, option)
+ exe 'nnoremap [o'.a:letter.' :set '.a:option.'<CR>'
+ exe 'nnoremap ]o'.a:letter.' :set no'.a:option.'<CR>'
+ exe 'nnoremap co'.a:letter.' :set <C-R>=<SID>toggle("'.a:option.'")<CR><CR>'
+call s:option_map('c', 'cursorline')
+call s:option_map('u', 'cursorcolumn')
+nnoremap [od :diffthis<CR>
+nnoremap ]od :diffoff<CR>
+nnoremap cod :<C-R>=&diff ? 'diffoff' : 'diffthis'<CR><CR>
+call s:option_map('h', 'hlsearch')
+call s:option_map('i', 'ignorecase')
+call s:option_map('l', 'list')
+nnoremap [on :set <C-R>=(exists('+rnu') && &rnu ? 'norelativenumber ' : '')<CR>number<CR>
+nnoremap ]on :set <C-R>=(exists('+rnu') && &rnu ? 'norelativenumber ' : '')<CR>nonumber<CR>
+nnoremap con :set <C-R>=(exists('+rnu') && &rnu ? 'norelativenumber ' : '').<SID>toggle('number')<CR><CR>
+call s:option_map('r', 'relativenumber')
+call s:option_map('s', 'spell')
+call s:option_map('w', 'wrap')
+nnoremap [ox :set cursorline cursorcolumn<CR>
+nnoremap ]ox :set nocursorline nocursorcolumn<CR>
+nnoremap cox :set <C-R>=&cursorline && &cursorcolumn ? 'nocursorline nocursorcolumn' : 'cursorline cursorcolumn'<CR><CR>
+" }}}1
" Encoding and decoding {{{1
function! s:string_encode(str)

0 comments on commit 728535b

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