Skip to content

Commit

Permalink
Merge pull request #1367 from fatih/improve-cursor-replacement-fmt
Browse files Browse the repository at this point in the history
fmt.vim: fix cursor staying on the same line when goimports is used
  • Loading branch information
fatih authored Jul 22, 2017
2 parents ca1d712 + 8384920 commit ab0df08
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions autoload/go/fmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ab0df08

Please sign in to comment.