22

I'm setting up virtualized Linux boxes (as local development servers) for developers at a company that is primarily Windows-based, and some of developers make negative cracks about vim (among other things). (It seems to them to represent Linux/Unix in some way, and prove that the environment is obtusely difficult to use.) I remember when I was first forced to use vim, (the sysadmins refused to install emacs!) and the difficult initial learning curve, so I'm somewhat sympathetic. It occured to me that, rather than introduce them to nano (which they would probably never get past) it might be possible to set up nano-like menus in vim to make the transition easier. (I've found a very beginner-friendly .vimrc file to give them, but it doesn't have anything like nano-style menus.)

The only problem is the only thing I've been able to find that claims it's possible to setup menus in vim (not gvim) didn't work, and my attempts to correct the problem just left me with yet another problem to solve. Before I waste lots of time I'd like to know if it is in fact possible, since there seems to be very little information about how to do it.

2
  • 3
    Now this is in Vim help: :h console-menus.
    – Alexey
    Oct 28, 2015 at 10:32
  • @Alexey: thanks! that's very helpful to know... if I scroll down to section "5.2 Creating New Menus" that looks like it'll do what I want.
    – iconoclast
    Oct 29, 2015 at 3:02

2 Answers 2

26

Yes, it is possible. You can load menu.vim (the default gvim menu definitions), or you can just start from scratch and create your own, then access them through :emenu. This doesn't give you nano-like always-visible menus, though; it gives you the ability to navigate menus using command-line tab completion.

If the user doesn't have a vimrc, you'll want to start by disabling vi compatibility:

:set nocompatible

Enable smart command line completion on <Tab> (enable listing all possible choices, and navigating the results with <Up>, <Down>, <Left>, <Right>, and <Enter>):

:set wildmenu

Make repeated presses cycle between all matching choices:

:set wildmode=full

Load the default menus (this would happen automatically in gvim, but not in terminal vim):

:source $VIMRUNTIME/menu.vim

After those four commands, you can manually trigger menu completion by invoking tab completion on the :emenu command, by doing :emenu<space><tab>

You can navigate the results using the tab key and the arrow keys, and the enter key (it both expands submenus and selects items). You can then make that more convenient by going a step further, and binding a mapping to pop up the menu without having to type :emenu every time:

Make Ctrl-Z in a mapping act like pressing <Tab> interactively on the command line:

:set wildcharm=<C-Z>

And make a binding that automatically invokes :emenu completion for you:

:map <F4> :emenu <C-Z>
1
  • 3
    Brilliant! Let me know how I can buy you a beer!
    – iconoclast
    Dec 7, 2012 at 21:38
4

I've had the problem myself that I can't remember all the commands and key combinations for plugins I am using. Plus, I wanted to have simple ways to quickly execute commands without having to set new key mappings or inventing commands to access them.

Vim-Venu

I've written a small vim menu plugin that allows you to define menus for each filetype that you might edit with vim. This way, you can define the menu option 'Compile' for different filetypes and initiate the correct instructions to compile the code depending on what file you are editing (.py, .c, .c++, ...). Or create a submenu for 'Table' plugin commands in a markdown file.

Check it out here: https://github.com/Timoses/vim-venu

As a side note: I think everybody should choose their own favorite text editor. Vim does have a little barrier (which is worth learning!). If somebody is not willing to learn, then vim won't be of much use for that person.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .