It is possible to open a new file with :edit or :tabnew but without jumping to that new buffer ?
2 Answers
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. Mar 17, 2019 at 18:43
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.