Vim Tip: I want more menus!

Post by Nico Brailovsky @ 2015-04-02 | Permalink | 1 comments | Leave a comment

As a uber vim geek, you shouldn't be using a lot of gui menus. Scratch that, you shouldn't be using any menus at all, period. Still, I'll admit it's a bit hard to remember every single shortcut for actions you rarely use.

Say, for example, you like to encrypt your text. Not always, but every once in a while. Enough to make a shortcut for it but not enough to remember what the shortcut is. You can try to grep your ~/.vimrc. You might find something like:

" Encrypt my stuff
map e ggg?G

(Yes, that command will actually encrypt your text in Vim. Try it!)

Wouldn't it be nice if you had a simpler way, though?

Turns out you can add your "encrypt" command to your gui. Then "menu" commands work just like the "map" family, but they create a GUI menu instead. Change your vimrc to something like this:

" Encrypt my stuff
map e ggg?G
menu Project.Encrypt ggg?G

Now if you reload your vimrc you'll find a new GUI menu created, from which you can easily encrypt your text. Decrypting is left as an exercise to the reader.

Extra tip: Want to try to learn the actual shortcut, like a real vim'er? Then try this:

menu Project.Encryptggg?G ggg?G

Everything after the TAB will be right-aligned: you can use that space to annotate the key-combo you should use next time.

As usual, for more info check :help menu


In reply to this post, Simple vim plugin I: integrating new commands | An infinite monkey - Nicolas Brailovsky's blog commented @ 2016-11-24T08:00:30.000+01:00:

[...] tip: add these too if you want to have a GUI menu for your new commands as [...]

Original published here.