Thursday, September 26, 2013

Calling a user function via a map cancels visual mode

I have the following function and mappings:

function! JumpToNextNonMatching(direction)
let flags = ''
if a:direction == -1
let flags = flags . 'b'
endif
let ntimes = max([v:count, 1])
let i = 1
while i <= ntimes
let i = i + 1
let curr_line = getline('.')
let spattern = '^[^' . curr_line[0] . '][^' . curr_line[1] . ']'
call search(spattern, flags)
endwhile
endfunction
noremap ,n :<C-U>call JumpToNextNonMatching(1)<CR><C-L>
noremap ,N :<C-U>call JumpToNextNonMatching(-1)<CR><C-L>

The idea is simply to jump to a previous or next line not matching the beggining of current line.

But if I am in visual mode and use one of the mappings then visual mode is cancelled.
Any suggestions on howto properly define the function of the mapping so when I use it I stay in visual mode (with the selection resulting of applying the map, of course).

Thanks,
Jorge

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: