Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt.vim: fix cursor staying on the same line when goimports is used #1367

Merged
merged 1 commit into from
Jul 22, 2017
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