I normally write my functions this way

public void test() {}

to continue, I need to insert a new line from within the brackets, so the final output is this:

public void test(){
    // cursor is here now

To do so in vim, I follow these steps: (the pipe is where the cursor at)

public void test() {}

I press Esc to go to normal mode, then j so now my cursor is here:

public void test() {|}

I press i to go to insert mode and then enter twice so now I have this:

public void test() {


then I press Esc to go to normal mode and then k to go up a line, and then i to go to insert mode and then tab to get to the desired outcome.

Is there a better way?

Note: I really don't wanna use plugins, I hope native vim helps me.


Turn on :h 'autoindent' and :h 'smartindent' , assume current typing is:

public void test(){

input enter}:

public void test(){

input escO:

public void test(){

If you prefer :h i_CTRL-O , replace esc with ctrl-o.

FYI, another way to reindent current line in insert mode is :h i_CTRL-F .

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.