From 838492059991b772659674694b41d470978917a6 Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Sun, 23 Jul 2017 00:37:15 +0300 Subject: [PATCH] fmt.vim: fix cursor staying on the same line when goimports is used fixes #1342 --- autoload/go/fmt.vim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/autoload/go/fmt.vim b/autoload/go/fmt.vim index ce77213d4e..41cd3e5c18 100644 --- a/autoload/go/fmt.vim +++ b/autoload/go/fmt.vim @@ -70,6 +70,8 @@ function! go#fmt#Format(withGoimport) abort endif let out = go#fmt#run(bin_name, l:tmpname, expand('%')) + let diff_offset = len(readfile(l:tmpname)) - line('$') + if go#util#ShellError() == 0 call go#fmt#update_file(l:tmpname, expand('%')) elseif g:go_fmt_fail_silently == 0 @@ -95,6 +97,9 @@ function! go#fmt#Format(withGoimport) abort " Restore our cursor/windows positions. call winrestview(l:curw) endif + + " be smart and jump to the line the new statement was added/removed + call cursor(line('.') + diff_offset, 0) endfunction " update_file updates the target file with the given formatted source