From 2ec4c5f4f90838ba4b63e2edda63ccf261849177 Mon Sep 17 00:00:00 2001 From: Jonty Wareing Date: Fri, 17 Aug 2018 16:39:34 +0100 Subject: [PATCH] vim: Restore cursor/window position after format (#433) Without this the cursor jumps to the top of the window after formatting occurs. --- plugin/black.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin/black.vim b/plugin/black.vim index 0b958b8..df033e6 100644 --- a/plugin/black.vim +++ b/plugin/black.vim @@ -2,7 +2,7 @@ " Author: Łukasz Langa " Created: Mon Mar 26 23:27:53 2018 -0700 " Requires: Vim Ver7.0+ -" Version: 1.0 +" Version: 1.1 " " Documentation: " This plugin formats Python files. @@ -10,6 +10,8 @@ " History: " 1.0: " - initial version +" 1.1: +" - restore cursor/window position after formatting if v:version < 700 || !has('python3') echo "This script requires vim7.0+ with Python 3.6 support." @@ -108,7 +110,9 @@ def Black(): except Exception as exc: print(exc) else: + cursor = vim.current.window.cursor vim.current.buffer[:] = new_buffer_str.split('\n')[:-1] + vim.current.window.cursor = cursor print(f'Reformatted in {time.time() - start:.4f}s.') def BlackUpgrade(): -- 2.39.5