135843Re: How to determine the start of a visual block (C-V) when it starts in the void?
- Jan 30, 2013On Wednesday, January 30, 2013 9:49:52 AM UTC-6, Axel Bender wrote:
> Hi Ben,This should be:
> try this:
> xnoremap <silent> _C :<C-U>call SomeFunc()<CR> " My current mapping
> xnoremap <silent><expr>_D SomeFunc()<CR> " John's proposal
> xnoremap <silent> _E SomeFunc()<CR> " same w/o <expr>
xnoremap <silent> _C :<C-U>call SomeFunc()<CR>
xnoremap <silent><expr>_D SomeFunc()
Your third mapping will never work, why do you expect it to? It is like pressing the keys S o m e F u n c ( ) and then <CR> in sequence, in visual mode. The S will replace the entire visual selection and enter the rest of the text in insert mode.
> fun! SomeFunc()I modified this to echo the columns instead of doing whatever the for loop does.
> let col = virtcol("'<") - 1
> let ecol = virtcol("'>")
> for l in range(line("'<"), line("'>"))
> call setline(l, strpart(getline(l), col, ecol - col))
> Select (ve=block) a visual block from "Fun" down to "ol ", the press _C, _D, and _E. Repeat the same (_C, _E) with an extended block (one line further down - in the void).The first mapping clears visual mode and echos 1 on empty lines, as you reported, and as I and John expect, BECAUSE THE : ENDS VISUAL MODE. There is nothing you can do about this. There is nothing Vim SHOULD do about this. Visual mode is over. Done. Complete. You are no longer in visual block mode so the cursor can no longer be outside the real text.
The second mapping works as expected, getting the virtual column of the visual block selection, because IT NEVER LEAVES VISUAL MODE.
Note to call a function in a visual mode <expr> mapping, the function should return the text desired for the RHS of the mapping. In this case, adding:
to the end of the mapping lets it do no further action on the visual selection.
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.
- << Previous post in topic Next post in topic >>