From 84c097b2586fa3efd63605a41d4cf34f4beea0e9 Mon Sep 17 00:00:00 2001 From: monaqa Date: Thu, 6 Apr 2023 00:12:08 +0900 Subject: [PATCH] doc: add doc for g in NORMAL mode --- README.md | 4 +++ README_ja.md | 4 +++ doc/dial.jax | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ doc/dial.txt | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 184 insertions(+) diff --git a/README.md b/README.md index 0dbedf2..869f5ef 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ To use this plugin, you need to assign the plugin key-mapping to the key you lik ```vim nmap (dial-increment) nmap (dial-decrement) +nmap g g(dial-increment) +nmap g g(dial-decrement) vmap (dial-increment) vmap (dial-decrement) vmap g g(dial-increment) @@ -61,6 +63,8 @@ Or you can configure it with Lua as follows: ```lua vim.keymap.set("n", "", require("dial.map").inc_normal(), {noremap = true}) vim.keymap.set("n", "", require("dial.map").dec_normal(), {noremap = true}) +vim.keymap.set("n", "g", require("dial.map").inc_gnormal(), {noremap = true}) +vim.keymap.set("n", "g", require("dial.map").dec_gnormal(), {noremap = true}) vim.keymap.set("v", "", require("dial.map").inc_visual(), {noremap = true}) vim.keymap.set("v", "", require("dial.map").dec_visual(), {noremap = true}) vim.keymap.set("v", "g",require("dial.map").inc_gvisual(), {noremap = true}) diff --git a/README_ja.md b/README_ja.md index 548ff63..2c92e10 100644 --- a/README_ja.md +++ b/README_ja.md @@ -53,6 +53,8 @@ ```vim nmap (dial-increment) nmap (dial-decrement) +nmap g g(dial-increment) +nmap g g(dial-decrement) vmap (dial-increment) vmap (dial-decrement) vmap g g(dial-increment) @@ -64,6 +66,8 @@ vmap g g(dial-decrement) ```lua vim.keymap.set("n", "", require("dial.map").inc_normal(), {noremap = true}) vim.keymap.set("n", "", require("dial.map").dec_normal(), {noremap = true}) +vim.keymap.set("n", "g", require("dial.map").inc_gnormal(), {noremap = true}) +vim.keymap.set("n", "g", require("dial.map").dec_gnormal(), {noremap = true}) vim.keymap.set("v", "", require("dial.map").inc_visual(), {noremap = true}) vim.keymap.set("v", "", require("dial.map").dec_visual(), {noremap = true}) vim.keymap.set("v", "g", require("dial.map").inc_gvisual(), {noremap = true}) diff --git a/doc/dial.jax b/doc/dial.jax index 8a93f44..18a5e24 100644 --- a/doc/dial.jax +++ b/doc/dial.jax @@ -29,6 +29,7 @@ Configurations |dial-config| User |dial-augends-user| Advanced Usage |dial-advanced-usage| Dot Repeating |dial-dot-repeating| + Additive Dot Repeating |dial-additive-dot-repeating| Interface |dial-interface| Mapping |dial-mapping| Command |dial-command| @@ -95,6 +96,8 @@ USAGE *dial-usage* > nmap (dial-increment) nmap (dial-decrement) + nmap g g(dial-increment) + nmap g g(dial-decrement) vmap (dial-increment) vmap (dial-decrement) vmap g g(dial-increment) @@ -109,6 +112,12 @@ USAGE *dial-usage* vim.keymap.set("n", "", function() require("dial.map").manipulate("decrement", "normal") end) + vim.keymap.set("n", "g", function() + require("dial.map").manipulate("increment", "gnormal") + end) + vim.keymap.set("n", "g", function() + require("dial.map").manipulate("decrement", "gnormal") + end) vim.keymap.set("v", "", function() require("dial.map").manipulate("increment", "visual") end) @@ -1264,6 +1273,64 @@ DOT REPEATING *dial-dot-repeating* したがって上の例では、ひとたび検索を行った後であれば `.n.n.` とするだけですべ ての期限を1ヶ月延ばすことができるのです。 +------------------------------------------------------------------------------ +ADDITIVE DOT REPEATING *dial-additive-dot-repeating* + +Vim の便利な機能の1つに、VISUAL モードにおける g があります +(|v_g_CTRL-A| 参照)。これは加数を行ごとに1ずつ増やすことができる機能であり、 +番号付きの箇条書きなどを生成する際に重宝します。もちろん |dial.nvim| でも同等 +の機能を備えています (|v_g(dial-increment)|)。この機能は便利ながら、増加 +対象が離れた場所にあると使いづらいという制限がありました。 +これを解決するため、|dial.nvim| ではノーマルモードの g に相当する機能を提 +供しています。これを有効にするには、以下の設定を書いておく必要があります: +> + nmap g g(dial-increment) + nmap g g(dial-decrement) +< +もしくは Lua 上で以下のように設定することもできます。 +> + vim.keymap.set("n", "g", function() + require("dial.map").manipulate("increment", "gnormal") + end) + vim.keymap.set("n", "g", function() + require("dial.map").manipulate("decrement", "gnormal") + end) + +ノーマルモード上での g の動作は通常の とほぼ同じですが、ドットリ +ピートを実行したときの挙動のみが異なります。 でドットリピートを実行した +とき加数は [count] のままですが、 g でドットリピートすると加数が [count] +ずつ増えていきます。 + +たとえば、以下のようなバッファを考えます。なにか適当な関数を定義し、同じものを +2回コピーした場面です。このままでは関数名が衝突してしまうため、関数の数字を1つ +ずつインクリメントして `test_foo_1`, `test_foo_2`, `test_foo_3` という名前に変 +更したいものとします。 +> + def test_foo_0(): + assert 100 + 100 == 200 + + def test_foo_0(): + assert 100 + 100 == 200 + + def test_foo_0(): + assert 100 + 100 == 200 + +このような関数の命名が良いのかどうかはさておき、テキスト編集を行う上での直近の +問題は編集対象の行が離れていることです。このままではビジュアルモードでの g +が使えません。 +しかし、ノーマルモードの g であれば簡単に解決できます。 + +1. `test_foo_0` を検索し、g を押す。 +2. `n` で次の検索結果に移動し、 `.` を押す(ドットリピート)。 +3. `n` で次の検索結果に移動し、 `.` を押す(ドットリピート)。 + +これだけで `test_foo_1`, `test_foo_2`, `test_foo_3` という関数名が得られたはず +です。 + +これだけ見ると被加数が延々と増加してしまうのではと感じたかもしれませんが、そん +なことはありません。被加数が増加するのは g でドットリピートを実行したとき +だけであり、 や g を改めて押せば数値はリセットされます。 + ============================================================================== INTERFACE *dial-interface* @@ -1331,6 +1398,14 @@ MAPPING *dial-mapping* {VISUAL}["x]g(dial-decrement) *v_g(dial-decrement)* VISUAL モードにおける |v_g_CTRL-X| に相当する機能を提供します。 +["x]g(dial-increment) *g(dial-increment)* + 基本的に |(dial-increment)| と同じですが、ドットリピートを実行したと + きの挙動が異なります。 |dial-additive-dot-repeating| 参照。 + +["x]g(dial-decrement) *g(dial-decrement)* + 基本的に |(dial-decrement)| と同じですが、ドットリピートを実行したと + きの挙動が異なります。 |dial-additive-dot-repeating| 参照。 + ------------------------------------------------------------------------------ COMMAND *dial-command* @@ -1397,6 +1472,18 @@ require("dial.map").dec_normal([group_name]) NORMAL モードにおいて与えられたグループ名をもとにデクリメントを行うための キーシーケンスを出力します。 + *dial.map.inc_normal()* +require("dial.map").inc_gnormal([group_name]) + + 加算的なインクリメントを行うためのキーシーケンスを表す文字列を出力します。 + |dial-additive-dot-repeating| 参照。 + + *dial.map.dec_normal()* +require("dial.map").dec_gnormal([group_name]) + + 加算的なデクリメントを行うためのキーシーケンスを表す文字列を出力します。 + |dial-additive-dot-repeating| 参照。 + *dial.map.inc_visual()* require("dial.map").inc_visual([group_name]) diff --git a/doc/dial.txt b/doc/dial.txt index fe3b632..2b5c70b 100644 --- a/doc/dial.txt +++ b/doc/dial.txt @@ -30,6 +30,7 @@ Configurations |dial-config| User |dial-augends-user| Advanced Usage |dial-advanced-usage| Dot Repeating |dial-dot-repeating| + Additive Dot Repeating |dial-additive-dot-repeating| Interface |dial-interface| Mapping |dial-mapping| Command |dial-command| @@ -98,6 +99,8 @@ plugin. > nmap (dial-increment) nmap (dial-decrement) + nmap g g(dial-increment) + nmap g g(dial-decrement) vmap (dial-increment) vmap (dial-decrement) vmap g g(dial-increment) @@ -112,6 +115,12 @@ Alternatively, you can configure with Lua as follows: vim.keymap.set("n", "", function() require("dial.map").manipulate("decrement", "normal") end) + vim.keymap.set("n", "g", function() + require("dial.map").manipulate("increment", "gnormal") + end) + vim.keymap.set("n", "g", function() + require("dial.map").manipulate("decrement", "gnormal") + end) vim.keymap.set("v", "", function() require("dial.map").manipulate("increment", "visual") end) @@ -1320,6 +1329,66 @@ the nearest "month" of the date and then the same increment operation is performed. Thus, in the above example, once you have done the search, you can extend all the due dates by one month just by typing `.n.n.`. +------------------------------------------------------------------------------ +ADDITIVE DOT REPEATING *dial-additive-dot-repeating* + +One convenient feature of Vim is g in VISUAL mode (see |v_g_CTRL-A|). +This allows you to increase the addend by one per line, which is useful for +generating numbered list, etc. Of course, |dial.nvim| provides the same +functionality (|v_g(dial-increment)|). However, this feature had the +limitation that it was difficult to use when the increase targets were located +far away. +To solve this, |dial.nvim| provides the equivalent of g in normal mode. +To enable it, the following configuration must be written: . +> + nmap g g(dial-increment) + nmap g g(dial-decrement) + +Alternatively, you can configure with Lua as follows: +> + vim.keymap.set("n", "g", function() + require("dial.map").manipulate("increment", "gnormal") + end) + vim.keymap.set("n", "g", function() + require("dial.map").manipulate("decrement", "gnormal") + end) + +The behavior of g in normal mode is almost the same as normal , but +only the behavior during dot repeating is different. While the addend remains +[count] in dot repeating of , the addend is increased by [count] in dot +repeating of g. + +For example, consider the following buffer, where you have defined some +function and copied it twice. Since the function names conflict, we want to +rename the functions test_foo_1, test_foo_2, and test_foo_3 by incrementing +the function number by one. + +> + def test_foo_0(): + assert 100 + 100 == 200 + + def test_foo_0(): + assert 100 + 100 == 200 + + def test_foo_0(): + assert 100 + 100 == 200 + +We do not consider whether such function naming is a good idea. Anyway, the +most immediate problem is that the lines to be edited are far apart. As it is, +you cannot use g in VISUAL mode. +However, this can be easily resolved with g in NORMAL mode. + +1. Search for `test_foo_0`, jump, and press g. +2. Press `n` to move to the next result and press `.` (dot repeat). +3. Press `n` to move to the next result and press `.` (dot repeat). + +This should be enough to obtain the function names `test_foo_1`, `test_foo_2`, +and `test_foo_3`. + +You may think that the number of addend will increase endlessly, but this is +not true. The addend increases only when you execute a dot repeat, and the +number is reset when you press or g again. + ============================================================================== INTERFACE *dial-interface* @@ -1390,6 +1459,14 @@ MAPPING *dial-mapping* {VISUAL}["x]g(dial-decrement) *v_g(dial-decrement)* An alternative to the existing |v_g_CTRL-X| command in VISUAL mode. +["x]g(dial-increment) *g(dial-increment)* + Almost the same as |(dial-increment)|, but but the behavior differs + during dot repeating. See |dial-additive-dot-repeating|. + +["x]g(dial-decrement) *g(dial-decrement)* + Almost the same as |(dial-decrement)|, but but the behavior differs + during dot repeating. See |dial-additive-dot-repeating|. + ------------------------------------------------------------------------------ COMMAND *dial-command* @@ -1449,6 +1526,18 @@ require("dial.map").inc_normal([group_name]) ) < + *dial.map.inc_normal()* +require("dial.map").inc_gnormal([group_name]) + + Outputs a key sequence for additive incrementing. See + |dial-additive-dot-repeating|. + + *dial.map.dec_normal()* +require("dial.map").dec_gnormal([group_name]) + + Outputs a key sequence for additive decrementing. See + |dial-additive-dot-repeating|. + *dial.map.dec_normal()* require("dial.map").dec_normal([group_name])