Feature request: Move "after" character

15 views
Skip to first unread message

Siddhartha Kasivajhula

unread,
Apr 23, 2020, 10:31:10 AM4/23/20
to vim...@vim.org
Esteemed Vim Monks,
I often find myself reaching for the following feature but I don't think it's there, so I am bringing it up for consideration.

We can (f)ind a character or move un(t)il a character, but we can't move "after" a character.

The feature is analogous to f F t and T, and should be linked to , (repeat find backwards) and ; (repeat find forwards).

Example (cursor indicated with |):

|string-append

Say we'd like to change "append" to "concatenate". The options are:

w  string|-append
W  string-append|
f-  string|-append
t-  strin|g-append

But what we really want to do is to move after the hyphen, that is:

??  string-|append

Of course, in this particular case there are other options that would work -- since there are no 'a's in the first word, we could do fa. But that doesn't solve the general problem, for instance, it might be:

|data-append

... and then we're out of luck.

Another possibility is Eb for this particular case. But that still falls short of a general solution, for instance this wouldn't work for:

|data-append-together

Regarding what key to use for this, maybe a modifier key would be reasonable -- e.g. C-f doesn't seem to be bound to anything that I know of. But at least, providing the functionality so that it is integrated with , and ; could mean that users could map it to a convenient keybinding that works for them.

WDYT? If you think this is reasonable, I could create a GitHub issue or proceed in the recommended way. Or if it already exists, then please show me the way.

Thanks :)
-Sid

Bram Moolenaar

unread,
Apr 23, 2020, 11:25:57 AM4/23/20
to vim...@googlegroups.com, Siddhartha Kasivajhula, vim...@vim.org

Siddhartha Kasivajhula wrote:

> Esteemed Vim Monks,
> I often find myself reaching for the following feature but I don't think
> it's there, so I am bringing it up for consideration.
>
> We can (f)ind a character or move un(t)il a character, but we can't move
> "after" a character.
>
> The feature is analogous to f F t and T, and should be linked to , (repeat
> find backwards) and ; (repeat find forwards).
>
> *Example (cursor indicated with |):*
>
> |string-append
>
> Say we'd like to change "append" to "concatenate". The options are:
>
> w string|-append
> W string-append|
> f- string|-append
> t- strin|g-append
>
> But what we really want to do is to move *after* the hyphen, that is:
>
> ?? string-|append
>
> Of course, in this particular case there are other options that would work
> -- since there are no 'a's in the first word, we could do fa. But that
> doesn't solve the general problem, for instance, it might be:
>
> |data-append
>
> ... and then we're out of luck.
>
> Another possibility is Eb for this particular case. But that still falls
> short of a general solution, for instance this wouldn't work for:
>
> |data-append-together
>
> Regarding what key to use for this, maybe a modifier key would be
> reasonable -- e.g. C-f doesn't seem to be bound to anything that I know of.
> But at least, providing the functionality so that it is integrated with ,
> and ; could mean that users could map it to a convenient keybinding that
> works for them.
>
> WDYT? If you think this is reasonable, I could create a GitHub issue or
> proceed in the recommended way. Or if it already exists, then please show
> me the way.

You can move after the hyphen with "f-l". Adding a new command such as
"gx-" doesn't help, since it's the same number of keys to type. We've
run out of single-letter commands.

So the only way is to make a mapping for yourself to replace one of the
commands that exists, but you don't use.

--
hundred-and-one symptoms of being an internet addict:
2. You kiss your girlfriend's home page.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Christian Brabandt

unread,
Apr 23, 2020, 11:36:46 AM4/23/20
to vim...@vim.org
We are running out of keys for a new key. Also this can be mapped using
some Vimscript functions. Something like this:

:nnoremap <expr> gF 'f'.nr2char(getchar()).'l'

Note: A real solution probably needs also an operator-pending map as
well as needs to handle some edge cases correctly (as well as needs
some error handling). But that can serve as a starter :)

There exists also some plugins, that allow configurable navigation
within a buffer, such as easymotion or similar.

Mit freundlichen Grüßen
Christian
--
Wie man sein Kind nicht nennen sollte:
Eva N. Gelium

Gregory Seidman

unread,
Apr 23, 2020, 11:50:21 AM4/23/20
to vim...@googlegroups.com, vim...@vim.org
On Thu, Apr 23, 2020 at 05:25:47PM +0200, Bram Moolenaar wrote:
>
> Siddhartha Kasivajhula wrote:
>
> > Esteemed Vim Monks,
> > I often find myself reaching for the following feature but I don't think
> > it's there, so I am bringing it up for consideration.
> >
> > We can (f)ind a character or move un(t)il a character, but we can't move
> > "after" a character.
[...]
> You can move after the hyphen with "f-l". Adding a new command such as
> "gx-" doesn't help, since it's the same number of keys to type. We've
> run out of single-letter commands.
>
> So the only way is to make a mapping for yourself to replace one of the
> commands that exists, but you don't use.

There is a more functionality than a mapping could provide:

- Is there even a way to write a mapping that takes a following character
and puts it in the map? nmap S<NextChar> f<NextChar>l ???

- F/f/T/t commands don't move at all if the character is not found.

- F/f/T/t commands set what , and ; does but a mapping can't

A new gx or whatever command would make it possible to map to something
shorter with correct semantics.

Meanwhile, I'm not sure this is a feature I'd necessarily use, but I like
the concept.

--Greg

> --
> hundred-and-one symptoms of being an internet addict:
> 2. You kiss your girlfriend's home page.
>
> /// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
> /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
> \\\ an exciting new programming language -- http://www.Zimbu.org ///
> \\\ help me help AIDS victims -- http://ICCF-Holland.org ///
>
> --
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/202004231525.03NFPlDr024120%40masaka.moolenaar.net.
>

Christian Brabandt

unread,
Apr 23, 2020, 12:04:01 PM4/23/20
to vim...@googlegroups.com

On Do, 23 Apr 2020, Gregory Seidman wrote:
>
> There is a more functionality than a mapping could provide:
>
> - Is there even a way to write a mapping that takes a following character
> and puts it in the map? nmap S<NextChar> f<NextChar>l ???
>
> - F/f/T/t commands don't move at all if the character is not found.
>
> - F/f/T/t commands set what , and ; does but a mapping can't
>
> A new gx or whatever command would make it possible to map to something
> shorter with correct semantics.
>
> Meanwhile, I'm not sure this is a feature I'd necessarily use, but I like
> the concept.

If you are serious with such a mapping, you would need to create a
plugin. I have done with my improved-ft plugin, that replaces the f/F
functions with a search function. The whole logic became a bit complex,
because of error handling and edge cases, so it is not so easy to do.

There are other alternative plugins like clever-f or sneak or
fanfingtastic (and probably even more).

But still, personally I don't think we need 2 built-in keys for that
(forward and backward motion) and I have never really had the use for
such a movement in all the years. Probably because the alternative like
'f<key>l' is easy enough to type (yes, I know it's not quite the same).

Besides, which keys to chose? It could be only g<key><argument> or
z<key><argument>, which means you would have to type 3 characters. That
is the same as f<key>l already, so not much is won.

Best,
Christian
--
Lieber Arm dran als Bein ab.
Reply all
Reply to author
Forward
0 new messages