aboutsummaryrefslogtreecommitdiff
path: root/posts
diff options
context:
space:
mode:
Diffstat (limited to 'posts')
-rw-r--r--posts/hold_position!.md23
1 files changed, 23 insertions, 0 deletions
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 @@
1Often times, when I run a vim command that makes "big" changes to a file (a
2macro or a `:vimgrep` command) I lose my original position and feel disoriented.
3
4*Save position with `winsaveview()`!*
5
6The `winsaveview()` command returns a `Dictionary` that contains information
7about the view of the current window. This includes the cursor line number,
8cursor coloumn, the top most line in the window and a couple of other values,
9none of which concern us.
10
11Before running our command (one that jumps around the buffer, a lot), we save
12our view, and restore it once its done, with `winrestview`.
13
14```
15let view = winsaveview()
16s/\s\+$//gc " find and confirm replace trailing blanks
17winrestview(view) " restore our original view!
18```
19
20It might seem a little overkill in the above example, just use `` (double
21backticks) instead, but it comes in handy when you run your file through
22heavier filtering.
23