Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! That would do it. I'm guessing the second argument to cursor() is the column number?

endfunction

" update_file updates the target file with the given formatted source
Expand Down