On Thu, 15 Jun 2006, Mathias Michaelis wrote:
Hi Gerald
Given a new buffer with these 2 lines:
1x2x3x4x
5x6x7x8x
Put cursor on "1". Then type:
v3:<C-u>/x<CR>
where <C-u> is Ctrl-u and <CR> is Enter.
Shouldn't the cursor be on the "x" between "3" & "4" instead of on "5",
just like you would with typing:
3/x<CR>
instead ?
This behaviour of Vim has nothing to do with its visual mode, but
with its history. To do want you want, type
v3/x<CR>
without any colon(:).
If you type a colon(:), you must enter an ex-command -- by observing
its syntax rules: Every ex-command can be preceded by one or two
line numbers. The simplest ex-command is "go to a line", which can
be entered simply by the corresponding line number. E.g. ":7<CR>"
(without quotes) go to line 7.
[snip]
Yes, Ex commands do work linewise, which explains the behavior.
What if we had a count stored in the variable g:mycount, and wanted to
induce that count for a search / in a mapping?
For instance, with
map <F2> /
hitting "3" + <F2> will have the search do with a count of 3 (taken from
v:count and v:count1). How would we have it so it takes from g:mycount
instead?
One foreseeable way is to grab the search expression as an input(), and
do
:exe "norm ".g:mycount."/".searchinput."\<CR>"
Is this the only way? The downside to this approach would be
quoting problems with the searchinput expression, and we'd also lose
operator-pending ability.
Thanks :)
--
Gerald