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:
<esc> + char
<esc> + char
won't workSo 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.
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?)
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
Use your favorite plugin manager.
git clone https://github.com/vim-utils/vim-alt-mappings.git ~/.vim/bundle/vim-alt-mappings
Bundle 'vim-utils/vim-alt-mappings'
to .vimrc:BundleInstall
NeoBundle 'vim-utils/vim-alt-mappings'
to .vimrc:NeoBundleInstall
Plug 'vim-utils/vim-alt-mappings'
to .vimrc:PlugInstall
OS X Terminal.app: check "Use option as meta key"
OS X iTerm2, no setup needed
other?
Mappings for the following keys are (currently?) not possible:
Alt-O
(that's Alt
big o)Alt->
, Alt-[
- couldn't find a way to make these workAlt-space
- when set up, messes up all other mappingsThere are more than 90 Alt
key mappings available, so hopefully you won't
miss the above 4 that are not (yet?) possible.
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.
you do not need to have this plugin installed
choose a character you're sure won't cause you problems in macros or
mappings, for example x
. It's unlikely you'll ever have <Esc>x
in your
macros or mappings.
enable <M-x>
mapping by putting the following in .vimrc
set <M-x>=\<Esc>x
map <M-x>
to something useful and use it!
map <M-x> :echo "really useful"<cr>
This plugin uses the excellent vader.vim Vimscript testing framework. To run the tests locally:
vader.vim
plugin$ test/run
@tpope for his rsi.vim plugin, which was an inspiration for this one.