From fc955453787491127c557b4e18a4757960ea8c2c Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 2 May 2015 16:38:47 +0200 Subject: [PATCH] rename: save/restore tab/windows; not via `new_buffer` Ref: https://github.com/davidhalter/jedi-vim/pull/364#discussion-diff-25785992 --- jedi_vim.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/jedi_vim.py b/jedi_vim.py index 475885c..8894fbe 100644 --- a/jedi_vim.py +++ b/jedi_vim.py @@ -428,10 +428,13 @@ def rename(): vim_command('normal! diw') vim_command(':startinsert') else: - window_path = vim.current.buffer.name # reset autocommand vim_command('autocmd! jedi_rename InsertLeave') + # Save original window / tab. + saved_tab = int(vim_eval('tabpagenr()')) + saved_win = int(vim_eval('winnr()')) + replace = vim_eval("expand('')") vim_command('normal! u') # undo new word cursor = vim.current.window.cursor @@ -458,9 +461,10 @@ def rename(): vim.current.window.cursor = r.start_pos vim_command('normal! cw%s' % replace) - result = new_buffer(window_path) - if not result: - return + # Restore previous tab and window. + vim_command('tabnext {:d}'.format(saved_tab)) + vim_command('{:d}wincmd w'.format(saved_win)) + vim.current.window.cursor = cursor echo_highlight('Jedi did %s renames!' % len(temp_rename))