From db3d51ddc421dad68abddb95d01ffdab440197d6 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 19 Mar 2023 03:24:43 +0900 Subject: feat(content): specify heading id --- .../vim-swap-order-of-selected-lines/index.html | 46 +++++++++++----------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html') 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 @@

-
-

バージョン情報

+
+

TL; DR

+
" License: Public Domain
+
+command! -bar -range=%
+    \ Reverse
+    \ keeppatterns <line1>,<line2>g/^/m<line1>-1
+
+ +
+

バージョン情報

:version の一部

@@ -75,10 +84,10 @@
-
-

よく紹介されている手法

-
-

tac / tail

+
+

よく紹介されている手法

+
+

tac / tail

tactail -r などの外部コマンドを ! を使って呼び出し、置き換える。

@@ -94,8 +103,8 @@

-
-

:g/^/m0

+
+

:g/^/m0

こちらは外部コマンドに頼らず、Vim の機能のみを使う。g:global コマンドの、m:move コマンドの略

@@ -138,8 +147,8 @@
-
-

:g/^/m0 の問題点

+
+

:g/^/m0 の問題点

:global コマンドは各行に対してマッチングを行う際、現在の検索パターンを上書きしてしまう。^ は行の先頭にマッチするため、結果として全ての行がハイライトされてしまう。'hlsearch' オプションを無効にしている場合その限りではないが、その場合でも直前の検索パターンが失われてしまうと n コマンドなどの際に不便である。

@@ -151,8 +160,8 @@
-
-

解決策

+
+

解決策

[2020/9/28追記] より簡潔な方法を見つけたので次節に追記した @@ -212,8 +221,8 @@ command! -bar -range=%

-
-

解決策 (改訂版)

+
+

解決策 (改訂版)

[2020/9/28追記] より簡潔な方法を見つけたため追記する @@ -234,15 +243,6 @@ command! -bar -range=%

- -
-

コピペ用再掲

-
" License: Public Domain
-
-command! -bar -range=%
-    \ Reverse
-    \ keeppatterns <line1>,<line2>g/^/m<line1>-1
-
-- cgit v1.2.3-70-g09d2