Mappings, no idea how to use.

17 views
Skip to first unread message

stosss

unread,
Nov 17, 2012, 11:33:37 PM11/17/12
to Vim Users
Greetings,

This is one of my rear occasions to ask a question. I don't have any
idea what to search for to try to figure it out.

I did not create this. I have no idea how this works or what key
strokes trigger it. Can someone help me understand how to use it? It
looks like there are two or three mappings below. Does it go in the
.vimrc or somewhere else?

" Search for selected text, forwards or backwards.
vnoremap <silent> * :<C-U>
\let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\gvy/<C-R><C-R>=substitute(
\escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\gV:call setreg('"', old_reg, old_regtype)<CR>
vnoremap <silent> # :<C-U>
\let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
\gvy?<C-R><C-R>=substitute(
\escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
\gV:call setreg('"', old_reg, old_regtype)<CR>

" Convert curly quotes to straight.
" Any argument causes substitute to confirm changes.
function! ToStraight(line1, line2, args)
let flags = 'eg'
let range = a:line1 . ',' . a:line2
if empty(a:args)
let range = 'silent ' . range
else
let flags .= 'c'
endif
let search = @/
exe range . "s/['']/'/" . flags
exe range . 's/[""]/"/' . flags
nohl
let @/ = search
endfunction
command! -nargs=? -range ToStraight call ToStraight(<line1>, <line2>, '<args>')

Thanks for the help,
Jack

John Beckett

unread,
Nov 18, 2012, 12:09:42 AM11/18/12
to vim...@googlegroups.com
stosss wrote:
> I did not create this. I have no idea how this works or what
> key strokes trigger it. Can someone help me understand how to
> use it? It looks like there are two or three mappings below.
> Does it go in the .vimrc or somewhere else?

The first extract you posted comes from:
http://vim.wikia.com/wiki/Search_for_visually_selected_text

which was mentioned along with your second extract here:
http://groups.google.com/group/vim_use/browse_thread/thread/6f7b894aa05c5bb7

In the latter, I mentioned that the code is from my vimrc, and
included some usage examples.

John

Reply all
Reply to author
Forward
0 new messages