Quickly Toggle Casing

· Nano Tips for Vim

#keymap #casing #plugins #prose

When writing prose (or comments or documentation in markdown), it is often useful to toggle between lower case ("word") and Capital Case ("Word"). While you could lower case a word with guiw and Capital Case it with bgUl, those really aren't convenient keychords to type. And even if remapped, it's two keymap you have to remember, even though it is really only one action (toggling between lower and Capital case).

This is one of the rare cases where the ~ command to toggle the case of the character under the cursor comes in handy: paired with b, the keystroke combination b~ does the job. But by making a few addition, we can further improve this:

When we then create a mapping for the final macro, mzlblgueh~`z, we have one keybinding that:

1vim.keymap.set("n", "<leader>u", "mzlblgueh~`z")

For changing between variable casing conventions, e.g. to turn a SNAKE_CASE variable into camelCase, there is the fantastic vim-absolish.