aboutsummaryrefslogtreecommitdiffhomepage
path: root/public/posts/2021-10-02/vim-swap-order-of-selected-lines
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-03-18 15:47:05 +0900
committernsfisis <nsfisis@gmail.com>2023-03-18 15:47:05 +0900
commit2b50e1778b164e641c03c2e77176b6f47ca1e278 (patch)
tree3fa48f5c5c3c2b9d8753ce82d438aa2523856660 /public/posts/2021-10-02/vim-swap-order-of-selected-lines
parent4ce1f674055ac1dd1c4864f366aac212f5643248 (diff)
downloadblog.nsfisis.dev-2b50e1778b164e641c03c2e77176b6f47ca1e278.tar.gz
blog.nsfisis.dev-2b50e1778b164e641c03c2e77176b6f47ca1e278.tar.zst
blog.nsfisis.dev-2b50e1778b164e641c03c2e77176b6f47ca1e278.zip
refactor: add RawHTML type to represent text node not being escaped
Diffstat (limited to 'public/posts/2021-10-02/vim-swap-order-of-selected-lines')
-rw-r--r--public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html24
1 files changed, 12 insertions, 12 deletions
diff --git a/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html b/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html
index 8dbea05..22042a8 100644
--- a/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html
+++ b/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html
@@ -125,9 +125,9 @@
なお、<code>:g/^/m0</code>は全ての行を入れ替えるが、<code>:N,Mg/^/mN-1</code>とすることで N行目から M行目を処理範囲とするよう拡張できる。手でこれを入力するわけにはいかないので、次のようなコマンドを用意する。
</p>
- <pre class="highlight" language="vim" linenumbering="unnumbered"><code class="highlight">command! -bar -range=%
+ <pre class="highlight" language="vim" linenumbering="unnumbered"><code class="highlight">command! -bar -<span class="hljs-built_in">range</span>=%
\ Reverse
-\ &lt;line1&gt;,&lt;line2&gt;g/^/m&lt;line1&gt;-1</code></pre>
+\ <span class="hljs-symbol">&lt;line1&gt;</span>,<span class="hljs-symbol">&lt;line2&gt;</span>g/^/<span class="hljs-keyword">m</span><span class="hljs-symbol">&lt;line1&gt;</span>-<span class="hljs-number">1</span></code></pre>
<p>
これは望みの動作をするが、実際に実行してみると全行がハイライトされてしまう。次節で詳細を述べる。
@@ -160,13 +160,13 @@
前述した<code>:Reverse</code>コマンドの定義を少し変えて、次のようにする:
</p>
- <pre class="highlight" language="vim" linenumbering="unnumbered"><code class="highlight">function! s:reverse_lines(from, to) abort
- execute printf(&quot;%d,%dg/^/m%d&quot;, a:from, a:to, a:from - 1)
- endfunction
+ <pre class="highlight" language="vim" linenumbering="unnumbered"><code class="highlight"><span class="hljs-keyword">function!</span> <span class="hljs-title">s</span>:reverse_lines<span class="hljs-params">(from, to)</span> abort
+ <span class="hljs-keyword">execute</span> <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;%d,%dg/^/m%d&quot;</span>, <span class="hljs-variable">a:from</span>, <span class="hljs-variable">a:to</span>, <span class="hljs-variable">a:from</span> - <span class="hljs-number">1</span>)
+ <span class="hljs-keyword">endfunction</span>
- command! -bar -range=%
+ command! -bar -<span class="hljs-built_in">range</span>=%
\ Reverse
- \ call &lt;SID&gt;reverse_lines(&lt;line1&gt;, &lt;line2&gt;)</code></pre>
+ \ <span class="hljs-keyword">call</span> <span class="hljs-symbol">&lt;SID&gt;</span>reverse_lines(<span class="hljs-symbol">&lt;line1&gt;</span>, <span class="hljs-symbol">&lt;line2&gt;</span>)</code></pre>
<p>
実行しているコマンドが変わったわけではないが、関数呼び出しを経由するようにした。これだけで前述の問題が解決する。
@@ -217,9 +217,9 @@
</p>
</blockquote>
- <pre class="highlight" language="vim" linenumbering="unnumbered"><code class="highlight">command! -bar -range=%
+ <pre class="highlight" language="vim" linenumbering="unnumbered"><code class="highlight">command! -bar -<span class="hljs-built_in">range</span>=%
\ Reverse
- \ keeppatterns &lt;line1&gt;,&lt;line2&gt;g/^/m&lt;line1&gt;-1</code></pre>
+ \ keeppatterns <span class="hljs-symbol">&lt;line1&gt;</span>,<span class="hljs-symbol">&lt;line2&gt;</span>g/^/<span class="hljs-keyword">m</span><span class="hljs-symbol">&lt;line1&gt;</span>-<span class="hljs-number">1</span></code></pre>
<p>
まさにこのための Exコマンド、<code>:keeppatterns</code>が存在する。<code>:keeppatterns {command}</code>のように使い、読んで字の如く、後ろに続く Exコマンドを「現在の検索パターンを保ったまま」実行する。はるかに分かりやすく意図を表現できる。
@@ -234,11 +234,11 @@
<section id="section--_コピペ用再掲">
<h2><a href="#section--_コピペ用再掲">コピペ用再掲</a></h2>
- <pre class="highlight" language="vim" linenumbering="unnumbered"><code class="highlight">&quot; License: Public Domain
+ <pre class="highlight" language="vim" linenumbering="unnumbered"><code class="highlight"><span class="hljs-comment">&quot; License: Public Domain</span>
- command! -bar -range=%
+ command! -bar -<span class="hljs-built_in">range</span>=%
\ Reverse
- \ keeppatterns &lt;line1&gt;,&lt;line2&gt;g/^/m&lt;line1&gt;-1</code></pre>
+ \ keeppatterns <span class="hljs-symbol">&lt;line1&gt;</span>,<span class="hljs-symbol">&lt;line2&gt;</span>g/^/<span class="hljs-keyword">m</span><span class="hljs-symbol">&lt;line1&gt;</span>-<span class="hljs-number">1</span></code></pre>
</section>
</div>
</article>