aboutsummaryrefslogtreecommitdiff
path: root/docs/posts/hold_position!/index.html
blob: eaa6e0dcb8201212c232b410aa6416f764193481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="/style.css">
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1">
    <meta content="#ffffff" name="theme-color">
    <meta name="HandheldFriendly" content="true">
    <meta property="og:title" content="nerdypepper">
    <meta property="og:type" content="website">
    <meta property="og:description" content="a static site {for, by, about} me ">
    <meta property="og:url" content="https://nerdypepper.tech">
    <body>
      <div class="posts">
        <div class="post">
          <a href="/" class="post-end-link">⟵ Back</a>
          <div class="separator"></div>
          <div class="date">
            30/07 2019
            <div class="stats">
              <span class="stats-number">
                9.18
              </span>
              <span class="stats-unit">cm</span>
              &nbsp
              &nbsp
              <span class="stats-number">
                1.0
              </span>
              <span class="stats-unit">min</span>
            </div>
          </div>
          <span class="post-title">
            Hold Position!
          </span>
          <div class="post-text">
            <p>Often times, when I run a vim command that makes &#8220;big&#8221; changes to a file (a
macro or a <code>:vimgrep</code> command) I lose my original position and feel disoriented.</p>

<p><em>Save position with <code>winsaveview()</code>!</em></p>

<p>The <code>winsaveview()</code> command returns a <code>Dictionary</code> 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.</p>

<p>Before running our command (one that jumps around the buffer, a lot), we save
our view, and restore it once its done, with <code>winrestview</code>.</p>

<pre><code>let view = winsaveview()
s/\s\+$//gc              &quot; find and (confirm) replace trailing blanks
winrestview(view)        &quot; restore our original view!
</code></pre>

<p>It might seem a little overkill in the above example, just use &#8220; (double
backticks) instead, but it comes in handy when you run your file through
heavier filtering.</p>

          </div>
          <div class="separator"></div>
          <a href="/" class="post-end-link">⟵ Back</a>
        </div>
      </div>
    </body>
</html>