I'm trying to write a Vim script function to toggle between ->
and .
but searching for .
is seemingly impossible.
I've tried to search using ASCII (decimal and hex) and it doesn't work. It all works from normal mode and when I do my experiments it let's me cycle between the dots using n
etc but the cursor either doesn't move or goes forward once or goes to the beginning of the line etc.
The closest I got just sets my cursor to the start of the next line with a dot occurring.
How is this meant to be done? I've even upgraded to the latest version to try to fix it assuming it's some bug, but it still doesn't let me just search for a dot. Why would it be this difficult? I can't find anything when I Google. I loaded Vim without my .vimrc
and it still results the same.
I just want a search that puts the cursor on the next dot. Something like
:exec "normal /\."
or
:exec "normal /\%d46"
only that works.
Those are typed from memory and I'm away from the computer with a headache, so I'm not sure those are good examples of what I've been trying but some of what I've tried was to that ilk.
/\.
should be all you need. You definitely don't want to do:exec "normal /\."
because then you also need to explicitly include the enter key, which is complicated to add to the command line (you need to typectrl-v enter
to insert a literal enter):h function-search-undo
, which explains, why using the normal search command does not work when used as VimScript solution. Second, your useage of double quoted strings is wrong, you need to double the backslashes there, see:h expr-string
(and you would have to add theEnter
to the command to move to the search result). And finally, if you want to emulate the normal search command, it is usually better to use the explicitsearch()
function.