On Wed, January 30, 2013 16:49, Axel Bender wrote:
> Hi Ben,
>
> try this:
>
> xnoremap <silent> _C :<C-U>call SomeFunc()<CR> " My current
> mapping
> xnoremap <silent><expr>_D SomeFunc()<CR> " John's proposal
For expression mappings, you don't need the trailing <CR>, because
they don't execute the rhs of the mapping, but rather evaluate it.
> xnoremap <silent> _E SomeFunc()<CR> " same w/o <expr>
Not sure, what you are expecting here. This won't work.
>
> fun! SomeFunc()
> let col = virtcol("'<") - 1
> let ecol = virtcol("'>")
>
> for l in range(line("'<"), line("'>"))
> call setline(l, strpart(getline(l), col, ecol - col))
> endfor
> endf
>
> 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 problem is, expression-mappings are not allowed to change the
text, therefore they can't work exactly the same. To work around this
issue, they need to return what the user would type, which would then
be executed. E.g. for your usecase, use this function (there might
actually be better ways to achieve what you want, I haven't thought
about it):
xnoremap <silent> _C :<C-U>call SomeFunc()<CR> " My current mapping
xnoremap <silent><expr>_D SomeFunc1() " John's proposal
[匽
fun! SomeFunc1()
let col = virtcol("'<") - 1
let ecol = virtcol("'>")
let range= range(line("'<"), line("'>"))
let result=printf(": for l in %s|".
\ "call setline(l, strpart(getline(l), %d, %d))|".
\ "endfor", string(range), col, ecol-col)
return result
endf
regards,
Christian
--
--
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:
Post a Comment