Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Open new explorer tab with the directory of the file you're currently on

Tags:

I'd like to open a new tab with the file explorer set to the directory of the file I have open, instead of the directory I opened vim from. For example,

If I do:

~: cd ~/dir1 ~/dir1: vim dir2/dir3/dir4/file1 

Then from inside that window I would like to open a new tab with a file explorer currently showing the contents of ~/dir1/dir2/dir3/dir4/ (the directory of the file in the currently active tab).

I have the following mapping set up:

nnoremap <leader>t :tabnew<CR>:Ex . <CR> 

But that just opens the file explorer at ~/dir1. How can I edit this key-mapping to pass to :Ex the directory of the file that is currently open?

like image 651
Diego Avatar asked Apr 08 '11 14:04

Diego


People also ask

How do I open a new tab in Vim?

Opening a tab Probably the easiest to remember is to run the :tabnew command while in normal mode. This will open a new tab with an empty buffer. If you want to edit a file in the new tab, you can run :tabnew filename and Vim will load the file in the new tab.

How do I open a vim file in Explorer?

The command :Explore opens the file explorer window. Select a file or directory name and press Enter to open that file or directory. (For example :e /home/user displays the contents of that directory.) To return to the explorer window, press Ctrl-^ (usually Ctrl-6).

What is Netrw in Vim?

netrw - the unloved directory browser The netrw plugin normally ships with vim and is the default filebrowser. It gets a bad rap and ships with all kinds of features likes remote editing over SSH and FTP, and anecdotally has many bugs.


1 Answers

Alternatively to :tabe %:h, there is also

:Texplore

or simply :Te

like image 127
François Avatar answered Sep 24 '22 00:09

François