4

It is possible to open a new file with :edit or :tabnew but without jumping to that new buffer ?

  • no, but you can make a custom command, that will jump back from after opening a new window/tabpage – Christian Brabandt Mar 17 at 16:41
2

Perhaps :badd {fname} is what you are looking for. It just adds a new buffer to the buffer list without switching to it.

See :help badd.

I don't think there is something similar for tabs.

  • Wow, I didn't know about this! Way better than the custom command solution! Nice. – DoYouEvenCodeBro Mar 17 at 18:43
0

I'm not aware of a command to do this. Not to worry though - you can define your own commands to do it!

For edit, you might want to use something like this to open the file then immediately switch to the previous buffer.

command -nargs=1 Bgedit edit <args> | bprevious

Which you can call with :Bgedit filename.

Explanation:

command - Create a new user-defined command

-nargs=1 - With one argument (the filename)

Bgedit - Name of the command (user-defined commands have to start with capital letters).

What comes next is what you will run when :Bgedit gets called:

edit <args> - open the file

| - Used in vim to chain two commands together, like a semicolon in bash

bprevious - switch to the previous buffer.

For tabnew, you can do the same thing, but using tabprevious

command -nargs=1 Tabbgedit tabnew <args> | tabprevious

You would put these two lines in your .vimrc.

  • For windows, you could do (v)split | wincmd p – D. Ben Knoble Mar 17 at 22:16

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.