Vim fugitive back from :Glog - vim

I'm look for vim command which will exit from Glog'ed file view back to the normal (original) file.
EXAMPLE:
Let say I'm viewing a file with vim.
After entering :Glog I'm able to browse through all git versions of this file.
I'm looking for command (or something) which let's me go back to viewing current file version so I can modify and save this file.
Is it possible?

Quoting the README:
When you're done, use :Gedit in the historic buffer to go back to the work tree version.
(It's mentioned in relation to :Gblame, but :Gedit works with :Glog too—I checked.)

Related

Go from file to file tree in neovim

I am a newbie at neovim. I basically entered a file and can't go back to file tree in a vanilla NeoVim configuration.
Funny enough I couldn't find a way to do this. Even in the nvim tutor.
I don't want to exit the editor so:
:q
:wq
:qa
Won't work
How do I go back to the file tree after I enter a file?
You can use :bp (short form of :bprevious) to move to the previous buffer, in nvim it will work even in case it was a directory listing.
Another way of always returning to the files tree is by typing:
:Explore
This works better than writing :bp as it isn't actually intended to return to the files tree but to the previous buffer(whatever that is).
The only purpose of running :Ntree is to actually go to the files tree.

How to back to editing file after :Ex

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

Break from vimdiff on large number of diff files

I am using vimdiff as a diff tool for my git repo. Say I have five modified files and I am done with diff after the second file. How can I tell vim to stop opening the rest of the diff? Right now I just keep closing the buffer using :qa. I figured there's gotta be a better way to cut through instead of manually closing one buffer at a time.
I checked vim :help diff.txt but don't seem to find what I need.
Do you get prompts when running git difftool? You should get something like this:
Viewing (2/5): 'foo.bar'
Launch 'vimdiff' [Y/n]:
You can interrupt (^C) at the prompt to stop viewing any more changes.
If you don't get the prompt, set difftool.prompt option (see git-config(1)).

undo reloading new buffer with vim

I had a file open with gvim and it asked me if I wanted to reload the current buffer because it detected a newer version of the file. I accepted, but it turns out the new buffer is not what I want. Is there a way to recover the old buffer? The file on disk (and the swp file, which I viewed with vim -r) contains the new buffer) unfortunately.
If your buffer had fewer lines than the 'undoreload' settings, then its content will be stored in the undotree just before it was reloaded. This means, that a simple u or g- should get your buffer contents back. A plugin like my histwin plugin or the famous Gundo or undotree plugin could be helpful as well.
Note, this needs a Vim of at least version 7.3 or newer to work. Older Vims didn't store the buffer state on reloading.
Try u (undo; if you’ve made changes since reloading, repeat until the old version shows up).
I am in terminal Vim, but I don’t think that should make a difference here. I opened a test file with Vim in one terminal tab, went to a new tab and edited it there, saved that, switched back to the first tab, ran :e to reload the file, and then switched it back to the last version I had opened in the tab with u.
I have something like this is my .vimrc
" Backup stuff
set backupdir=~/.vim/backup
set directory=~/.vim/swap
set undodir=~/.vim/undo
I can help with cases like this were you accidentally overwrite your local changes and you want to find your old version of the file. Make sure to create the directories first to avoid errors on startup.

closing pending vim windows to open

I know that I can close all opened buffers in vim by :qall.
I want to close event to pending opening buffers.
I have problem while reviewing my changes in P4 sandbox. When I have changes in multiple files and I try to review my code with "P4 diff" and set my P4DIFF to vimdiff.
It opens one by one vimdiff of all changed files. Now if I have 10 opened files and after reviewing 2 files I want to close diff for remaining 8 files. How can I do that?
Thanks,
This sounds like a job for hastily learnt Vimscript!
Particularly, the :bufdo, if, and match statements!
Try out the following:
:bufdo if match(expand("%"), ".vim") >= 0 | bw | endif
bw is for buffer wipe in Ex-mode (the : operator)
expand("%") returns the name of the current buffer
match(string, pattern) finds the index of a pattern in string
|'s separate lines if you're in Ex-mode
This matches buffers that contain .vim in their filenames and closes those buffers.
I'm guessing if these are temp buffers that are fed into vimdiff, they wouldn't have file names to begin with. Maybe you can use bufnr(".") to output the number of the current buffer. Then you can close all buffers past or before a certain number.
You can probably do even more buffer manipulation with certain plugins. I've been considering adopting one of the following three plugins that help manage plugins:
LustyExplorer
FuzzyFinder
minibufexpl
I can't speak for any merits, but I've heard them mentioned several times over the internet and on IRC.
I'm assuming you open vim with a number of arguments (known as... the argument list).
You should probably reset it:
:args %
You can also selectively manage the list (:argdelete). More information: :he arglist
DISCLAIMER: I've not used perforce, so I've had to make an assumption: that when multiple files have uncommitted changes, it will behave like a lot of VCS's and run the configured diff command (in this case, vimdiff) on each changed file in turn (I'm thinking this is what you meant by "opens one by one vimdiff of all changed files").
If this is the case, then vim won't have any references to any of the remaining files when viewing the changes for any particular file, so no amount of trickery within a single vim session is going to help you.
If you are willing to change your workflow at all, you may be able to do something with this vim script I found: http://www.vim.org/scripts/script.php?script_id=240
It claims to be modelled after the P4 GUI, so hopefully could fit neatly into your usage. From the overview of the script, it sounds like it should be able to show you a summary of which files have changed and allow you to view the changes.
If none of this is suitable for you, you could always try the old favourite Ctrl-C immediately after closing a vimdiff session for a file.
This is a bad hack but putting it here as no other answers worked for me.
Add "qall" without qoutes on top of your .vimrc .
:e ~/.vimrc
:source ~/.vimrc
:q
All files will close automatically after opening.
Then open vimrc in emacs or sed and remove qall.

Resources