vim-utils / vim-alt-mappings

(experimental!) Enables ALT key mappings in terminal vim
MIT License
38 stars 5 forks source link

This plugin is experimental

This plugin is experimental. After "playing" with it (if you want), you should probably uninstall it due to problems it can cause to your workflow.

After creating this plugin and validating the functionality via automated tests, 2 pretty big problematic areas were discovered:

So far I don't know how to solve these issues and thus the label "experimental".

Please get in touch (via github issue) if you have an idea how to solve the above problems.

Update: I opened an issue to Tim Pope in vim-rsi plugin, since he uses alt mappings there as well. It seems Tim was unaware of the problem as well.

Alt mappings in terminal Vim

Build Status

This plugin enables Alt key mappings in terminal vim.

Now you can do something like this:

map <M-a> :echo "You just pressed Alt-a!"<CR>
map <M-X> :echo "Works with uppercase letters."<CR>
map <M-5> :echo "Numbers are supported too"<CR>
map <M-$> :echo "as well as characters..."<CR>
map <M-?> :echo "and more characters..."<CR>
map <M-~> :echo "and more..."<CR>

Alt behaves as just another modifier key (can't get enough of those, right?)

Use cases

For example, when having soft-wrapped text in your buffer, to move between lines you can use gj and gk ("g" stands for graphical). When you use it a lot, you may realize that it quickly becomes tedious to have to prepend "g" every time. Drew Neil in his vimcast "Soft wrapping text" suggests mapping the "Command" key (D) to graphical keystrokes:

map <D-j> gj
map <D-k> gk

However, in Terminal vim this is not an option, because the "Command" key is used by the OS, and can't be used for mappings. Furthermore, PC users don't even have a "Command" key. "Alt" mappings to the rescue!

map <M-j> gj
map <M-k> gk

Installation

Use your favorite plugin manager.

Terminal related setup

Limitations

Mappings for the following keys are (currently?) not possible:

There are more than 90 Alt key mappings available, so hopefully you won't miss the above 4 that are not (yet?) possible.

Selectively enable Alt mappings

If you're aware of the issues that Alt mappings can do, and still wanna use some of them selectively, here's how you can do that.

Tests

This plugin uses the excellent vader.vim Vimscript testing framework. To run the tests locally:

Thanks

@tpope for his rsi.vim plugin, which was an inspiration for this one.