|
|
| Line 19: |
Line 19: |
| |
<pre> |
|
<pre> |
| |
before: bla bla Selected Text bla bla |
|
before: bla bla Selected Text bla bla |
| − |
:'<,'>call Surround('"', '"')<CR> |
+ |
:'<,'>call Surround('"', '"')<CR> |
| |
after : bla bla "Selected Text" bla bla |
|
after : bla bla "Selected Text" bla bla |
| |
</pre> |
|
</pre> |
| Line 25: |
Line 25: |
| |
<pre> |
|
<pre> |
| |
fun! Surround(s1, s2) range |
|
fun! Surround(s1, s2) range |
| − |
exe "normal vgvmboma\<ESC>" |
+ |
exe "normal vgvmboma\<Esc>" |
| |
normal `a |
|
normal `a |
| |
let lineA = line(".") |
|
let lineA = line(".") |
| Line 33: |
Line 33: |
| |
let columnB = col(".") |
|
let columnB = col(".") |
| |
" exchange marks |
|
" exchange marks |
| − |
if lineA > lineB || lineA <= lineB && columnA > columnB |
+ |
if lineA > lineB || lineA <= lineB && columnA > columnB |
| |
" save b in c |
|
" save b in c |
| |
normal mc |
|
normal mc |
| Line 41: |
Line 41: |
| |
normal `cma |
|
normal `cma |
| |
endif |
|
endif |
| − |
exe "normal `ba" . a:s2 . "\<ESC>`ai" . a:s1 . "\<ESC>" |
+ |
exe "normal `ba" . a:s2 . "\<Esc>`ai" . a:s1 . "\<Esc>" |
| |
endfun |
|
endfun |
| |
</pre> |
|
</pre> |
| Line 50: |
Line 50: |
| |
before: bla bla Selec |
|
before: bla bla Selec |
| |
ted Text bla bla |
|
ted Text bla bla |
| − |
:'<,'>call Surround('"', '"')<CR> |
+ |
:'<,'>call Surround('"', '"')<CR> |
| |
after : bla bla "Selec |
|
after : bla bla "Selec |
| |
ted Text" bla bla |
|
ted Text" bla bla |
| Line 58: |
Line 58: |
| |
|
|
|
| |
<pre> |
|
<pre> |
| − |
vnoremap _" :call Surround('"', '"')<CR> |
+ |
vnoremap _" :call Surround('"', '"')<CR> |
| − |
vnoremap _( :call Surround('(', ')')<CR> |
+ |
vnoremap _( :call Surround('(', ')')<CR> |
| − |
vnoremap _[ :call Surround('[', ']')<CR> |
+ |
vnoremap _[ :call Surround('[', ']')<CR> |
| − |
vnoremap _{ :call Surround('{', '}')<CR> |
+ |
vnoremap _{ :call Surround('{', '}')<CR> |
| |
</pre> |
|
</pre> |
| |
|
|
|
| Line 67: |
Line 67: |
| |
|
|
|
| |
<pre> |
|
<pre> |
| − |
command! -range -nargs=* Sur call Surround(<f-args>) |
+ |
command! -range -nargs=* Sur call Surround(<f-args>) |
| |
</pre> |
|
</pre> |
| |
|
|
|
| |
<pre> |
|
<pre> |
| |
before: bla bla Selected Text bla bla |
|
before: bla bla Selected Text bla bla |
| − |
:'<,'>Sur (<\ - -\ >) |
+ |
:'<,'>Sur (<\ - -\ >) |
| − |
after : bla bla (< -Selected Text- >) bla bla |
+ |
after : bla bla (< -Selected Text- >) bla bla |
| |
</pre> |
|
</pre> |
| |
|
|
|
| Line 79: |
Line 79: |
| |
<pre> |
|
<pre> |
| |
"wrap highlighted text in doublequotes |
|
"wrap highlighted text in doublequotes |
| − |
:vmap [q "zdi"<C-R>z" |
+ |
:vmap [q "zdi"<C-R>z" |
| |
"these wrap ansi color character commands around the visualmode selected text - good for adding |
|
"these wrap ansi color character commands around the visualmode selected text - good for adding |
| |
"color to stdout [b=blue, [r=red, etc |
|
"color to stdout [b=blue, [r=red, etc |
| − |
:vmap [b "zdi<C-V><ESC>[1;34m<C-R>z<C-V><ESC>[0m<ESC> |
+ |
:vmap [b "zdi<C-V><Esc>[1;34m<C-R>z<C-V><Esc>[0m<Esc> |
| − |
:vmap [r "zdi<C-V><ESC>[1;31m<C-R>z<C-V><ESC>[0m<ESC> |
+ |
:vmap [r "zdi<C-V><Esc>[1;31m<C-R>z<C-V><Esc>[0m<Esc> |
| − |
:vmap [m "zdi<C-V><ESC>[1;35m<C-R>z<C-V><ESC>[0m<ESC> |
+ |
:vmap [m "zdi<C-V><Esc>[1;35m<C-R>z<C-V><Esc>[0m<Esc> |
| − |
:vmap [c "zdi<C-V><ESC>[1;36m<C-R>z<C-V><ESC>[0m<ESC> |
+ |
:vmap [c "zdi<C-V><Esc>[1;36m<C-R>z<C-V><Esc>[0m<Esc> |
| − |
:vmap [y "zdi<C-V><ESC>[1;33m<C-R>z<C-V><ESC>[0m<ESC> |
+ |
:vmap [y "zdi<C-V><Esc>[1;33m<C-R>z<C-V><Esc>[0m<Esc> |
| − |
:vmap [g "zdi<C-V><ESC>[1;32m<C-R>z<C-V><ESC>[0m<ESC> |
+ |
:vmap [g "zdi<C-V><Esc>[1;32m<C-R>z<C-V><Esc>[0m<Esc> |
| |
</pre> |
|
</pre> |
| |
|
|
|
This tip is deprecated for the following reasons:
This tip is deprecated by the surround plugin.
Inspired by VimTip987 I wrote a small function to surround selected text in visual-mode with text.
For example, to quote a selection:
before: bla bla Selected Text bla bla
:'<,'>call Surround('"', '"')<CR>
after : bla bla "Selected Text" bla bla
fun! Surround(s1, s2) range
exe "normal vgvmboma\<Esc>"
normal `a
let lineA = line(".")
let columnA = col(".")
normal `b
let lineB = line(".")
let columnB = col(".")
" exchange marks
if lineA > lineB || lineA <= lineB && columnA > columnB
" save b in c
normal mc
" store a in b
normal `amb
" set a to old b
normal `cma
endif
exe "normal `ba" . a:s2 . "\<Esc>`ai" . a:s1 . "\<Esc>"
endfun
Surround also works for a selection over more than one line.
before: bla bla Selec
ted Text bla bla
:'<,'>call Surround('"', '"')<CR>
after : bla bla "Selec
ted Text" bla bla
Some handy mappings:
vnoremap _" :call Surround('"', '"')<CR>
vnoremap _( :call Surround('(', ')')<CR>
vnoremap _[ :call Surround('[', ']')<CR>
vnoremap _{ :call Surround('{', '}')<CR>
I defined it as a command to perform fast on-demand-surroundings
command! -range -nargs=* Sur call Surround(<f-args>)
before: bla bla Selected Text bla bla
:'<,'>Sur (<\ - -\ >)
after : bla bla (< -Selected Text- >) bla bla
"wrap highlighted text in doublequotes
:vmap [q "zdi"<C-R>z"
"these wrap ansi color character commands around the visualmode selected text - good for adding
"color to stdout [b=blue, [r=red, etc
:vmap [b "zdi<C-V><Esc>[1;34m<C-R>z<C-V><Esc>[0m<Esc>
:vmap [r "zdi<C-V><Esc>[1;31m<C-R>z<C-V><Esc>[0m<Esc>
:vmap [m "zdi<C-V><Esc>[1;35m<C-R>z<C-V><Esc>[0m<Esc>
:vmap [c "zdi<C-V><Esc>[1;36m<C-R>z<C-V><Esc>[0m<Esc>
:vmap [y "zdi<C-V><Esc>[1;33m<C-R>z<C-V><Esc>[0m<Esc>
:vmap [g "zdi<C-V><Esc>[1;32m<C-R>z<C-V><Esc>[0m<Esc>