0

Say I have a line that looks like this:

(Type)obj.method());

Is there a motion that will go to the last of a specific character on a line? I'd like to do

^c (motion to ')' character) (insert text) <Esc>

and transform that line to

obj.otherMethod());

I know I can use #f or #t, but I'd rather not count the parens.

Josiah
  • 423
  • 7
  • 16
  • possible duplicate of [Motion to last character](http://stackoverflow.com/questions/19356598/motion-to-last-character) – glts Nov 13 '13 at 22:39
  • I don't really get why you need to go to a last character to achieve this. XY problem, or am I misunderstanding? – Jamie Schembri Nov 13 '13 at 22:45

2 Answers2

2

As I understand your question, you don't just want to go to the last instance of a character, which you could achieve by going to the end of the line and searching backward. You want to clear text from your current caret position to the last instance of a character, right?

I'd typically use a pattern search to complete a motion to a desired character when there may be n of the same character in between. In your example, you can clear from the current caret position to the last ) by using c/);Enter, since only the last instance of o is followed by ;. You could precede this with a v instead of c, for example, if you wanted to select everything in between.

Using the same example, you could move to the 3rd o with /odEnter.

It may seem tedious at first, but in practice you are probably looking directly at the spot where you want be, so you can already see the additional characters you need and you only need to increase you specificity until you get the match, and you'll have immediate visual feedback as long as you have set incsearch.

Note: If your line did not have a semicolon at the end, you could move to the last paren by using )\n to search for the next ) followed by a line break.

Jay
  • 56,361
  • 10
  • 99
  • 123
  • Yes, I needed a motion to search forward to the last instance of a character, similar to 'f'. It didn't occur to me that I could just use a regex... – Josiah Nov 13 '13 at 22:54
1

You could use visual mode:

v$F)c

But in this case you're really just inserting some new text and changing the case:

f.aotherEscl~

Matthew Strawbridge
  • 19,940
  • 10
  • 72
  • 93