visually select 4 lines
This vmap works, puts '\ ' at start of each line.
vmap <F5> :s/^/\\ /e<cr>gv
visually select 4 lines
This vmap does NOT work. How to make it work?
vmap <F5> <F5>gv
" ==============================================================
These mappings all work.
let sr5='s/^/\\ /e'
nmap <silent> <F5> :<c-r>=sr5<cr><cr>
imap <silent> <F5> <c-o>:<c-r>=sr5<cr><cr>
vmap <silent> <F5> :<c-r>=sr5<cr><cr>gv
On Dec 25, 9:54 pm, Bee <200...@calcentral.com> wrote:
> visually select 4 lines
> This vmap does NOT work. How to make it work?
> vmap <F5> <F5>gv
>
This mapping does not (as you seem to intend) trigger the normal-mode
mapping for <F5>, because it never leaves visual mode. Instead, it
just continually calls itself recursively until it reaches the limit
defined in Vim, I think by a configurable option.
You probably want something like:
vmap <F5> <ESC><F5>gv
Thank you, I understand what you are saying.
Adding <esc> did allow it to work, but only on the last line of the
selection.
How can the selection be passed on?
On Dec 27, 9:46 am, Bee <200...@calcentral.com> wrote:
> Adding <esc> did allow it to work, but only on the last line of the
> selection.
>
> How can the selection be passed on?
Oops, I neglected that part.
Your explicit visual-mode mapping works on every line because pressing
':' in visual mode automatically enters a range of '<,'> to your Ex
command, which means to run the Ex command on the visual selection. I
do not think you will be able to use <F5> in your mapping after all,
without some logic to determine what mode you are in, in which case it
would just be easier to explicitly specify the command in a visual-
mode mapping.
You could make the "implementation" mapping be defined for visual
mode, then map normal-mode <F5> to V<F5> and insert mode <F5> to
<C-o>V<F5>, or something like that, but then using <F5> in normal or
insert mode would clobber the '< and '> marks. You could split out
the important part of the implementation into a cmap, and have normal,
insert, and visual all be mapped to something that gets into
command-line mode with the correct leading range, and then invokes
that cmap, but that's almost certainly more trouble than it's worth.
It's probably best to just define the map multiple times.
~Matt
No, because the {lhs} is at the start of the {rhs}, see ":help
recursive-mapping". In this case the F5 is not mapped again, and so does
what F5 does by default in Visual mode (i.e. nothing) followed by gv
>
> You probably want something like:
>
> vmap<F5> <ESC><F5>gv
>
Best regards,
Tony.
--
Eternal nothingness is fine if you happen to be dressed for it.
-- Woody Allen