Skip to content

Commit

Permalink
Preserve cursor column through formatting (#1369)
Browse files Browse the repository at this point in the history
* Preserve cursor column through formatting

Save it before calling the formatter, and use the column argument
when setting the position after.
  • Loading branch information
Chris Lee authored and fatih committed Jul 24, 2017
1 parent 2d89f00 commit 6be1c21
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion autoload/go/fmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function! go#fmt#Format(withGoimport) abort
let bin_name = "goimports"
endif

let current_col = col('.')
let out = go#fmt#run(bin_name, l:tmpname, expand('%'))
let diff_offset = len(readfile(l:tmpname)) - line('$')

Expand Down Expand Up @@ -99,7 +100,7 @@ function! go#fmt#Format(withGoimport) abort
endif

" be smart and jump to the line the new statement was added/removed
call cursor(line('.') + diff_offset, 0)
call cursor(line('.') + diff_offset, current_col)
endfunction

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

0 comments on commit 6be1c21

Please sign in to comment.