3

Let's say I just completed following path using Ctrl-x, Ctrl-f (twice) and I haven't exited the Ctrl-x mode yet and I got

/home/john.doe/

Let's say I chose john.doe accidentally and actually want to go back to /home to finally go to

/home/jane.doe/

Is there a way to undo the last e.g. Ctrl-f action without losing the whole path (i.e without losing /home here)?

To elaborate why I'm asking: If we exit with e.g. Ctrl-y and then use u, the whole path will be removed. So in theory one could exit after every completion, but that seems rather cumbersome.

3
  • 2
    What about Ctrl-e? That will abort the completion, without inserting any of the completion options
    – husB
    Jun 23, 2022 at 8:52
  • @husB Thanks for the tip! That does work indeed! I just played with it but it seems you can only undo the most recent completion (i.e. john.doe in the example above, but it wouldn't work for home after that), right?
    – flawr
    Jun 23, 2022 at 14:34
  • Indeed, Ctrl-e only cancels the current completion, it does not undo the completion, unfortunately.
    – husB
    Jun 24, 2022 at 2:51

1 Answer 1

1

I normally use i_CTRL-W and re-enter ^X-mode by i_CTRL-X i_CTRL-F. It does of course then exit the ^X-mode + if you do not have / as iskeyword, which would not be very user friendly, the approach require a few hits from time to time.

If it is something one do frequently enough one could do a remap. For example i_CTRL-G:

:inoremap <C-G>  <ESC>dT/a<BS><C-X><C-F><C-P>

It does:

  • <ESC>: Exit insert mode
  • dT/: Delete backwards until first /
  • a: enter insert mode
  • <BS> delete /
  • <C-X><C-F>: Re-open ^X-mode file
  • <C-P>: Move up one so that the selection is empty. This way we can hit CTRL-G multiple times without having to set it to no-selection.
1
  • Note that one is left in normal mode if dT/ comes up short. Have to look for a fix for that.
    – Moba
    Jun 27, 2022 at 10:20

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.