vi map help sought

lvirden

New Member
Joined
Oct 6, 2017
Messages
7
Reaction score
0
Credits
0
My goal is to do the following vi actions in a map

Find the 4th (or 5th if necessary) occurrence of the | symbol
add to - or change - the letters between the 4th and 5th | symbols to XXX

Seems like it would be simple.

However,

map Q 4f|lcwXXX^[
where the real command ends in an escape
results in
:map Q 4f|lcwXXX^[
The lcwXXX command is unknown.

I also tried
:map Q 5f|haXXX^[
The haXXX command is unknown.
and
:map Q 5f|hiXXX^[
The hiXXX command is unknown.


What is the technique to use so that this sequence can occur?
 


That's a tricky one... I thought it would be simple too..... :/
If you record the actions as a macro - it works absolutely fine.

I used the following keypresses to record the macro to the q register:
qq04f|lcwXXX<Esc>jq

Note: The leading 0 sends the cursor to the start of the current line. The trailing j after the escape will cause the cursor to drop to the next line.
These additional motions make it easier to repeat the macro (assuming the macro will only be used once per line).

But, there is a problem if you try to create a key mapping to fire off a command-string containing the commands stored in the q register - it throws an error message.... Odd!
Also trying to manually set the contents of a register in .vimrc using the 'let' command is problematic too...

That said - after a macro has been recorded -when you exit vim, the content of the register is written out to your .viminfo file anyway. So it shoudl be reloaded when you open vim again and should persist until that register gets clobbered with something else. So for now, other than keeping the action as a macro - I'm not sure what to suggest.

After recording your macro to the q register, you could map a keybind using something like:
:map Q @q

Other than that this has me completely stumped! I'm not sure if this is a limitation of vim, or whether there is something simple that we are missing! :/
 
Last edited:
I was working with nvi, and had the problems I mentioned above - seems like vim has reproduced limitations from other vi's.

My choice would have been to fix that stuff in vim - but perhaps the engine that executes commands just isn't complex enough to solve the issue.

Maybe I will see if I can solve this issue another way
 
I ended up building a gawk script that did what I was trying to accomplish.

Thank you for verifying that the issue wasn't just one of me not understanding vi enough.
 

Members online


Latest posts

Top