diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-04 01:06:45 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-04 01:06:45 +1200 |
commit | 2bb4902d546efc814150134f3900b7860bac9b84 (patch) | |
tree | c6eb6f4e62d1c21da38dff198f0d4be4da2cf862 | |
parent | Merge branch 'release/v0.1.0' (diff) | |
parent | Bump VERSION (diff) | |
download | vim-keep-position-0.2.0.tar.gz (sig) vim-keep-position-0.2.0.zip |
Merge branch 'release/v0.2.0'v0.2.0
* release/v0.2.0:
Add ranges support
Add command example
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | autoload/keep_position.vim | 6 | ||||
-rw-r--r-- | doc/keep_position.txt | 18 | ||||
-rw-r--r-- | plugin/keep_position.vim | 4 |
4 files changed, 23 insertions, 7 deletions
@@ -1 +1 @@ -0.1.0 +0.2.0 diff --git a/autoload/keep_position.vim b/autoload/keep_position.vim index a2f2ed4..7ff0228 100644 --- a/autoload/keep_position.vim +++ b/autoload/keep_position.vim @@ -1,5 +1,7 @@ -function! keep_position#(command) abort +function! keep_position#(command, range, start, end) abort let view = winsaveview() execute a:command - call winrestview(view) + if !a:range || (a:start >= line("'[") && a:end <= line("']")) + call winrestview(view) + endif endfunction diff --git a/doc/keep_position.txt b/doc/keep_position.txt index 6f1d516..05f69bc 100644 --- a/doc/keep_position.txt +++ b/doc/keep_position.txt @@ -15,8 +15,22 @@ COMMANDS *keep_position-commands* *:KeepPosition* Run the given command while preserving the cursor position and window view. -Works rather like |:keepalt| or |:keepjumps|. - +Works rather like |:keepalt| or |:keepjumps|. It's good for filters, +especially ones that work on the entire buffer: +> + :KeepPosition %!tidy +< +You will generally want to use this command as above, without a range. +However, if you do specify a range, it will only preserve the view if the last +change to the buffer--presumably made by your nominated command--entirely +encompassed the given range. This is checked with the |'[| and |']| marks. + +The author uses the range functionality to make a "conditional jump"; only +jump to the changes the given command makes if it didn't affect the entire +buffer, e.g.: +> + :nnoremap u :<C-U>%KeepPosition undo<CR> +< AUTHOR *keep_position-author* Written and maintained by Tom Ryder <tom@sanctum.geek.nz>. diff --git a/plugin/keep_position.vim b/plugin/keep_position.vim index 1389bcf..01227c3 100644 --- a/plugin/keep_position.vim +++ b/plugin/keep_position.vim @@ -11,5 +11,5 @@ endif let loaded_keep_position = 1 " User command definition refers to autoloaded function -command! -nargs=+ -complete=command KeepPosition - \ call keep_position#(<q-args>) +command! -nargs=+ -complete=command -range KeepPosition + \ call keep_position#(<q-args>, <range>, <line1>, <line2>) |