DESCRIPTION
Files edited in Vim often relate to one another; maybe they just differ in
file extensions, are numbered sequentially, or contain common patterns. One
can use the built-in cmdline-completion or filename-modifiers like %:r to
quickly edit a similar file, or even use special plugins, e.g. to alternate
between source and header files (vimscript #31).

This plugin provides custom versions of the :edit, :view, :split, :vsplit,
:sview, :file, :write and :saveas commands which facilitate quick and simple
editing of similarly named files. To quickly edit another file based on the
current file, one can:
- substitute {old} with {new}
- go to previous/next numbered file or add any offset to the number
- go to succeeding / preceding files in the same directory
- change the file extension
To open a set of similar files, it is possible to:
- open all files matching a pattern in split windows

SEE ALSO
- The PatternsOnText.vim plugin (vimscript #4602) applies the
{text}={replacement} of :EditSubstitute via :substitute to the text in the
buffer with :SubstituteWildcard.

RELATED WORKS
- altr (vimscript #4202) lets you set up custom (per-filetype) rules and then
opens related files through two forward / backward mappings, e.g. allowing
you to open the autoload file from the plugin.
- nextfile (vimscript #4698) has definitions of related files (like Rails
controllers, views, model, tests), and can edit a next file via a mapping.
- projectile (https://github.com/tpope/vim-projectile) allows you to define
per-project settings and navigation commands, e.g. :Eplugin and :Edoc.

USAGE
Substitutions: Change all occurrences via {text}={replacement} in the
currently edited file (modeled after the Korn shell's "cd {old} {new}"
command). This can also be achieved with the built-in filename-modifiers:
:edit %:gs?pattern?replacement?
but the syntax is difficult to memorize (it's subtly different from :s) and
harder to type (because one has to use regular expressions instead of the
simpler file wildcards).

Plus / Minus: Add an offset to the last (decimal) number in the currently
edited file.
:[N]EditPlus[!] [N]
:[N]EditMinus[!] [N]
:...

Next / Previous: In the directory listing of the current file, go to
succeeding / preceding file entries.
:[N]EditNext [{filelist}]
:[N]EditPrevious [{filelist}]
:...

Root: Change the file extension in the currently edited file.
This is an enhanced version of the built-in:
:edit %:r.{extension}

:EditRoot[!] {extension}
:...

Pattern: Open all files matching the pattern in split windows, similar to how
:argadd {name} adds all matching files to the argument list.

:SplitPattern [++opt] [+cmd] {file-pattern} [{file-pattern} ...]
:...

install details

INSTALLATION
This script is packaged as a vimball. If you have the "gunzip" decompressor
in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress
the archive first, e.g. using WinZip. Inside Vim, install by sourcing the
vimball or via the :UseVimball command.
vim EditSimilar*.vmb.gz
:so %
To uninstall, use the :RmVimball command.

CONFIGURATION
For a permanent configuration, put the following commands into your vimrc:

All these edit commands are about speed; after all, they vie to be a faster
alternative to the built-in commands that take a complete filename. Each
user's Vim setup and behavior is different. Therefore, the previously defined
short command forms :Esubst, :Enext, etc. are gone in version 1.20. Instead,
you are encouraged to define your own shortcuts, depending on your preferences
and needs. A great way to do this (because it allows the definition of pure
lowercase commands) is defining short aliases through the cmdalias plugin
(vimscript #746), like this:
" Shorten the most frequently used commands from EditSimilar.vim.
Alias es EditSubstitute
Alias sps SplitSubstitute
Alias epl EditPlus
Alias emi EditMinus
Alias en EditNext
Alias ep EditPrevious
Alias er EditRoot
Alias spr SplitRoot
Alias spp SplitPattern

- Add :BDelete... comands, which are especially useful for when "E139: File is loaded in another buffer" is given.
- Add :DiffSplit... comands.
- For next files, escape the dirspec for wildcards to handle peculiar directories.
- Allow to :write partial buffer contents by defining -range=% on :Write... commands that do not yet use the count.
- Add :SaveOverBufferAs and :WriteOverBuffer commands (that with [!] also :bdelete an existing buffer with the same name) and use those in the :Save... and :Write... commands.
- All commands now properly abort on error. *** You need to update to ingo-library (vimscript #4433) version 1.018! ***

- Handle dot prefixes (e.g. ".txt") in root completion.
- Also offer multi-extension roots (e.g. ".orig.txt") in root completion, and correctly handle existing roots (e.g. ".orig.t").
- Add workaround for editing via :pedit, which uses the CWD of existing preview window instead of the CWD of the current window; leading to wrong not-existing files being opened when :set autochdir. Work around this by always passing a full absolute filespec. *** You need to update to ingo-library (vimscript #4433) version 1.017! ***

ENH: Complete file extensions for any files found in the file's directory for those commands that most of the time are used to create new files; the default search for the current filename's extensions won't yield anything there.

FIX: To avoid issues with differing forward slash / backslash path separator components, canonicalize the glob pattern and filespec. This avoids a "Cannot locate current file" error when there is a mismatch.

- Rename the :EditNext / :EditPrevious commands to :EditPlus / :EditMinus and redefine them to operate on directory contents instead of numerical offsets. *** PLEASE USE THE NEW RENAMED COMMANDS AND UPDATE ANY USAGES IN SCRIPTS AND MAPPINGS ***
- Better modularization of the different similarities.
- BUG: Substituted filenames that only exist in an unpersisted Vim buffer cause a "file does not exist" error when a:isCreateNew isn't set. Also check Vim buffers for a match.

- ENH: Allow [v]split mode different than determined by 'splitbelow' / 'splitright' via configuration.
- Refactoring: Move file extension completion to EditSimilar#Root#Complete() and create the root commands also in the command builder.
- ENH: Omit current buffer's file extension from the completion for EditSimilar-root commands.
- Obsolete the short command forms :Esubst, :Enext, :Eprev; the starting uppercase letter makes them still awkward to type, there's more likely a conflict with other custom commands (e.g. :En -> :Encode, :Enext), and I now believe aliasing via cmdalias.vim is the better way to provide personal shortcuts, instead of polluting the command namespace with all these duplicates.
- Rename :Vsplit... -> :VSplit... and :Sview... -> :SView... as I think this is a more intuitive long form. (And now that the user is encouraged to create his own custom short aliases, anyway.) The only other plugin with similar commands that I know is bufexplorer with its :VSBufExplorer.

Avoid that :SplitPattern usually opens splits in reverse glob order (with default 'nosplitbelow' / 'nosplitright') by forcing :belowright splitting for all splits after the first. I.e. behave more like vim -o {pattern}.

- BF: :[N]EditPrevious with supplied [N] would skip over existing smaller number file and would claim that no substituted file existed.
- BF: :[N]EditPrevious with supplied large [N] together with a low original number hogs the CPU because the loop iterates over the entire number range where the resulting offset would be negative.

- ENH: {text} in :EditSubstitute can now also contain file wildcards (?, *, **
and [...]) to save typing.
- ENH: On Windows, {text} in :EditSubstitute can now also use forward slashes
as path separators (as an alternative to the usual backslashes).
- ENH: Supporting substitutions spanning both pathspec and filename by finally
applying failed replacements of multi-path elements to the entire filespec.
- Added ":ViewSimilar" and ":SviewSimilar" commands to open similar files in
read-only mode.