Visual mode maps with <expr> and folds in vimscript

25 views
Skip to first unread message

Silas Silva

unread,
Oct 2, 2012, 11:25:18 AM10/2/12
to vim...@googlegroups.com
Hi again!

I'm trying to remap '}' and '{' to a function with other paragraph
definition. The map command is something like:

nnoremap <silent> <buffer> } :call <SID>ParagraphNavigate()<CR>
nnoremap <silent> <buffer> { :call <SID>ParagraphNavigate()<CR>
vnoremap <expr> <buffer> } <SID>ParagraphNavigate()
vnoremap <expr> <buffer> { <SID>ParagraphNavigate()

In maps for Visual mode, I prefer to use <expr> because setpos() or
:normal inside the function would exit Visual mode, so I work by
returning normal commands (e.g. "20j") to build <expr>.

The problem comes up when folds exist. Motion commands ("j", "k") don't
open folds, they JUMP them, and "zO" exits Visual mode. setpos() points
cursor correctly, but it exits Visual mode.

I'd like to point the cursor correctly and open any fold that is opened,
like traditional '}' and '{' do. Any tip on that?

Thank you.

--
Silas Silva

Christian Brabandt

unread,
Oct 2, 2012, 3:00:49 PM10/2/12
to vim...@googlegroups.com
Hi Silas!
I don't have a solution, but you could add gv to reselect the last
selected region.

regards,
Christian
--
Reply all
Reply to author
Forward
0 new messages