Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I was an emacs user, and I have to switch to vim. But I miss some basic emacs commands in vim insert mode:

  1. C-A
  2. C-E
  3. C-K
  4. C-Y
  5. C-x C-s
  6. ... and some other

I know that I can press Escape and then press some of the following keys and finally press key i:

  1. ^
  2. $
  3. d$
  4. p
  5. :w [Enter]
  6. ...

However I will like to stay in vim insert mode and avoid pressing Escape/i keys.

On the web, I have found customizations for emacs (vi-mode, vip, viper, vimpulse, vim-mode, evil). But not yet found the opposite: customize vim to use emacs commands...

I am interested about the emacs commands in vim insert mode only. Just some basic commands, as bash commands: C-A, C-E, C-K, C-Y, C-U... (yep C-U is not a default emacs command but I like it too).

share|improve this question

2 Answers 2

You can map any command in insert mode to anything using the :imap command, or save typing by using :im. For your first mapping, you could type (in normal mode):

:im <C-A> <esc>^i

Which goes to normal mode (with escape), presses ^ for you and goes back to insert mode. See the help for more info:

:help :imap or shorter: :h :im

Do note that you might be overwriting existing key mappings. Put the commands into your .vimrc configuration file if you want them to be there for every document.

share|improve this answer
    
thanks for you tips +1 :-) But do you know whether this kind of mapping has already been configures? (e.g. without existing key mappings overwrite). Where to find such project/configuration? I would prefer to re-use something already done (and robust), than trying to do it myself (and missing something important). Cheers –  olibre Sep 26 '12 at 15:11
    
Should I ask/move my question to superuser.com ? –  olibre Sep 26 '12 at 15:15
    
Thanks! You can see whether a command exists with the (logic) command :im <c-a>. If it says 'No mapping found', you won't be overwriting anyting. I don't think it'll get much more robust than that... –  Joker Sep 26 '12 at 15:18
    
Humm... I have to code, test my configuration, then fix my bugs, and again.... But I do not know all the vim commands... Please, do you know where I can find a list of :im last arguments? FYI, I am also used with the following bash commands: M-backspace, M-F, M-B, M-D... It will be nice if someone has already done that and shares his work, isn't it? (something like evil) Therefore I could reuse his :im key mapping without doing it by myself (error prone). Do you see what I mean? –  olibre Sep 26 '12 at 16:43
    
I might not understand exactly what you mean, but you can find all non-standard key mappings by typing :im. To make a higher-level comment: if you want to be able to use Vim on multiple platforms/computers without always having to load your own plugins, special modes or vimrc-file, I think the best thing to do is to learn/use the standard Vim-commands as much as possible. I made several key mappings myself, but always try to find the standard Vim-alternative. And it can be pretty quick. One thing I did is map <esc> to ;j, making your nr 1 mapping as easy as ;jI and nr 2 ;jA. –  Joker Oct 2 '12 at 15:50

Not a complete answer, but are you aware of Vim's so-called "easy mode" (vim -y)? It is always in edit mode by defaut, and does quite a lot of what you want, and doesn't need you to install or customise anything. It does CTRL-A, C, V, X, Y etc. From the key-listing:

Key mappings:
    <Down>      moves by screen lines rather than file lines
    <Up>        idem
    Q           does "gq", formatting, instead of Ex mode
    <BS>        in Visual mode: deletes the selection
    CTRL-X      in Visual mode: Cut to clipboard
    <S-Del>     idem
    CTRL-C      in Visual mode: Copy to clipboard
    <C-Insert>  idem
    CTRL-V      Pastes from the clipboard (in any mode)
    <S-Insert>  idem
    CTRL-Q      do what CTRL-V used to do
    CTRL-Z      undo
    CTRL-Y      redo
    <M-Space>   system menu
    CTRL-A      select all
    <C-Tab>     next window, CTRL-W w
    <C-F4>      close window, CTRL-W c

A much more powerful version of this is Cream, which remaps many more keys, and makes the basic commands similar to other editors you may be familiar with.

There is also the plugin Vimacs, which enables all the common emacs key mappings. It's easy to install, and may do what you want (I've never tried it).

share|improve this answer
    
Very interesting +1 :-) I an reading/testing all your links... I will give you more feedback later. Thank you. Cheers –  olibre Sep 27 '12 at 7:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.