vim, open buffer without changing alternate file

vim

Solution

You should better use the Control-i and Control-o mappings to move between positions across files. That way you can easily get back to your previous file.

Though to actually answer your question, as the alternate file is stored in the `#` register, I guess you could create a mapping that copies the `#` into a temporary register, open the file and restore the saved register into `#`. Theoretically that would be the following:

:let @x=@#|edit file|let @#=@x

but for some reason you can't write into the `@#` register.

Though in the help of `alternate-file`, there's the `:keepalt` command that is suggested to not overwrite the alternate file register with the command given as parameter:

:keepalt {cmd}              Execute {cmd} while keeping the current alternate file
                            name.  Note that commands invoked indirectly (e.g.,
                            with a function) may still set the alternate file
                            name.  {not in Vi}

Problem

Often times I like to switch back and forth between the alternate file. If I need to look at another file just for a second and come back to where I was it's frustrating to lose the alternate file I was toggling between. Anyway to not overwrite the alternate file for quick one-off buffer edits?

Original source