Loading ...
Sorry, an error occurred while loading the content.

139375Re: Calling a user function via a map cancels visual mode

Expand Messages
  • skeept
    Sep 28, 2013
    • 0 Attachment
      > The : in your mappings is what ends visual mode.
      > You can't avoid this, but you can go back into visual mode with the same region as you had, simply by adding 'gv' to the end of your mapping.
      > :help gv

      Thanks Ben,
      I modified my function and mappings to the following:

      function! JumpToNextNonMatching(direction)
      let flags = ''
      if a:direction < 0
      let flags = flags . 'b'
      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)
      if a:direction == 2
      mark >
      if a:direction == -2
      mark <
      nnoremap ,n :<C-U>call JumpToNextNonMatching(1)<CR>
      nnoremap ,N :<C-U>call JumpToNextNonMatching(-1)<CR>
      vnoremap ,n :<C-U>call JumpToNextNonMatching(2)<CR>gv
      vnoremap ,N :<C-U>call JumpToNextNonMatching(-2)<CR>gv

      This almost works, if I am moving backwards it progressively increases the visual selected area, but if I am moving forward the visually selected area remains the same because it seems that `gv` brings the cursor back to the beginning of the selection...
      Any idea on how to make this work also for the forward movement?


      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@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Show all 4 messages in this topic