From c9ef66a75bb9a5a9c54d20b6d8a0b18966f0bf61 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Tue, 30 Jul 2019 19:16:37 +0530 Subject: new post! --- posts/hold_position!.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 posts/hold_position!.md (limited to 'posts') diff --git a/posts/hold_position!.md b/posts/hold_position!.md new file mode 100644 index 0000000..76cc2cc --- /dev/null +++ b/posts/hold_position!.md @@ -0,0 +1,23 @@ +Often times, when I run a vim command that makes "big" changes to a file (a +macro or a `:vimgrep` command) I lose my original position and feel disoriented. + +*Save position with `winsaveview()`!* + +The `winsaveview()` command returns a `Dictionary` that contains information +about the view of the current window. This includes the cursor line number, +cursor coloumn, the top most line in the window and a couple of other values, +none of which concern us. + +Before running our command (one that jumps around the buffer, a lot), we save +our view, and restore it once its done, with `winrestview`. + +``` +let view = winsaveview() +s/\s\+$//gc " find and confirm replace trailing blanks +winrestview(view) " restore our original view! +``` + +It might seem a little overkill in the above example, just use `` (double +backticks) instead, but it comes in handy when you run your file through +heavier filtering. + -- cgit v1.2.3