When I open a directory browsing in vim, I can open a file by moving the cursor to a file name and pressing Enter.
Now, is there any command to go back to the previous directory browsing?
If not, is there a way to open a file without closing the directory browsing mode?
You can go back to the last buffer using :b#.
If you just opened a file, then it will bring you just back to the directory browsing.
Update:
Since this answer happened to be accept as the correct answer and is thus on the top, I'd like to summarize a bit the answers, including the one by #romainl that imho is the correct one.
:Rex[plore]: Return to Explorer (by #romainl) vimdoc.sourceforge
:Explorer: opens the Explorer, same as :E (if no other command starting with E is defined (see stackoverflow), or as :Ex (see vim.wikia) (by #drug_user841417).
:b#: goes back to the "previously edited buffers". See vim.wikia
:e# or Ctrl-6 (or Ctrl-^): goes back to the "previously edited file" (by #aman-jain). See vim.wikia
Ctrl-O: jump back to the previous (older) location, not necessarily a buffer (by #Peyman). See vim.wikia
You can use Ctrl-O to go back to the previous buffer.
The proper command for returning to the netrw listing is :Rex[plore]. You can run it even after you have jumped to and from dozens of files.
:Ex will take you back (and show you what you edited and didn't save).
I rely on Ctrl ^ to go back and forth b/w two buffers.
I usually just use :E. It's easy to remember and gets you back to the directory listing of the file you had open.
I'd like to use the Jump-motions shortcut keys to do any 'go back' or 'go forward' actions in Vim. It makes vim like a web browser.
You can search for Vim's help for more details.
Vim :h jump-motions
So like as mentioned in other answers ctrl+O works cool, and hope vim's help-file let you learn more commands like ctrl+I .
Ctrl + I : Go Forward
Ctrl + O : Go Back
Related
I'm editing a new file in NeoVim and I don't remember the path of the directory I want to save my file to, so I want to look at the directory tree before saving. I do this by typing :Ex, which takes me to Netrw.
I'm done looking at the directory tree and I want to go back to my file and and finish my work. However I don't know the command to get back from Netrw to the file, and none of the numerous solutions I looked up online worked. The help file didn't help either. The intuitive command would be :q, which works fine for help but doesn't work for this situation. I have also tried q, Q, gq, gQ, :visual and :vi as suggested by people online.
Right, after making this post I finally stumbled upon a working solution in a comment by another.anon.coward on How to go back when I run :Ex command in Vim
You could try :bunload to unload current buffer & go back to previous
I think you can just press Ctrl-6 to go back to the previous buffer. Also check the nvim help: :help CTRL-6.
You can use those default vim mappings for that:
CTRL-O - Go to older cursor position in jump list
CTRL-I - Go to newer cursor position in jump list
So when you'll be at netrw press <C-o> couple of times and it will bring you back to the place where you started.
To read more about jump commands: :help jump-motions
I’m trying to use vim’s compl-filename feature (Ctrl-XCtrl-F) to complete paths in INSERT mode, but I can’t work out how to traverse into directories without (temporarily) ending the completion mode:
Let’s say I want to complete the path /etc/sysconfig/network-scripts/ifup.
I would like to be able to do something like:
/eCtrl-XCtrl-F
/etc/
/etc/sysCtrl-F
/etc/sysconfig/
/etc/sysconfig/netCtrl-F
/etc/sysconfig/netconsoleCtrl-N
/etc/sysconfig/networkCtrl-N
/etc/sysconfig/network-scripts/
/etc/sysconfig/network-scripts/ifupCtrl-Y
/etc/sysconfig/network-scripts/ifup
The issue is, as soon as I start typing* after a path match (like /etc/), it ends file name completion. I would like it to stay in file name completion, so that I can still use Ctrl-F, Ctrl-N, etc. Since it ends completion, I have to type Ctrl-XCtrl-F again to restart it, and the helpful completion popup menu disappears in the meantime.
Is there an option I can set to change this?
* By ‘typing’ here, I am referring to characters in 'isfname' -- of course, typing other characters (like space or punctuation) should not continue file name completion.
I'm not sure exactly what you're saying, but you can just press Ctrl-XCtrl-F again on a directory while you're in the completion menu to expand it. You don't have to close out of the menu first. I just keep Ctrl held down and tap xf to traverse a directory, n and p to move up and down and w to go back up.
If you don't use :h i_CTRL-F then you could remap it. For example,
inoremap <C-f> <C-x><C-f>
Simple remap would be
inoremap / /<C-x><C-f>
So when you type slash(/) in insert mode you will get that auto completion popup :)
Place it in your .vimrc file (for vim) or in init.vim (for neovim)
Vim doesn't do auto-completion.
For that, you'll need a dedicated plugin like AutoComplPop or NeoComplCache
Please use insert "i" first before using cntr+x+f. I was in similar situation. :)
I really like the Ctrl-O and Ctrl-I to jump backward and forward.
If I open fileA, then use :tabe fileB to open another file in a new tabpage.
In the 2nd tabpage, I type Ctrl-O to jump back to the previous location.
Vim simply shows fileA in current window instead of switching to the 1st tabpage.
Now I have two tabpages display the same files. It is not I want.
I can use :drop fileA, but I need to provide full name. It's not good enough.
Is there some good way to switch between windows cross tabpages?
Yes, the switchbuf setting:
set switchbuf=useopen,usetab
I know you know where to get more info on the possible values. ;-)
By the way, along with set hidden, this is the key to using buffers and windows and tabs efficiently in Vim.
So, the :Vexplore command in vim opens a nice little directory browser to the left.
But how do I then open a file from that side-pane into the main window on the right?
One would assume there's a simple mapping for it, but I can't seem to find it.
I think you want o or P
Also, have a look at the documentation, e.g.
:he netrw-p11
It turns out it's just a single line in .vimrc:
let g:netrw_browse_split=4 " Open file in previous buffer
Source: http://vimcasts.org/episodes/the-file-explorer/#comment-45366660
I'm sure what you're looking for is this:
:Vexplore!
This is the same command you would use to navigate to different windows in Vim (like quickfix window, or different split), everything is explained in
:help windows.txt
But to answer to your question directly:
CTRLwCTRLh to move to the left window
CTRLwCTRLl to move to the right window
then Enter to select the file you want to open.
You might want to read :help netrw as well
The latest netrw plugin (up to v153f) now provides the :Lexplore command, which opens an explorer on the right hand side of the vim display. It sets g:netrw_chgwin so edits occur in the window to the right of the netrw window. You can get it from http://www.drchip.org/astronaut/vim/index.html#NETRW .
I am a Vim user and sometimes I made several changes in a file but then want to get back to the beginning and have to type :u a lot of times, so I ask you if there is a shortcut to get to the "oldest change"?
Cheers!
Rodrigo Alves Vieira
http://rodrigo3n.com | #rodrigo3n
The keystroke to undo is just u; if you're pressing :u then that's too many keys (although it works, it's four keys instead of one). Usually I would just hold down u and let auto-repeat do the trick (note that Ctrl+R is the opposite of u if you go too far)..
You can reload from the last saved version on disk using :e!.
Does ':e!' (followed by return) work for you? It gets back to the state of the edited file when it was last saved, or when you started if you've not saved yet...
You also have the :earlier command. :help :ea
Using :e! will get you back to the oldest change as saved. Aside from typing just u instead of :u, also see :h undo-redo for help on all the undo commands.
Other options might be use a vim plugin, such as undo_tags.
You know you can use repeat counts on just about any VIM command, right?
My favorite way:
10000u
ten-thousand-undos.
Zips me back in time, usually to where I opened the file. I can see how things USED to be.
then
10000^R
then-thousand-redos
And I'm back at the end again.
You're welcome.