MacOS – MacVim — switch to tab where file is opened if trying to open an already-opened file

macosmacvim

Over the course of the day, I often open many tabs/windows open in MacVim, I forget exactly which files I've opened etc.

Then when I try to open a file I have already opened somewhere, I get something like the following:

enter image description here

So I have to go look for where I opened the file before, which is annoying (I have to go through all windows one-by-one to find its tab).

Is there a way to make MacVim just close the tab where I last opened the file automatically when I try to open the file again?

Best Answer

You can remap tabnew to tab drop so you will be switched to already opened files or directed to newly created file.

cnoreabbrev <expr> tabnew getcmdtype() == ":" && getcmdline() == "tabnew" ? "tab drop" : "tabnew"