Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

updated unimpaired

  • Loading branch information...
commit 6aace099d3c32dffb1de79b869a5b70ed1c33c89 1 parent d6e5ff8
Dave Ray authored
1  bundle/tpope-vim-unimpaired-e801372/.gitignore
... ... @@ -0,0 +1 @@
  1 +/doc/tags
61 bundle/tpope-vim-unimpaired-e801372/README.markdown
Source Rendered
... ... @@ -0,0 +1,61 @@
  1 +unimpaired.vim
  2 +==============
  3 +
  4 +Much of unimpaired.vim was extracted from my vimrc when I noticed a
  5 +pattern: complementary pairs of mappings. They mostly fall into three
  6 +categories.
  7 +
  8 +There are mappings which are simply short normal mode aliases for
  9 +commonly used ex commands. `]q` is :cnext. `[q` is :cprevious. `]a` is
  10 +:next. `[b` is :bprevious. See the documentation for the full set of
  11 +20 mappings and mnemonics. All of them take a count.
  12 +
  13 +There are linewise mappings. `[<Space>` and `]<Space>` add newlines
  14 +before and after the cursor line. `[e` and `]e` exchange the current
  15 +line with the one above or below it.
  16 +
  17 +There are mappings for encoding and decoding. `[x` and `]x` encode and
  18 +decode XML (and HTML). `[u` and `]u` encode and decode URLs. `[y` and
  19 +`]y` do C String style escaping. `[Y` and `]Y` encode and decode Base64.
  20 +
  21 +And in the miscellaneous category, there's `[o` and `]o` to go to the
  22 +next/previous file in the directory, and `[n` and `]n` to jump between
  23 +SCM conflict markers.
  24 +
  25 +The `.` command will work with the linewise encoding mappings if you
  26 +install [repeat.vim](https://github.com/tpope/vim-repeat).
  27 +
  28 +Installation
  29 +------------
  30 +
  31 +If you don't have a preferred installation method, I recommend
  32 +installing [pathogen.vim](https://github.com/tpope/vim-pathogen), and
  33 +then simply copy and paste:
  34 +
  35 + cd ~/.vim/bundle
  36 + git clone git://github.com/tpope/vim-unimpaired.git
  37 +
  38 +Once help tags have been generated, you can view the manual with
  39 +`:help unimpaired`.
  40 +
  41 +Contributing
  42 +------------
  43 +
  44 +See the contribution guidelines for
  45 +[pathogen.vim](https://github.com/tpope/vim-pathogen#readme).
  46 +
  47 +Self-Promotion
  48 +--------------
  49 +
  50 +Like unimpaired.vim? Follow the repository on
  51 +[GitHub](https://github.com/tpope/vim-unimpaired) and vote for it on
  52 +[vim.org](http://www.vim.org/scripts/script.php?script_id=1697). And if
  53 +you're feeling especially charitable, follow [tpope](http://tpo.pe/) on
  54 +[Twitter](http://twitter.com/tpope) and
  55 +[GitHub](https://github.com/tpope).
  56 +
  57 +License
  58 +-------
  59 +
  60 +Copyright (c) Tim Pope. Distributed under the same terms as Vim itself.
  61 +See `:help license`.
18 ...e/tpope-vim-unimpaired-5b7a9c3/doc/unimpaired.txt → ...e/tpope-vim-unimpaired-e801372/doc/unimpaired.txt
@@ -44,6 +44,14 @@ is "args" and for the "q" commands is "quickfix".
44 44 ]o Go to the file succeeding the current one
45 45 alphabetically in the current file's directory.
46 46
  47 + *[n*
  48 +[n Go to the previous SCM conflict marker. Try d[n
  49 + inside a conflict.
  50 +
  51 + *]n*
  52 +]n Go to the next SCM conflict marker. Try d]n inside a
  53 + conflict.
  54 +
47 55 LINE OPERATIONS *unimpaired-lines*
48 56
49 57 *[<Space>*
@@ -96,6 +104,16 @@ Mnenomic: encoding always comes before decoding; "[" always comes before "]".
96 104 ]yy
97 105 {Visual}]y
98 106
  107 + *[Y* *[YY* *v_[Y*
  108 +[Y{motion} Base64 encode.
  109 +[YY foo bar => Zm9vIGJhcg==
  110 +{Visual}[Y
  111 +
  112 + *]Y* *]YY* *v_]Y*
  113 +]Y{motion} Base64 decode
  114 +]YY Input length must be a multiple of 4.
  115 +{Visual}]Y
  116 +
99 117 TODO *unimpaired-todo*
100 118
101 119 Avoid munging null characters when encoding and decoding.
149 ...pope-vim-unimpaired-5b7a9c3/plugin/unimpaired.vim → ...pope-vim-unimpaired-e801372/plugin/unimpaired.vim
... ... @@ -1,15 +1,13 @@
1 1 " unimpaired.vim - Pairs of handy bracket mappings
2   -" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
  2 +" Maintainer: Tim Pope <http://tpo.pe/>
3 3 " Version: 1.1
  4 +" GetLatestVimScripts: 1590 1 :AutoInstall: unimpaired.vim
4 5
5 6 if exists("g:loaded_unimpaired") || &cp || v:version < 700
6 7 finish
7 8 endif
8 9 let g:loaded_unimpaired = 1
9 10
10   -let s:cpo_save = &cpo
11   -set cpo&vim
12   -
13 11 " Next and previous {{{1
14 12
15 13 function! s:MapNextFamily(map,cmd)
@@ -77,18 +75,84 @@ nmap ]o <Plug>unimpairedONext
77 75 nmap [o <Plug>unimpairedOPrevious
78 76
79 77 " }}}1
  78 +" Diff {{{1
  79 +
  80 +nmap [n <Plug>unimpairedContextPrevious
  81 +nmap ]n <Plug>unimpairedContextNext
  82 +omap [n <Plug>unimpairedContextPrevious
  83 +omap ]n <Plug>unimpairedContextNext
  84 +
  85 +nnoremap <silent> <Plug>unimpairedContextPrevious :call <SID>Context(1)<CR>
  86 +nnoremap <silent> <Plug>unimpairedContextNext :call <SID>Context(0)<CR>
  87 +onoremap <silent> <Plug>unimpairedContextPrevious :call <SID>ContextMotion(1)<CR>
  88 +onoremap <silent> <Plug>unimpairedContextNext :call <SID>ContextMotion(0)<CR>
  89 +
  90 +function! s:Context(reverse)
  91 + call search('^@@ .* @@\|^[<=>|]\{7}[<=>|]\@!', a:reverse ? 'bW' : 'W')
  92 +endfunction
  93 +
  94 +function! s:ContextMotion(reverse)
  95 + if a:reverse
  96 + -
  97 + endif
  98 + call search('^@@ .* @@\|^diff \|^[<=>|]\{7}[<=>|]\@!', 'bWc')
  99 + if getline('.') =~# '^diff '
  100 + let end = search('^diff ', 'Wn') - 1
  101 + if end < 0
  102 + let end = line('$')
  103 + endif
  104 + elseif getline('.') =~# '^@@ '
  105 + let end = search('^@@ .* @@\|^diff ', 'Wn') - 1
  106 + if end < 0
  107 + let end = line('$')
  108 + endif
  109 + elseif getline('.') =~# '^=\{7\}'
  110 + +
  111 + let end = search('^>\{7}>\@!', 'Wnc')
  112 + elseif getline('.') =~# '^[<=>|]\{7\}'
  113 + let end = search('^[<=>|]\{7}[<=>|]\@!', 'Wn') - 1
  114 + else
  115 + return
  116 + endif
  117 + if end > line('.')
  118 + execute 'normal! V'.(end - line('.')).'j'
  119 + elseif end == line('.')
  120 + normal! V
  121 + endif
  122 +endfunction
  123 +
  124 +" }}}1
80 125 " Line operations {{{1
81 126
82   -nnoremap <silent> <Plug>unimpairedBlankUp :<C-U>put!=repeat(nr2char(10),v:count)<Bar>']+1<CR>
83   -nnoremap <silent> <Plug>unimpairedBlankDown :<C-U>put =repeat(nr2char(10),v:count)<Bar>'[-1<CR>
  127 +function! s:BlankUp(count) abort
  128 + put!=repeat(nr2char(10), a:count)
  129 + ']+1
  130 + silent! call repeat#set("\<Plug>unimpairedBlankUp", a:count)
  131 +endfunction
  132 +
  133 +function! s:BlankDown(count) abort
  134 + put =repeat(nr2char(10), a:count)
  135 + '[-1
  136 + silent! call repeat#set("\<Plug>unimpairedBlankDown", a:count)
  137 +endfunction
  138 +
  139 +nnoremap <silent> <Plug>unimpairedBlankUp :<C-U>call <SID>BlankUp(v:count1)<CR>
  140 +nnoremap <silent> <Plug>unimpairedBlankDown :<C-U>call <SID>BlankDown(v:count1)<CR>
84 141
85 142 nmap [<Space> <Plug>unimpairedBlankUp
86 143 nmap ]<Space> <Plug>unimpairedBlankDown
87 144
88   -nnoremap <silent> <Plug>unimpairedMoveUp :<C-U>exe 'norm m`'<Bar>exe 'move--'.v:count1<CR>``
89   -nnoremap <silent> <Plug>unimpairedMoveDown :<C-U>exe 'norm m`'<Bar>exe 'move+'.v:count1<CR>``
90   -xnoremap <silent> <Plug>unimpairedMoveUp :<C-U>exe 'norm m`'<Bar>exe '''<,''>move--'.v:count1<CR>``
91   -xnoremap <silent> <Plug>unimpairedMoveDown :<C-U>exe 'norm m`'<Bar>exe '''<,''>move''>+'.v:count1<CR>``
  145 +function! s:Move(cmd, count, map) abort
  146 + normal! m`
  147 + exe 'move'.a:cmd.a:count
  148 + norm! ``
  149 + silent! call repeat#set("\<Plug>unimpairedMove".a:map, a:count)
  150 +endfunction
  151 +
  152 +nnoremap <silent> <Plug>unimpairedMoveUp :<C-U>call <SID>Move('--',v:count1,'Up')<CR>
  153 +nnoremap <silent> <Plug>unimpairedMoveDown :<C-U>call <SID>Move('+',v:count1,'Down')<CR>
  154 +xnoremap <silent> <Plug>unimpairedMoveUp :<C-U>exe 'normal! m`'<Bar>exe '''<,''>move--'.v:count1<CR>``
  155 +xnoremap <silent> <Plug>unimpairedMoveDown :<C-U>exe 'normal! m`'<Bar>exe '''<,''>move''>+'.v:count1<CR>``
92 156
93 157 nmap [e <Plug>unimpairedMoveUp
94 158 nmap ]e <Plug>unimpairedMoveDown
@@ -122,6 +186,65 @@ function! s:UrlDecode(str)
122 186 return substitute(str,'%\(\x\x\)','\=nr2char("0x".submatch(1))','g')
123 187 endfunction
124 188
  189 +let g:unimpaired_base64_chars = map(range(char2nr('A'),char2nr('Z')),'nr2char(v:val)')
  190 + \ + map(range(char2nr('a'),char2nr('z')),'nr2char(v:val)')
  191 + \ + map(range(char2nr('0'),char2nr('9')),'nr2char(v:val)')
  192 + \ + ['+','/']
  193 +
  194 +let g:unimpaired_base64_filler = '='
  195 +let g:unimpaired_base64_reverse_map = {}
  196 +let s:pos = 0
  197 +for s:char in g:unimpaired_base64_chars
  198 + let g:unimpaired_base64_reverse_map[s:char] = s:pos
  199 + let s:pos = s:pos + 1
  200 +endfor
  201 +unlet s:pos
  202 +
  203 +function! s:Base64Encode(str)
  204 + " Respect current file encoding
  205 + let to_be_encoded=a:str
  206 + let encoded = ''
  207 + while len(to_be_encoded) > 2
  208 + let encoded .= g:unimpaired_base64_chars[char2nr(to_be_encoded[0])/4]
  209 + \ . g:unimpaired_base64_chars[16*(char2nr(to_be_encoded[0])%4 )+char2nr(to_be_encoded[1])/16]
  210 + \ . g:unimpaired_base64_chars[4 *(char2nr(to_be_encoded[1])%16)+char2nr(to_be_encoded[2])/64]
  211 + \ . g:unimpaired_base64_chars[char2nr(to_be_encoded[2])%64]
  212 + let to_be_encoded = to_be_encoded[3:]
  213 + endwhile
  214 + if len(to_be_encoded) == 2
  215 + let encoded .= g:unimpaired_base64_chars[char2nr(to_be_encoded[0])/4]
  216 + \ . g:unimpaired_base64_chars[16*(char2nr(to_be_encoded[0])%4 )+char2nr(to_be_encoded[1])/16]
  217 + \ . g:unimpaired_base64_chars[4 *(char2nr(to_be_encoded[1])%16)]
  218 + \ . g:unimpaired_base64_filler
  219 + elseif len(to_be_encoded) == 1
  220 + let encoded .= g:unimpaired_base64_chars[char2nr(to_be_encoded[0])/4]
  221 + \ . g:unimpaired_base64_chars[16*(char2nr(to_be_encoded[0])%4 )]
  222 + \ . g:unimpaired_base64_filler
  223 + \ . g:unimpaired_base64_filler
  224 + endif
  225 + return encoded
  226 +endfunction
  227 +
  228 +function! s:Base64Decode(str)
  229 + let to_be_decoded=a:str
  230 + let decoded=''
  231 + while len(to_be_decoded) % 4 == 0
  232 + let decoded .= nr2char( 4 * (g:unimpaired_base64_reverse_map[to_be_decoded[0]] )
  233 + \ + (g:unimpaired_base64_reverse_map[to_be_decoded[1]] / 16 )
  234 + \)
  235 + if to_be_decoded[2] !=# g:unimpaired_base64_filler
  236 + let decoded .= nr2char(16 * (g:unimpaired_base64_reverse_map[to_be_decoded[1]] % 16) + (g:unimpaired_base64_reverse_map[to_be_decoded[2]]/4))
  237 + if to_be_decoded[3] !=# g:unimpaired_base64_filler
  238 + let decoded .= nr2char(64 * (g:unimpaired_base64_reverse_map[to_be_decoded[2]] % 4) + g:unimpaired_base64_reverse_map[to_be_decoded[3]])
  239 + endif
  240 + endif
  241 + let to_be_decoded = to_be_decoded[4:]
  242 + if empty(to_be_decoded)
  243 + return decoded
  244 + endif
  245 + endwhile
  246 +endfunction
  247 +
125 248 " HTML entities {{{2
126 249
127 250 let g:unimpaired_html_entities = {
@@ -267,9 +390,9 @@ call s:MapTransform('UrlEncode','[u')
267 390 call s:MapTransform('UrlDecode',']u')
268 391 call s:MapTransform('XmlEncode','[x')
269 392 call s:MapTransform('XmlDecode',']x')
  393 +call s:MapTransform('Base64Encode','[Y')
  394 +call s:MapTransform('Base64Decode',']Y')
270 395
271 396 " }}}1
272 397
273   -let &cpo = s:cpo_save
274   -
275   -" vim:set ft=vim ts=8 sw=2 sts=2:
  398 +" vim:set sw=2 sts=2:

0 comments on commit 6aace09

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