Open the editable file in vsplit, but stay in the starting position in vimscript

I am trying to write a plugin that will make a system call that generates a file based on the current buffer and then open the generated file in vsplit or, if it is already open, it will update it when the original file changes.

I have the code to such an extent that it generates a file and opens / updates the division, but the problem is that when it first opens the division, the focus moves to the split and when it updates the cursor position on the source the file goes to the top of the page.

Here is what I am 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 the fact that although keepjumps should return the cursor to its previous position, this does not seem to be the case.

+6
source share
2 answers

It sounds like the perfect use of the preview window in vim. When you open a file in the preview window ( :pedit /path/to/file ), the focus is not removed from the current window. You also have the option to go directly to the preview window when you need wincmd P if you need to. You can also close the preview window from anywhere with :pclose . If the file has been modified and you want to see the updates, you can simply :pedit /path/to/file get the updates again.

Another small advantage, even if you have a file in the preview window, you can still exit vim with a simple :q instead of :qa .

+3
source

I suspect that you want to use wincmd p after separation, this will return you to the previous window in which you were.

+1
source

Source: https://habr.com/ru/post/914816/


All Articles