Hi,

I was trying to write a vmap for a custom text-object, and I could
move the cursor to select the text by using a search specified
directly within the vmap, but if I tried to instead put those searches
in separte functions and call those functions from within the vmap, it
didn't work.

So this worked:

    vmap ac <ESC>?^:<CR>V/^:<CR>k

but this (which is the same, but with the searches put into functions)
didn't

    function! NextSection()
        call search("^:", "Ws")
    endfunction

    function! PrevSection()
        call search("^:", "bWs")
    endfunction

    vmap ac <ESC>:call PrevSection()<CR>V:call NextSection()<CR>k

and neither did this

    function! PrevSection()
        execute "?^:"
    endfunction

    function! NextSection()
        execute "/^:"
    endfunction

    vmap ac <ESC>:call PrevSection()<CR>V:call NextSection()<CR>k

(BTW, this is for a text file format I'm using that contains sections
delimited by headings - a heading is just a line that starts with a
colon.
e.g.

    :section 1 heading

    text of section one

    ::section 1.1 heading

    some more text

    :section 2 heading

    the text of section 2
)

Something to do with executing the searches from within functions
seems to take Vim out of visual mode - thus making the vmap not work.
I haven't be able to understand why this is - would anyone be able to
explain it to me?  Is there a way to execute the search from within a
function, without going out of visual mode?

Thanks,
James.

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to