vim-alt-mappings


Ⅰ. 插件描述

(experimental!) Enables ALT key mappings in terminal vim

Ⅱ. 基本信息

创建日期:  2014-03-31
使用用户:  9
Github星:  35
插件作者:  vim-utils

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'bruno-/vim-alt-mappings'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'bruno-/vim-alt-mappings'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'bruno-/vim-alt-mappings'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/bruno-/vim-alt-mappings

Ⅳ. 文档说明

# 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:

  • it breaks macros if they use <esc> + char
  • mappings that use <esc> + char won't work

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.

  • Pathogen

    • just git clone https://github.com/vim-utils/vim-alt-mappings.git ~/.vim/bundle/vim-alt-mappings
  • Vundle

    • add Bundle 'vim-utils/vim-alt-mappings' to .vimrc
    • then run :BundleInstall
  • NeoBundle

    • add NeoBundle 'vim-utils/vim-alt-mappings' to .vimrc
    • then run :NeoBundleInstall
  • vim-plug

    • add Plug 'vim-utils/vim-alt-mappings' to .vimrc
    • then run :PlugInstall

Terminal related setup

  • OS X Terminal.app: check "Use option as meta key"<br/>
    OS X Terminal.app setting
  • OS X iTerm2, no setup needed
  • other?

Limitations

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

  • Alt-O (that's Alt big o)<br/>
  1. this one is set, movements arrow keys produce funny characters in insert and

command line mode.

  • Alt->, Alt-[ - couldn't find a way to make these work
  • Alt-space - when set up, messes up all other mappings

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.

  • 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>`
    

Tests

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

  • install vader.vim plugin
  • in this project's root directory run $ test/run

Thanks

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

添加新评论