Giter Site home page Giter Site logo

vim-alt-mappings's Introduction

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/junegunn/vader.vim.git ~/.vim/bundle/vader.vim
  • Vundle
    • add Bundle 'junegunn/vader.vim' to .vimrc
    • then run :BundleInstall
  • NeoBundle
    • add NeoBundle 'junegunn/vader.vim' to .vimrc
    • then run :NeoBundleInstall
  • vim-plug
    • add Plug 'junegunn/vader.vim' to .vimrc
    • then run :PlugInstall

Terminal related setup

  • OS X Terminal.app: check "Use option as meta key"
    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)
    if 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.

vim-alt-mappings's People

Contributors

janko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.