A simple hinting Rust binary to be used in the Kakoune editor

Overview

Hop: hinting brought to Kakoune selections

Table of content:

This binary is intended to be used with the Kakoune editor, and provides hinting capabilities based on the current selections of the user. The workflow is simple:

  1. Make a selection in your buffer.
  2. Call the binary by providing the selections in %sh{} block — via $kak_selections_desc, typically.
  3. Hints appear. You can press the keys in order of each hint to reduce the hints.
  4. You typically reduce until only one hint remains; in such case, hinting is disabled and you are left with the sole selection. However, you are free to leave hinting at any reduction step by pressing the <esc> key.

Install

Currently, the only installation channel is https://crates.io. It requires cargo to be installed.

cargo install hop-kak

Configuration

Kakoune options

You must include the hop.kak file before trying to use Hop. It contains:

  • The hop_ranges option. Used to highlight your buffer with the labels.
  • The hop_label face definition. Feel free to override the default.

Another approach is to use hop-kak --init inside your kakrc to automatically inject the of the hop.kak file:

evaluate-commands %sh{ hop-kak --init }

--init is only available if hop-kak is compiled with the init features, which is enabled by default.

hop-kak options

hop-kak — the built binary — doesn’t have any configuration file. Instead, it is configured by passing CLI arguments:

  • -k --keyset: the keyset to use. This depends on your keyboard layout. Choose it wisely! It must not have any duplicate key, and keys are ordered by importance; i.e. the keys that are easier to reach should appear first.
    • For QWERTY, we recommend TODO.
    • For AZERTY, we recommend TODO.
    • For BÉPO, we recommend etisura,cnovpdélxqygàhfbjz.
  • -s --sels: selections to hint. You should always pass $kak_selections_desc here.
  • -l --labels: previous generated labels. You should never need to use that argument.
  • -z --key: key for reduction. You should never need to use that argument.
  • --handle: which part of a selection to put the cursor on; the anchor, or the cursor. Default to the anchor.

Usage

The binary was made with few responsibilities, so that people can use it in a wider variety of situations. For this reason, you will have to build a bit around hop-kak. hop-kak works by reading selections in, highlighting them and making Kakoune wait for a key press to either abort, or reduce the hints. If you decide to reduce the hints, hop-kak will filter your selections and reduce them to map the new set of hints. Hence, hop-kak can basically be seen as a trie reducer for Kakoune selections. It is then very composable. You pass it initial selections, and it interactively filters them.

Whatever your selections, you will always want to start a hopping session with the following command:

eval -no-hooks -- %sh{ hop-kak --keyset "<YOUR_KEYSET_HERE>" --sels "$kak_selections_desc" }

For instance, with the bépo keyboard layout, you could map the è key to start hopping with your current selections:

map global normal è ':eval -no-hooks -- %sh{ hop-kak --keyset "etisura,cnovpdélxqygàhfbjz" --sels "$kak_selections_desc" }<ret>'

Then, it’s up to you to come up with your own workflow!

Workflow examples

Default keyset

You should have an option to set your keyset if you intend on having several workflows. For instance, for bépo:

declare-option str hop_kak_keyset 'etisura,cnovpdélxqygàhfbjz'

Better selections

Something that is pretty useful is to map a key to select the visible part of the buffer. <a-%> is a good candidate, as it’s not mapped by Kakoune for now:

map global normal <a-%> ':execute-keys gtGbx<ret>'

This will help with creating selections. We assume you have this binding below. You can also make a command for that:

define-command hop-kak %{
  eval -no-hooks -- %sh{ hop-kak --keyset "$kak_opt_hop_kak_keyset" --sels "$kak_selections_desc" }
}

Select and hint visible words

With the <a-%> mapping, you can select words with <a-%>s\w+, and then press your mapping to start hopping around.

A slightly better approach to reduce the number of keys and control keys to type is to create a small function like this:

define-command -override hop-kak-words %{
  exec 'gtGbxs\w+<ret>:eval -no-hooks -- %sh{ hop-kak --keyset "$kak_opt_hop_kak_keyset" --sels "$kak_selections_desc" }<ret>'
}

And mapping it to your key; e.g. SPC è:

map global user è :hop-kak-words<ret>
You might also like...
Ox is a code editor that runs in your terminal
Ox is a code editor that runs in your terminal

Ox editor Ox is a code editor that runs in your terminal. About The Project Ox is a code editor. It was written in Rust using ANSI escape sequences. I

A standalone code editor with syntax highlighting and themes.
A standalone code editor with syntax highlighting and themes.

CodeEditor A standalone code (and text) editor for people like me who write their own user interfaces utilizing crates like pixels. CodeEditor renders

Move multiple files, with the power of your editor

NOTE FOR USERS THAT WANT TO TRY THIS OUT! The current code on the master branch doesn’t work as documented, as a newer more powerful interface is bein

Julia plugin for the Lapce Editor (using LanguageServer.jl)

Lapce Julia (LanguageServer) Lapce plugin for the Julia language powered by LanguageServer.jl Pre-requisites Make sure you have the julia binary on PA

Learn the helix editor keymap on the web!
Learn the helix editor keymap on the web!

Helix Shortcut Quiz A web quiz built with yew for testing your knowledge of helix editor shortcuts. Development Installation Frontend If you don't alr

SysEx editor for Roland SC-55 (GS), Roland SC-7, and eventually maybe Yamaha XG
SysEx editor for Roland SC-55 (GS), Roland SC-7, and eventually maybe Yamaha XG

SoundPalette: MIDI SysEx Generator This is the source code for SoundPalette, a tool for editing MIDI System Exclusive (SysEx) messages for the Roland

A list of crates with snippets used by me to learn more about Rust.

my-rust-examples This is a list of crates used by me to learn Rust. How to execute You can use a dependency called cargo-play: cargo install cargo-pla

Testing out if Rust can be used for a normal Data Engineering Pipeline.

RustForDataPipelines Testing out if Rust can be used for a normal Data Engineering Pipeline. Check out the full blog post here. https://www.confession

Rust implementation of TARA archive format, used in Tanki Online.

Tanki Online archive format Rust implementation of .tara archive format, developed by Alternativa Platform, used in Tanki Online. License Licensed und

Comments
  • Feature requst: post-hop actions

    Feature requst: post-hop actions

    Maybe I missed something in the README but I'm not seeing a way to execute actions after the selection has been selected. Is something like this currently possible?

    I was going to add two commands examples to the README, for adding a selection as a new cursor and extending current selection. These would start with Z before the hop and end with <a-z>a and <a-z>u respectively after the hop.

    I could maybe dig into source code to see what happens and what could be hooked into, but I think it would be awesome to have an established interface for this.

    enhancement 
    opened by postsolar 2
  • Some less-frequenty characters don't get interpreted when entering the label

    Some less-frequenty characters don't get interpreted when entering the label

    On my keyboard < happens to be just right of Shift and just below A, but when I'm using it as a label character it doesn't get interpreted. The error I'm getting is:

    Error: 1:1: 'evaluate-commands': 3:1: 'execute-keys': register '^' does not contain a selections desc
    

    Interestingly though characters which aren't mapped to Kakoune commands work fine, so can be used as a label, which is nice to have.

    opened by postsolar 1
Owner
Dimitri Sabadie
Do not make more tools than existing problems.
Dimitri Sabadie
Determine which CPU architecture is used in a binary file.

cpu_rec_rs Determine which CPU architecture is used in a binary file. Example: $ cpu_rec_rs /bin/bash /usr/lib/firmware/rtlwifi/rtl8821aefw* Loading c

Raphaël Rigo 61 Jun 27, 2023
Simple code editor made with Freya 🦀

Simple code editor made with Freya ?? This is a >work in progress< simple code editor that showcases how to use tree-sitter and freya together. WARNIN

Marc Espín 12 Dec 12, 2022
A structure editor for a simple functional programming language, with Vim-like shortcuts and commands.

dilim A structure editor for a simple functional programming language, with Vim-like shortcuts and commands. Written in Rust, using the Yew framework,

Joomy Korkut 6 Nov 18, 2022
Simple yet powerful multi-line text editor widget for tui-rs and ratatui

tui-textarea tui-textarea is a simple yet powerful text editor widget like <textarea> in HTML for tui-rs and ratatui. Multi-line text editor can be ea

Linda_pp 126 Jul 12, 2023
mn is my project to learn rust, I will try to build a markdown editor

med is a markdown editor This is my project to learn rust programming language, I will try to build a powerful markdown editor. Highlight: Support Vim

Skoo Wu 7 Dec 29, 2022
A basic text editor, written in Rust (hence the name).

rut A basic text editor, written in Rust (hence the name). Why, though? I just wanted a basic TUI text editor (like Nano) that could: Be used with all

Lowell Thoerner 4 Feb 3, 2023
nvim-oxi provides safe and idiomatic Rust bindings to the rich API exposed by the Neovim text editor.

?? nvim-oxi nvim-oxi provides safe and idiomatic Rust bindings to the rich API exposed by the Neovim text editor. The project is mostly intended for p

Riccardo Mazzarini 655 Jul 13, 2023
Amp: A text editor for your terminal.

Amp: A text editor for your terminal. Heavily inspired by Vi/Vim. Amp aims to take the core interaction model of Vim, simplify it, and bundle in the e

Jordan MacDonald 3.3k Jan 3, 2023
Basic vim-like editor for Redox-OS

red red is an editor based on vim written in Rust. Goal of this project is to provide a basic command-line editor, much like nano. Targeted for Redox.

null 1 Mar 5, 2022
Native cross-platform full feature terminal-based sequence editor for git interactive rebase.

Native cross-platform full feature terminal-based sequence editor for git interactive rebase.

Tim Oram 1.2k Jan 2, 2023