I'm writing code like this:

if (!p){
    return 0; <-- cursor is on this line

And I want to start appending immediately after the code block, like this:

if (!p){
    return 0;
<-- cursor is on this line, in Insert mode

Is there a command for this? Usually I use jo to go down a line and then append a new line, or ]}o if there's more than one line of code inside the brackets, but both of these solutions feel kind of verbose.

  • If you do this a lout you can create a key binding. – elyashiv Mar 7 '15 at 17:24
  • 2
    In this literal example, it seems easiest to me to do }i, which is "go to the end of the paragraph" and "enter insert mode". But in general, I would do ]}o as you mention, because in the midst of coding I often don't mind the (one) extra keystroke if I spend 0 seconds thinking about it. – davidlowryduda Mar 7 '15 at 18:08

Ninja Feet

I made a plugin called ninja-feet.vim that, among other things, defines operators z[ and z] for entering Insert mode before and after a text object, respectively. Like other operators, they take a {motion}.

For your use case, you could use the ip text object: z]ip.


This operator is not repeatable with .; it will simply repeat the insertion at the cursor position.

  • Why not z]a}? – jamessan Mar 8 '15 at 5:23
  • Because a} is a characterwise motion. The operators will work like i / a for characterwise, and o / O for linewise. You could use z]Va} to force a} to be linewise. – tommcdo Mar 8 '15 at 14:13
  • z]ip is one more character than the sequence the OP has already dismissed as being too verbose! Upvoted anyway because your plugin looks nifty. – Rich Mar 10 '15 at 15:28
  • @Rich, lol. That's certainly true in this case. I'll (weakly) defend myself by saying that verbosity can be measured in different ways: keystrokes is one, and number of actions is another. Technically, z]ip is one action whereas ]}o is two. – tommcdo Mar 10 '15 at 15:53
  • Hahaha. Nice save ;). – Rich Mar 10 '15 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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