question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: option for `w` and `b` to move by/select whole words instead of to the start of a new word.

See original GitHub issue

I used this plugin on Kakoune and have found it more convenient than Kakoune’s normal behaviour. AFAIU, the plugin makes it such that the word navigation keys w and b move/select whole words (excluding trailing whitespaces) instead of moving to/selecting to the end/start of the current word (which is instead done with W and B, and which also excludes trailing whitespaces). It would be nice if there was an option to enable the same behaviour for Dance.

I’ve included some example expected behaviours if this hypothetical option was enabled in Dance. For each example, the first row is the buffer’s state before input, second is the input (in normal mode), and the third is the buffer’s state after the input. | is where the cursor is, [ and ] indicates the start and end of selection. These assume caret selection is enabled.

word_a wor|d_b word_c

w:

word_a [word_b]| word_c

word_a wor|d_b word_c

b:

word_a |[word_b] word_c

wor|d_a word_b word_c

ww:

word_a [word_b]| word_c

word_a word_b wor|d_c

bb:

word_a |[word_b] word_c

word_a wor|d_b word_c

W:

word_a wor[d_b]| word_c

word_a wor|d_b word_c

B:

word_a |[wor]d_b word_c

wor|d_a word_b word_c

WW:

wor[d_a word_b]| word_c

word_a word_b wor|d_c

BB:

word_a |[word_b wor]d_c

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
71commented, Mar 20, 2021

I think I know what the issue is. First of all, to search backwards you should use dance.search.backwards with input \\w (the input is a RegExp). Second of all, you can use dance.selections.{backward,forward} to change the direction of the selections.

{
  "key": "b",
  "command": "dance.run",
  "args": {
    "code": [
      "        const editor = vscode.window.activeTextEditor,",
      "              prev = editor.selections,",
      "              commands = [['.objects.performSelection', { object: 'word', action: 'select', inner: true }],",
      "                          ['.selections.backward']];",
      "",
      "        try {",
      "          await dance.execute(...commands);",
      "        } catch (e) {",
      "          if ((e?.message ?? '') !== 'no selections remaining') throw e;",
      "        }",
      "",
      "        if (editor.selections.every((x, i) => x.isEqual(prev[i]))) {",
      "          try {",
      "            await dance.execute(['.search.backwards', { input: '\\\\w' }], ...commands);",
      "          } catch (e) {",
      "            if ((e?.message ?? '') !== 'no selections remaining') throw e;",
      "          }",
      "        }"
    ]
  },
  "when": "editorTextFocus && dance.mode == 'normal'"
}

Unfortunately I did some debugging and no selections remaining still happens in that case and worse yet, it somehow prevents the code from working correctly. I have an idea of where the issue comes from (some off by one errors when handling selections that does not seem to happen in character mode) but I haven’t been able to fix it yet.

1reaction
71commented, Mar 19, 2021

Looking at it, it looks like it’s implemented by invoking existing Kakoune commands. I spent some time trying to replicate this and some changes were needed, but in 0.4.2 you can have this kind of keybinding:

{
  "key": "w",
  "command": "dance.run",
  "args": {
    "code": [
      "const editor = vscode.window.activeTextEditor,",
      "      prev = editor.selections;",

      "try {",
      "  await dance.execute('.objects.performSelection', { object: 'word', action: 'select' });",
      "} catch (e) {",
      "  if ((e?.message ?? '') !== 'no selections remaining') throw e;",
      "}",

      "if (editor.selections.every((x, i) => x.isEqual(prev[i]))) {",
      "  await dance.execute(",
      "    ['.search', { input: '\\\\w' }],",
      "    ['.objects.performSelection', { object: 'word', action: 'select' }]);",
      "}",
    ],
  },
  "when": "editorTextFocus && dance.mode == 'normal'"
},

And similar keybindings with WbB (replacing the arguments of objects.performSelection as needed). Unfortunately there is a bug in the above code that will lead to “no selections remaining” being printed in some cases, but I haven’t found out why yet (and you can probably work around this).

In the future I’d like to make keybindings scriptable and to improve the scripting API, but for now this will have to do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Look up words in the thesaurus - Microsoft Support
Word. Click the word in your document that you want to look up. On the Review tab, click Thesaurus. Thesaurus command on Review...
Read more >
Use simple words and phrases - Plain language
Use simple words and phrases. When you're making word choices, pick the familiar or commonly used word over the unusual or obscure. There...
Read more >
How to Use Synonyms Effectively in a Sentence - Enago
Using synonyms or words with similar meaning, in a sentence helps avoid repetition and verbosity and maintain reader's attention.
Read more >
Synonyms of request - Merriam-Webster Thesaurus
Synonyms for REQUEST: inquiry, question, query, call, questioning, ... While all three words mean "to seek to obtain by making one's wants known,"...
Read more >
Can't afford to pay your taxes? Here are your options - CNBC
Here are the fees you'll pay with the short-term payment plan: $0 setup fee; Interest until the balance is paid in full; Penalties...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found