vim customized with emacs commands (insert mode only)
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.
I am responding to this question four years later because the answer provided is a partial solution that does not completely address the original question.
I have the exact same desire as olibre, and wanted to come up with a complete solution. I come at it from a different perspective -- I'm used to Emacs line editing in bash -- but the issue is the same. I want to carry that over into Vim insert mode (only).
The following addresses all of the keybinding requests in the original question posed by olibre, plus few extras:
" Mimic Emacs Line Editing in Insert Mode Only
inoremap <C-A> <Home>
inoremap <C-B> <Left>
inoremap <C-E> <End>
inoremap <C-F> <Right>
" â is <Alt-B>
inoremap â <C-Left>
" æ is <Alt-F>
inoremap æ <C-Right>
inoremap <C-K> <Esc>lDa
inoremap <C-U> <Esc>d0xi
inoremap <C-Y> <Esc>Pa
inoremap <C-X><C-S> <Esc>:w<CR>a
The only bindings I cannot seem to get to work at this point are I have gotten Alt combinations to work based on another post's suggestion to just use the special characters. I have inserted them above.<Alt-B>
and <Alt-F>
, which would skip entire words. Whenever I bind <Esc>
, <Alt>
, or <Meta>
combinations, gVim (v7.4 on Windows) outputs accented characters. Please feel free to edit this answer if you have a solution to this issue.
Edit
-- (edit is not by original answer poster) --
I used the following under Neovim and Windows 10. You might need to change the "A" into "M" on other OSs as "alt" might be "meta" elsewhere. I haven't played with it enough.
inoremap <A-x> <Esc>:
inoremap <A-f> <Esc>lwi
inoremap <A-b> <Esc>bi
inoremap <A-S-f> <Esc>lWi
inoremap <A-S-b> <Esc>Bi
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).