2

(This question pertains to nvi instead of vim.)

To facilitate editing, I created the following mappings map! ( (?)@^[F?xi map! [ [?]@^[F?xi map! { {?}@^[F?xi so that entering ( will insert (|)@, where | denote the cursor position (in insert mode).

Now, what I want is that when I press <TAB>, the cursor will jump to the @, delete it, and go into insert mode. For this, I created the mapping

map! ^V^I ^[f@xi

But this works only when @ is not the last character in the line. Likewise,

map! ^V^I ^[f@xa

only works when @ is the last character in the line.


The problem is that the position of the cursor after x is different depending on whether the last character was removed.

What would solve this problem is if there is another command α (say) such that α acts as i or a depending the cursor is at the end of the line; as far as I know, no such α exists.

What can I do?

1 Answer 1

2

Once the cursor is on the @ you can press s to "substitute" the current character. This will delete the current character and leave you in insert mode.

Basically, you could replace all your xi and xa with s:

map! [ [?]@^[F?s
map! { {?}@^[F?s

map! ^V^I ^[f@s
3
  • Thanks that works perfectly! (I upvoted but it will not show up until I have 15 reputation.)
    – Kevin
    Nov 5, 2015 at 15:22
  • 1
    s is pretty basic. May I suggest you take a look at :viusage?
    – romainl
    Nov 5, 2015 at 16:00
  • Thanks! Most my vi knowledge comes from vim, and in vim I always had s mapped to a surround plugin. I'll take a look at :viusage.
    – Kevin
    Nov 6, 2015 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.