switch-case.hx
Text case conversion commands for Helix
- Stars: 7
- Last commit:
- Created:
Text case conversion commands for Helix
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.
| 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 |
Word boundaries are inferred from three sources, so any input style can be converted to any other:
_, -, punctuation);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.
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")
(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"))))
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.
AGPL-3.0-or-later. See LICENSE.
README from waddie/switch-case.hx · GNU Affero General Public License v3.0