Break from vimdiff on large number of diff files - linux

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)).

Related

Vim fugitive back from :Glog

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.)

using Tail Bundle to have vim follow a file

I'm trying to use vim to follow a file, similarly to how tail -f does it. I want to use vim, because I want the ability to move around the file, search for text, etc while still having the file be followed.
I've found the Tail Bundle plugin, but I can't seem to figure out how to make it work. None of the commands listed in the docs cause the file to continuously load at the bottom. They simply open the same file in a preview window.
Does anyone know how to use this plugin, or can you provide another way to use vim to follow a file like tail -f
I would not use Vim for that. less comes with many vi-like key-bindings for navigation and is inherently better for use as a pager than Vim.
$ less +F filename
$ command | less +F

Best way to view multiple logs at once?

I am currently running zookeeper processes and multiple internal processes and they all print out to their own log files as text. I am pretty green to linux but I was wondering if viewing multiple log file in a single screen without switching between emacs windows or vim windows is an issue for other. What is the best way to view say 3, four or more log files at once? Would it involve the CAT or | commands?
If you are viewing live logs you can use tail with multiple files, or just tail an entire directory using the wildcard operator.
If you are digging though logs you can use Terminator, it is in the Debian repos, to open multiple terminal sessions in one window.
If you are feeling more adventurous your can use tmux to split your terminal window, the great thing about tmux is that is works in textmode, so you can do it over ssh. Here is a pretty decent tmux split pane tutorial http://lukaszwrobel.pl/blog/tmux-tutorial-split-terminal-windows-easily
i like multitail as an optional but nice way to monitor multiple files whithout a lot of hacking around. After installing (e.g. apt-get install multitail) run multitail file1.log file2.log file3.log. the 'f1' key gives you inline help which keys to press.
But, if you want to stay in vim you can use this answer:
One can run this oneliner from ex (whithin vim) when needed (or put each command in vimrc, for when log-files are opened.)
:set autoread | au CursorHold * checktime | call feedkeys("lh")
Explanation:
- autoread: reads the file when changed from the outside (but it doesnt work on its own, there is no internal timer or something like that. It will only read the file when vim does an action, like a command in ex :!
- CursorHold * checktime: when the cursor isn't moved by the user for the time specified in 'updatetime' (which is 4000 miliseconds by default) checktime is executed, which checks for changes from outside the file
- call feedkeys("lh"): the cursor is moved once, right and back left. and then nothing happens (... which means, that CursorHold is triggered, which means we have a loop)
It hit me out of nowhere... I should just import the log folder directory into an empty project in eclipse, then I can swiftly explore and inspect logs and split the screens as needed across multiple monitors. All of Leon's answer is good stuff too, but since I am already using Eclipse heavily I might as well take advantage of that locality.

How do I cancel a paste operation in Vim?

I had rather a lot of text on my clipboard whenever I accidentally right clicked inside Putty (with Vim open), and Vim has initiated a paste operation which has been going for around ten minutes now.
I don't want to lose my unsaved work, is there a way to instruct Vim to stop pasting text?
If you're in normal mode, Ctrl-C aborts the current command in progress. Then press u to undo anything that changed before you stopped it.
Depending os your vim configuration, there's chances that you have a swap file (backup) in .nameOfTheOpenedFile.swp (substitute nameOfTheOpenedFile with the name for your file).
To recover the file :
vim -r .nameOfTheOpenedFile.swp
I know this is really old but the top answer is not right and I was clearly having a similar issue to OP. (accidentally pasted like a million lines of json into vim)
Keep in mind this may not allow you to save your work (but you can probably salvage something from the .swp file)
All you need to do is open a new terminal window and enter pkill vim into the command line.

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