From b2c5f0b9284f85e92d98efc97c780ad01ba81e0c Mon Sep 17 00:00:00 2001 From: Jan Larres Date: Sat, 22 Mar 2014 01:09:30 +1300 Subject: [PATCH] Keep cursor on current tag when sorting, closes #200 --- autoload/tagbar.vim | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index 1b9dbbc..d9ad0c5 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -2527,7 +2527,9 @@ function! s:ToggleSort() abort return endif + " Save the tag the cursor is currently on let curline = line('.') + let taginfo = s:GetTagInfo(curline, 0) match none @@ -2544,7 +2546,13 @@ function! s:ToggleSort() abort call s:RenderContent() call s:SetStatusLine('current') - execute curline + " If we were on a tag before sorting then jump to it, otherwise restore + " the cursor to the current line + if !empty(taginfo) + execute taginfo.tline + else + execute curline + endif endfunction " Display {{{1