3

Hope you're doing well.

Input:

let firstDate = src[0][0]|.toString();
                         ^
                         cursor in Insert mode

Desired output:

let firstDate = |.toString();
                ^
              cursor in Insert mode

So deleting src[0][0]. Currently I always spam <C-w> (in this case 6 times).

I found a similar question with the solution being, in Normal mode, cT<space>. The problem is that after entering Normal mode, the cursor is here:

let firstDate = src[0][0].toString();
                        ^
                        cursor in Normal mode

The result after jkcT<space> (jk is my remap to escape Insert mode)

let firstDate = |].toString();
                ^
                cursor in Insert mode

It leaves the ] behind, which is not what I want.

Also, is there any way I can do so without leaving Insert mode? I rarely use <C-U> so any remapping is fine with me too. Remapping with <C-b> in Insert mode seems appropriate. I'm open to use any vim/neovim plugin as well.

I thought I found the solution in this SO solution but the solution still requires 6 <C-b> to delete till previous whitespace.

Thank you!

1
  • 1
    In your second example, you're going from insert mode to normal mode and this moves the cursor to the left. You don't need to do that. If you're going to change something, stay as much as you can in normal mode. Therefore, I would immediately find the dot f. or F. depending on direction and type dT<space>.
    – r_31415
    Jun 2, 2022 at 5:54

1 Answer 1

2

Ctrl+o (see :help i_CTRL-O) allows you to perform a single Normal mode command from Insert mode and automatically return to Insert mode after it is executed.

As Robert Smith suggested, I would propose <C-o>dT<Space>:

Ctrl+o d T Space

You can also use the B motion to move to the beginning of the current WORD, which is delimited by whitespace.

So:

Ctrl+o d B

1

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.