Skip undo step in Vim - vim

Let's say I'm at state A in my document. I then make changes B, C, and D (in order).
Is there a way I can keep changes B and D, but skip C?
Or, let's say I'm at state A in my document. I make change B, undo it, and then make changes C and D (so Vim has an undo tree with two branches). I then change my mind and decide I want to use B and D but not C.
How can I do this in Vim? I have the gundo.vim plugin installed, but I haven't used it that much.

Well, I'll take a stab at this and say: No, I don't think there's a way to do exactly what you want with vim.
gundo.vim adds a nice interface to vim's undo, but doesn't change its core capabilities. So I took a look at the official vim docs to see if there's any hints to whether it is capable of this:
vim docs: undo
User manual page about undo
Nothing about merging two branches together. I think ewh and ZyX are right: to get a general solution for merging B with D, vim would need either for
Bram to add it as a separate feature in a future version
someone to implement it in a plugin by integrating with something that can already do merges (like git/hg)
You can of course try to do it manually by having files with versions B, C and D as well as a few diffs open.
Note: If I misunderstood and you weren't wondering about a general solution and are looking for help with a specific instance of this, let me know and I'll see what I can do :)

Is there a way I can keep changes B and D, but skip C?
You're at state D. :w file.ext_D
Backtrack to state C. :w file_ext_C
Backtrack to state B. :w file.ext_B
:!kdiff3 file.ext_B file.ext_C file.ext_D
This gives a 3 way merge of the differences, but still you'd have to manually go in and choose every red line in D for each merge conflict. Not exactly an easy solution.
If instead you do
:!kdiff3 file.ext_C file.ext_B file.ext_D
Then the merge happens automatically (except for individual lines with multiple changes)
For more complicated scenarios it gets tougher.
Note: I'm not sure how a revision control tool is much help. You're basically doing something like creating a patch between B and D, and then subtracting the patch from C to D from it. It seems to me that revision control systems are usually designed to manage merges between different sources of changes, not changes along a single branch.
kdiff3 is available at: http://kdiff3.sourceforge.net/

Related

Dymola, whitespace and version control

I opened a Modelica library in Dymola, changed one line, closed Dymola and clicked "Save all", now TortoiseSVN is showing several hundred changed files instead of just one file with the one line changed I intended to do. All these changes are either whitespace, or line breaks, introduced by Dymola it seems.
Of course I can now be careful to only commit the file I have changed (and revert the rest), but that makes committing more time-consuming and error-prone than it needs to be. Or I can just commit it all, but that makes it hard for my colleagues to review the change. Also, it feels like it is not deterministic, so a later commit might just revert parts back. I sometimes even revert all changes, then use a text editor to change just the one line. All this makes version control unnecessarily complicated.
When I look at the commits and diffs for e.g. the Modelica Standard library:
https://github.com/modelica/ModelicaStandardLibrary/commits/master
The diffs are nice and small and readable usually. Is there a trick to avoid the whitespace issue?
How I can I turn off all autoformatting by Dymola? Is there a technical reason to do it in the first place?
You can reduce (but not entirely prevent) this behavior as follows:
Increase the maximum line length, e.g. to 130
In the GUI: Options > Text Editor > Max line length
From the command line: Advanced.MaxLineLength=130
Let Dymola format your whole library one time
Open the text view of the top-level package
Mark everything with Ctrl+A
Auto-format with Ctrl+Shift+L or Right-Click > Auto-Format
Save everything with Ctrl+Shift+S
Now go through the changes. Most will be useful, but sometimes spaces are removed, which you usually like to keep (especially before import and extends statements. They are sometimes moved to the very left)
Commit the changes
From now on try to save individual models only, not packages
(When packages are saved, Dymola sometimes reformats the nested classes)
There are some things you can do to make pretty git commits for Modelica code:
Use a text editor instead of a graphical editor. You have absolute control of what you change.
Use a graphical editor that does not change whitespace. I'm not sure of other alternatives, but OpenModelica/OMEdit will preserve existing indentation as much as possible (it can also be used to minimize diffs from changes in other tools, but it works less and less well the more changes there are).
Use a formatter as a pre-commit hook (indenting all files according to some settings in the formatter; but then you can't manually change whitespace).
Hope someone on stackoverflow has more alternatives than this.

How to list all saved custom filters in Control-M?

Assume you created some, eg 3, custom filters saved with filter names A,B, C, using Control-M's ISPF client in zOS (mainframe). Using such custom filters, you can easily switch between the list of jobs to be shown in the Active Jobs File, using primary ISPF commands like:
s A
s B
s C
If you only have like 3 such filters, and with names like A, B or C, it's a piece of cake to remember them all. However, if you have like a dozen of names, each with up to (say) a length 8 (XYZ10000, PQR123, etc), it's pretty much impossible to remember them all.
So is it somehow possible to bring up a list of all available filters (similar to an ISPF memberlist)? If not, where to go find all such filters that are defined, maybe in some ISPF profile dataset member?
If you want to see a list of filters all you need to do is type SHOW ? in the command line and it will bring up a list of save filters.
Put an S beside the one you want to select it.
Rather accidentally, I discovered the correct (and complete) answer to my own question ...
The previous answer is a good start, i.e. you need to issue command show ? (or just s ?). But in my case just typing show ? still didn't show the filters (like A, B or C as in my question). The additional clue to really get it to work, at least in my case, is that I also have to press the PF8-key to perform a page down in that pop-up window (shown after first typing show ?). And without pressing the PF8-key, I only see a list of (vanilla) filters that come with Control-M.

How to fully sync two branches in perforce

I want to overwrite all files in branch B with another branch A. The use case is:
I branched B from A
Made some changes on B
Made other changes on A
I want B to be exactly the same as A, all changes on B are discarded
I want all files on B to be exactly the same as A, all additional changes on B are discarded (updated)
Is these a quick way to achieve this?
p4 branch would lead to a new branch C. And p4 integrate would keep the changes on B.
One possible way is, remove all files of B, and copy all files of A to B, and then run p4 reconcile on B. It's a little complicated. Anyone know a quick way? Thanks in advance.
'p4 copy' will copy files from one branch to another:
https://www.perforce.com/perforce/r16.1/manuals/cmdref/p4_copy.html
The previous history of branch B will still remain.
If you wish for it to look as if branch B was always an exact copy of branch A, then you may wish to obliterate it and re-create it.
Note that 'p4 obliterate' completely removes data from Perforce, so should be used with care and backups should be taken before running it.
More information about this command is here:
https://www.perforce.com/perforce/r16.1/manuals/cmdref/p4_obliterate.html
Hope this helps,
Jen.

What is this Perforce action?

I'm wondering what actions results in the left part of the graph, i.e. the red dashed arrow? This was done by Unreal Engine's Perforce plugin, when I renamed this file and submitted this change. The action shows add if I highlight that revision, but according to legend, this is a merge w/ edit action, so it doesn't seem to match.
The right part is my test, using P4V's move/rename action, and the action shows move/rename, which matches the legend Add (branch w/ edit), so this one seems fine.
So, what exactly happened in the left part? Is it really a merge w/ edit? Is it a correct result if someone is doing rename? Is move/add the only correct result when doing rename?
Thanks.
It's a mind-twister but there isn't necessarily a mismatch.
First the actions: the first is an add because the new file is created in addition to the old one. In contrast, the second is a move/add because you're adding a file by moving it from the old location, hence the old one ceases to exist. Indeed, you start the whole exercise with one file, and end it with two (rather than with three, as you would if you performed two adds; or rather than with one, as you would if you perform two move/adds).
Now the arrows. You're right the naming seems completely out of touch with the naming of the actions. I have no idea why there's the inconsistency.
You're asking about the Merge w/ Edit specifically. Perforce has four similar but distinct actions that could have been used here: p4 integrate, p4 merge, p4 copy, and p4 populate. There are subtle differences that don't matter here. At any case, all these actions do "merge" the file so I think the naming is OK. Intuitively, I feel this could/should have been done by p4 copy (since the target didn't exist, so you didn't have to merge anything) but it's also perfectly possible that Unreal Engine decided to use p4 merge or p4 integrate anyway. That, I believe, explains why the arrow is a Merge. As for the w/ Edit, did you perhaps make a (textual) edit in the file while duplicating it?

Vim: Navigating to Previous and Next Buffers in Edit History

When I edit multiple files I oftentimes want to go back and forth between the last edited files. I know about :bn(ext) and :bp(revious) to switch between buffers but they don't keep the history of the last used files. Instead they use the order in which the files were opened. E.g., if I opened the files in this order
A, B, C
an my navigation history would be
A, B, C, B
then :bprevious in the last buffer (B) would send me to A. Is there a command or plugin that would send me to C? I know of Ctrl-6, but this only switches between the last two buffers. I would like to go back and forth multiple buffers.
I have been wanting the same functionality for quite some time now as well. Your question inspired me to finally do something about it. Have a look at bufsurf, a small plugin that provides the required functionality. It provides the user with two commands:
:BufSurfBack
to navigate backwards in history, and similarly:
:BufSurfForward
to navigate forwards in history. For each window or tab a separate navigation history is kept in memory. Please let me know if you experience any problems, I did not have the chance to test this extensively yet.
Check out the lustyjuggler buffer plugin. It's awesome for this. It keeps the buffers in last used order and maps them to the home row keys so you can very quickly go back/forth between them.
http://www.vim.org/scripts/script.php?script_id=2050
You can see it demoed toward the end of my most recent vim screencast were I go over buffers:
http://lococast.net/archives/185

Resources