0

Say my cursor is []:

(A very intelligent turtle[)]

I'd like to issue something like o that would put me in insert mode here:

(A very intelligent turtle
[)]

I'm using spacemacs.

4
  • 3
    Welcome to Vi and Vim! Doesn't i followed by "Enter" do exactly what you described?
    – filbranden
    Jan 5, 2022 at 16:18
  • Thank you! Yes it does, but I was wondering if there was a one-key alternative, or variation of o that does that?
    – mcp
    Jan 5, 2022 at 21:51
  • You can always create your own keybindings... Assuming you want <CR> (in Normal mode) for that command, and that you'd like to stay in Normal mode at the end, you can use nnoremap <CR> i<CR><Esc>.
    – filbranden
    Jan 5, 2022 at 22:02
  • 1
    Okay, I guess your answer is the simplest though. If you want to put it as an answer I'll mark it.
    – mcp
    Jan 6, 2022 at 17:00

1 Answer 1

2

You can accomplish this task with i (to enter Insert mode) followed by Enter, which will break the line taking the part starting at the character under the cursor to the next line. This sequence will leave you in Insert mode.

If you'd like to repeat that for many lines, you can use i, Enter, Esc, to simply break the line and return to Normal mode. At that point, you can use the . command to repeat that insertion that is just breaking the line the way you want. So you can keep moving to the next position where you want to break the line and press . to break it. If you're using a search (for example, looking for a ) at the end of the line, with /)$), you can repeat the search too with n, so you can keep hitting n.n.n. etc. to find the next match and break the line, possibly skipping a break by just pressing ns more than once.

If this is an action you repeat often and would like an even shorter sequence than i, Enter, you can create a mapping for it. For example:

:nnoremap <CR> i<CR>

This maps the Enter key in Normal mode, and does the i, Enter action that breaks the line and leaves you in Insert mode.

If you want to end back in Normal mode, and prefer a different key for mapping, say ,, then use something like:

:nnoremap , i<CR><Esc>

Hopefully these examples will be helpful, you can adapt them to whatever makes the most sense for your specific use case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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