Skip to content

About

Text case conversion commands for Helix

Topics

Resources

Stars

7 stars

Watchers

0 watching

Forks

Repository files navigation

switch-case.hx

Text case conversion commands for the Helix editor.

Converts the text under each selection between UPPERCASE, lowercase, aLTERNATE cASE, PascalCase, camelCase, Title Case, Sentence case, snake_case, kebab-case, and CONSTANT_CASE.

Commands

Command Result
:switch-to-uppercase HELLO WORLD
:switch-to-lowercase hello world
:switch-to-alternate-case flips the case of each character
:switch-to-pascal-case HelloWorld
:switch-to-camel-case helloWorld
:switch-to-title-case Hello World
:switch-to-sentence-case Hello world
:switch-to-snake-case hello_world
:switch-to-kebab-case hello-world
:switch-to-constant-case HELLO_WORLD

Conversion rules

Word boundaries are inferred from three sources, so any input style can be converted to any other:

  • non-alphanumeric separators (spaces, _, -, punctuation);
  • camelCase transitions, where a lower-case character is followed by an upper-case one;
  • the end of an acronym, where the last upper-case character of a run is followed by a lower-case one, so HTTPServer is HTTP and Server.

Apostrophes are treated as an exception, so don’t and user’s are one word each.

UPPERCASE, lowercase, and aLTERNATE cASE change letter case and nothing else.

PascalCase, camelCase, snake_case, kebab-case and CONSTANT_CASE re-tokenise the words: they drop whatever separated the words and rejoin them with their own separator.

Title Case and Sentence case re-case the text where it stands, so prose keeps its punctuation and spacing: hello, world! becomes Hello, World!. A line with no whitespace of its own has no layout to keep, so it re-tokenises instead: helloWorld becomes Hello World and MY_CONST_VALUE becomes My Const Value. Punctuation other than _ and - stays where it was found either way, so foo.bar becomes Foo.Bar.

Every style converts a line at a time and leaves that line’s indentation and trailing padding alone, so a multiline selection keeps its shape and CRLF line endings survive.

Installation

Install with forge, Steel’s package manager:

forge pkg install --git https://github.com/waddie/switch-case.hx

Then load the plugin in your init.scm:

(require "switch-case/switch-case.scm")

Key bindings

(keymap (global)
  (normal ("`"
           (u ":switch-to-uppercase")
           (l ":switch-to-lowercase")
           (a ":switch-to-alternate-case")
           (p ":switch-to-pascal-case")
           (c ":switch-to-camel-case")
           (t ":switch-to-title-case")
           (S ":switch-to-sentence-case")
           (s ":switch-to-snake-case")
           (k ":switch-to-kebab-case")
           (C ":switch-to-constant-case")))
  (select ("`"
           (u ":switch-to-uppercase")
           (l ":switch-to-lowercase")
           (a ":switch-to-alternate-case")
           (p ":switch-to-pascal-case")
           (c ":switch-to-camel-case")
           (t ":switch-to-title-case")
           (S ":switch-to-sentence-case")
           (s ":switch-to-snake-case")
           (k ":switch-to-kebab-case")
           (C ":switch-to-constant-case"))))

Tests

The conversion logic is in switch-case-core.scm, which has no editor dependencies and so runs under the bare steel CLI. The suite needs steel-test:

sh tests/run-all.sh

switch-case.scm is the editor glue and can only be exercised in Helix.

Licence

AGPL-3.0-or-later. See LICENSE.

About

Text case conversion commands for Helix

Topics

Resources

Stars

7 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages