3

I am looking for a simple few key command which would move till the last occurrence of a character in the line. Is there anything already existing?

The alternative is to jump to the next specified character and repeat the jump as many times as you need. It is not terrible; I am just curious whether there is there is something built into vim which could speed this up.

A use case could be to strip the absolute path only to the last directory.

3

Assuming that &virtualedit is all or onemore it's $lF/ (i.e. get one character past the end of the string, in case it ends in a searching character, and find char backward).

More robust variant (not to depend on &virtualedit) is ACtrl-\Ctrl-OT/Esc.

to jump to the next specified character and repeat the jump as many times as you need

[count]f{char}

Also to repeat by pressing semicolon (;)

| improve this answer | |
  • Thanks! I like the first one. Could you explain how the second one works? <kbd>A</kbd> would put us into insert mode and I am not sure what <kbd>Ctrl-\</kbd> does. :h Ctrl-\ only gives me a command where <kbd>e</kbd> is followed. – Horror Vacui Apr 10 at 15:03
  • 1
    @HorrorVacui To search help topic for insert mode you should type: :h i_ctrl-\_ctrl-o The key combination is primarily for scripts/mappings to make sure we get past end of line no matter what is the value of &virtualedit – Matt Apr 10 at 15:40
  • thanks! Just leaving here my understanding of the second suggestion: it starts in normal mode, uses the insert mode and returns into the normal mode. It is a combination of commands which moves the cursor to the desired location, but it is not a "move" what one can use to define the scope of a command, but one can use marks to do that. – Horror Vacui Apr 12 at 0:05
  • Is there any downsides of using the visual mode for tasks like that? – Horror Vacui Apr 12 at 0:06
  • @HorrorVacui I can't get you. This is insert mode, not visual mode. – Matt Apr 12 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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