Open editable file in vsplit but stay in original position in vimscript

vim

Solution

This sounds like the perfect use of the preview window in vim. When you open a file in the preview window (`:pedit /path/to/file`) focus is not taken away from the current window. You also have the ability to jump directly to the preview window whenever you need to with `wincmd P` if you need to. You can also close the preview window from anywhere with `:pclose`. If the file has changed and you want to see the updates you can just `:pedit /path/to/file` again to get the updates.

Another small benefit, even if you have a file in the preview window you can still quit vim with a plain `:q` instead of `:qa`.

Problem

I'm trying to write a plugin that will make a `system` call which generates a file based on the current buffer and then open the generated file in a `vsplit`, or if already open, it will update it when the source file is changed. I've got the code to the point that it generates the file and opens/updates the split but the problem is that when it first opens the split the focus goes to the split and when it updates the cursor position on the source file jumps to the top of the page. Here is what I'm trying, any help would be greatly appreciated. ``` execute 'keepjumps silent ! ' . s:cmd . ' ' . s:src_file . ' > ' . s:dst_file if exists("s:outputbufnr") && bufexists(s:outputbufnr) execute 'keepjumps ' . bufwinnr(s:outputbufnr) else " execute "keepjumps vnew " s:dst_file execute "keepjumps rightbelow vertical new " . s:dst_file let s:outputbufnr=bufnr(s:dst_file) endif ``` From what I though `keepjumps` should be returning the cursor to its previous position, however, that doesn't appear to be the case.

Original source