aboutsummaryrefslogtreecommitdiffhomepage
path: root/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html')
-rw-r--r--public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html46
1 files changed, 23 insertions, 23 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 6b9e423..320e80e 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
@@ -62,8 +62,17 @@
</hr>
</p>
- <section id="section--_バージョン情報">
- <h2><a href="#section--_バージョン情報">バージョン情報</a></h2>
+ <section id="section--tl-dr">
+ <h2><a href="#section--tl-dr">TL; DR</a></h2>
+ <pre class="highlight" language="vim" linenumbering="unnumbered"><code class="highlight"><span class="hljs-comment">&quot; License: Public Domain</span>
+
+command! -bar -<span class="hljs-built_in">range</span>=%
+ \ Reverse
+ \ 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>
+
+ <section id="section--version">
+ <h2><a href="#section--version">バージョン情報</a></h2>
<p>
<code>:version</code> の一部
</p>
@@ -75,10 +84,10 @@
</blockquote>
</section>
- <section id="section--_よく紹介されている手法">
- <h2><a href="#section--_よく紹介されている手法">よく紹介されている手法</a></h2>
- <section id="section--_tac_tail">
- <h3><a href="#section--_tac_tail"><code>tac</code> / <code>tail</code></a></h3>
+ <section id="section--existing-solution">
+ <h2><a href="#section--existing-solution">よく紹介されている手法</a></h2>
+ <section id="section--existing-solution--external-commands">
+ <h3><a href="#section--existing-solution--external-commands"><code>tac</code> / <code>tail</code></a></h3>
<p>
<code>tac</code> や <code>tail -r</code> などの外部コマンドを <code>!</code> を使って呼び出し、置き換える。
</p>
@@ -94,8 +103,8 @@
</p>
</section>
- <section id="section--_gm0">
- <h3><a href="#section--_gm0"><code>:g/^/m0</code></a></h3>
+ <section id="section--existing-solution--global-command">
+ <h3><a href="#section--existing-solution--global-command"><code>:g/^/m0</code></a></h3>
<p>
こちらは外部コマンドに頼らず、Vim の機能のみを使う。<code>g</code> は <code>:global</code> コマンドの、<code>m</code> は <code>:move</code> コマンドの略
</p>
@@ -138,8 +147,8 @@
</section>
</section>
- <section id="section--_gm0_の問題点">
- <h2><a href="#section--_gm0_の問題点"><code>:g/^/m0</code> の問題点</a></h2>
+ <section id="section--problem-of-global-command">
+ <h2><a href="#section--problem-of-global-command"><code>:g/^/m0</code> の問題点</a></h2>
<p>
<code>:global</code> コマンドは各行に対してマッチングを行う際、現在の検索パターンを上書きしてしまう。<code>^</code> は行の先頭にマッチするため、結果として全ての行がハイライトされてしまう。<code>&apos;hlsearch&apos;</code> オプションを無効にしている場合その限りではないが、その場合でも直前の検索パターンが失われてしまうと <code>n</code> コマンドなどの際に不便である。
</p>
@@ -151,8 +160,8 @@
</blockquote>
</section>
- <section id="section--_解決策">
- <h2><a href="#section--_解決策">解決策</a></h2>
+ <section id="section--solution">
+ <h2><a href="#section--solution">解決策</a></h2>
<blockquote>
<p>
[2020/9/28追記] より簡潔な方法を見つけたので次節に追記した
@@ -212,8 +221,8 @@ command! -bar -<span class="hljs-built_in">range</span>=%
</p>
</section>
- <section id="section--_解決策_改訂版">
- <h2><a href="#section--_解決策_改訂版">解決策 (改訂版)</a></h2>
+ <section id="section--solution-revised">
+ <h2><a href="#section--solution-revised">解決策 (改訂版)</a></h2>
<blockquote>
<p>
[2020/9/28追記] より簡潔な方法を見つけたため追記する
@@ -234,15 +243,6 @@ command! -bar -<span class="hljs-built_in">range</span>=%
</p>
</blockquote>
</section>
-
- <section id="section--_コピペ用再掲">
- <h2><a href="#section--_コピペ用再掲">コピペ用再掲</a></h2>
- <pre class="highlight" language="vim" linenumbering="unnumbered"><code class="highlight"><span class="hljs-comment">&quot; License: Public Domain</span>
-
-command! -bar -<span class="hljs-built_in">range</span>=%
- \ Reverse
- \ 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>
</main>