vim: Restore cursor/window position after format (#433)
Without this the cursor jumps to the top of the window after formatting occurs.
This commit is contained in:
parent
1e56d02cad
commit
2ec4c5f4f9
@ -2,7 +2,7 @@
|
|||||||
" Author: Łukasz Langa
|
" Author: Łukasz Langa
|
||||||
" Created: Mon Mar 26 23:27:53 2018 -0700
|
" Created: Mon Mar 26 23:27:53 2018 -0700
|
||||||
" Requires: Vim Ver7.0+
|
" Requires: Vim Ver7.0+
|
||||||
" Version: 1.0
|
" Version: 1.1
|
||||||
"
|
"
|
||||||
" Documentation:
|
" Documentation:
|
||||||
" This plugin formats Python files.
|
" This plugin formats Python files.
|
||||||
@ -10,6 +10,8 @@
|
|||||||
" History:
|
" History:
|
||||||
" 1.0:
|
" 1.0:
|
||||||
" - initial version
|
" - initial version
|
||||||
|
" 1.1:
|
||||||
|
" - restore cursor/window position after formatting
|
||||||
|
|
||||||
if v:version < 700 || !has('python3')
|
if v:version < 700 || !has('python3')
|
||||||
echo "This script requires vim7.0+ with Python 3.6 support."
|
echo "This script requires vim7.0+ with Python 3.6 support."
|
||||||
@ -108,7 +110,9 @@ def Black():
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print(exc)
|
print(exc)
|
||||||
else:
|
else:
|
||||||
|
cursor = vim.current.window.cursor
|
||||||
vim.current.buffer[:] = new_buffer_str.split('\n')[:-1]
|
vim.current.buffer[:] = new_buffer_str.split('\n')[:-1]
|
||||||
|
vim.current.window.cursor = cursor
|
||||||
print(f'Reformatted in {time.time() - start:.4f}s.')
|
print(f'Reformatted in {time.time() - start:.4f}s.')
|
||||||
|
|
||||||
def BlackUpgrade():
|
def BlackUpgrade():
|
||||||
|
Loading…
Reference in New Issue
Block a user