aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/index.html30
-rw-r--r--posts/hold_position!.md23
2 files changed, 53 insertions, 0 deletions
diff --git a/docs/index.html b/docs/index.html
index 5a000e8..d5f2be0 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -28,6 +28,36 @@ function showPost(id) {
28 28
29 <div class="post"> 29 <div class="post">
30 <div class="date">30/07 2019</div> 30 <div class="date">30/07 2019</div>
31 <a href="#hold_position!.md" class="post-link" onClick="showPost('hold_position!.md')">Hold Position!</a>
32 <div id="hold_position!.md" class="post-text" style="display: none">
33 <p>Often times, when I run a vim command that makes &#8220;big&#8221; changes to a file (a
34macro or a <code>:vimgrep</code> command) I lose my original position and feel disoriented.</p>
35
36<p><em>Save position with <code>winsaveview()</code>!</em></p>
37
38<p>The <code>winsaveview()</code> command returns a <code>Dictionary</code> that contains information
39about the view of the current window. This includes the cursor line number,
40cursor coloumn, the top most line in the window and a couple of other values,
41none of which concern us.</p>
42
43<p>Before running our command (one that jumps around the buffer, a lot), we save
44our view, and restore it once its done, with <code>winrestview</code>.</p>
45
46<pre><code>let view = winsaveview()
47s/\s\+$//gc &quot; find and confirm replace trailing blanks
48winrestview(view) &quot; restore our original view!
49</code></pre>
50
51<p>It might seem a little overkill in the above example, just use &#8220; (double
52backticks) instead, but it comes in handy when you run your file through
53heavier filtering.</p>
54 <a href="#hold_position!.md" class="post-end-link" onClick="showPost('hold_position!.md')">↑ Collapse</a>
55 <div class=separator></div>
56 </div>
57 </div>
58
59 <div class="post">
60 <div class="date">30/07 2019</div>
31 <a href="#get_better_at_yanking_and_putting_in_vim.md" class="post-link" onClick="showPost('get_better_at_yanking_and_putting_in_vim.md')">Get Better At Yanking And Putting In Vim</a> 61 <a href="#get_better_at_yanking_and_putting_in_vim.md" class="post-link" onClick="showPost('get_better_at_yanking_and_putting_in_vim.md')">Get Better At Yanking And Putting In Vim</a>
32 <div id="get_better_at_yanking_and_putting_in_vim.md" class="post-text" style="display: none"> 62 <div id="get_better_at_yanking_and_putting_in_vim.md" class="post-text" style="display: none">
33 <ol> 63 <ol>
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