I'm running a bit of code in Vim and having a problem (I think) with not being in the correct mode. I'm trying to get the text between either '< >' or '[ ]' into a register. At point code starts below I know the cursor is between a pair of brackets, but I don't know what kind the brackets are:
" put text in x reg if I'm in <> brackets
normal! vi<"xy
" put in x reg if I'm in [] brackets
if len(@x) < 7
normal! vi["xy
endif
[. .. . more code follows making use of
value in x register]
If I'm clicking between <> brackets the rest of the code works okay, alhough I may not be in normal mode. If I'm clicking between the [] brackets then it doesn't work at all, and the literal text ["xy gets inserted at cursor position.
I've tried a couple different workarounds, e.g., trying to put into the keystrings (or a separate normal command) or using 'visual!' command after each visual part. Can't get things going with and the Visual! command avoids the character inserts on second part but but also seems to screw up getting the visual match into the x register.
I'm a little confused and not sure what mode I'm in exactly at all parts of script: normal, visual, or insert. I run through things manually and it seems to work fine but if I do it programmatically it behaves unexpectedly.
Is there some simple thing I'm missing? I could do what I want another way, but this method (at first look) seemed like easiest and most straightforward. Is it?
Thanks for any help.