Is there any key combination that simulate the Del in Vim insert mode? For the Backspace, there is the Ctrl-H which is very convenient, and make it easier than pushing the far away Backspace button.
Take a look at http://vimdoc.sourceforge.net/htmldoc/insert.html There are a few more built-in key combinations for various tasks.
Also you can set your own mappings using .vimrc for example your given example is just
imap ^H <Left><Del>
On my vim installation, Del in insert mode Just Works. :help i_<Del>
If Del isn't doing what you want, you can try :fixdel. :help :fixdel has a good explanation of what that tries to fix.
If you simply wanted to simulate Del via another Ctrl-key mapping (e.g. Ctrl-D), I'd recommend the following mapping:
imap <C-D> <C-O>x
Ctrl-O in insert mode will allow you to run a single normal mode command and automatically return back to insert mode. x deletes the key under the cursor.
You can map keys yourself in vim, including insert mode. The following article reveals more details:
Mapping keys in VIM
Related
I want to achieve the following using a key shortcut in Vim:
hi
| <-my cursor is here
there
press shift+o
hi
| <-my cursor is here
there
press enter
hi
| <-my cursor is here
there
The following mapping should be enough
nn <Leader>o O<CR><Esc>
Note
<Leader> is a "special key" that you can set (cf. :h <Leader>)
you can choose your own key combination to trigger the mapping, not necessarily <Leader>o
<Esc> is to go back to normal mode. Given How O and o work maybe you want to remain in insert mode? If so, remove <Esc>.
You are looking for :help mapping. Mapping keys is when you map one key or several keys to act like other keys. In your case, this is a map you might use:
nnoremap (your chosen key(s)) O<CR>
This means that in normal mode, when you hit your chosen key(s), vim will instead act as though you hit O and then <CR>. <CR> is how you indicate the 'Enter/Return' key.
This is assuming you meant you wanted to start from normal mode.
I have edited my .vimrc file and mapped some commands. They are only working in normal mode. Is there any way to map commands in insert mode? (e.g. commands involved with special keys such as Ctrl) For example, can I copy in insert mode using Ctrl+c?
The first letter in the :map commands determines which modes (:h map-modes) they apply to. So :nnoremap is for normal mode, and :inoremap for insert mode.
You usually cant' just use the same right-hand side; you need to consider that you're in a different mode. To invoke a (normal mode) command from insert mode:
prepend <Esc> if you want to stay in normal mode after the mapping
prepend <C-o> if you want to continue in insert mode after the mapping; this command switches to normal mode for just one command
For example, to map :w to <C-s>, you'd use this: :nnoremap <C-s> :w<CR>. The corresponding insert mode mapping (staying there) is:
:inoremap <C-s> <C-o>:w<CR
See :help imap. You can map keys, including keys with control, to various things within insert mode. For instance, if you wanted to copy the current word in insert mode with Ctrl+c you could use
inoremap <C-c> <esc>yiwea
I want to map the Home button so vim goes to the first non blank character in vim. But mapping the home button doesn't do anything? If I map another key, then it works correctly.
See below my vimrc file:
map <Home> 0w
imap <Home> <ESC>0wi
The above doesn't work. While the following works (Ctrl-F for example)
map <C-f> 0w
imap <C-f> <ESC>0wi
Isn't there a way to map Home key to this? I really need it, because I got used to this when working with Notepad++, Sublime text 2, Visual Studio,...
I also tried the following, with no results. When using another key, it works again...
http://vim.wikia.com/wiki/Smart_home
From Vim FAQ (also available through this nice plugin):
20.4. I am not able to create a mapping for the <xxx> key. What is wrong?
1) First make sure, the key is passed correctly to Vim. To determine if
this is the case, put Vim in Insert mode and then hit Ctrl-V (or
Ctrl-Q if your Ctrl-V is remapped to the paste operation (e.g. on
Windows if you are using the mswin.vim script file) followed by your
key.
If nothing appears in the buffer (and assuming that you have
'showcmd' on, ^V remains displayed near the bottom right of the Vim
screen), then Vim doesn't get your key correctly and there is nothing
to be done, other than selecting a different key for your mapping or
using GVim, which should recognise the key correctly.
This way you can check if the home key you are pressing is the same that Vim understand as <Home>.
Another possibility is that some other mapping is interfering with this one. You could try the following:
noremap <Home> 0w
inoremap <Home> <ESC>0wi
Edit:
It seems the problem is that your terminal is sending a home keycode that Vim isn't recognizing as <Home>.
I believe that the best solution is make Vim recognize that key correctly, so you can move your .vimrc to other terminals/systems without changes.
From :h xterm-end-home-keys:
On some systems (at least on FreeBSD with XFree86 3.1.2) the codes that the
<End> and <Home> keys send contain a <Nul> character. To make these keys send
the proper key code, add these lines to your ~/.Xdefaults file:
*VT100.Translations: #override \n\
<Key>Home: string("0x1b") string("[7~") \n\
<Key>End: string("0x1b") string("[8~")
If that doesn't work, you could try :set t_kh=^V^[[1~. If it work you can enclose it on a check of your terminal type.
Additional information can be found at :h terminal options
Edit 2:
20.4. I am not able to create a mapping for the <xxx> key. What is wrong?
:
:
3) If the key is seen, but not as itself and not as some recognizable
key, then there is probably an error in the terminal library for the
current terminal (termcap or terminfo database). In that case >
:set term?
will tell you which termcap or terminfo Vim is using. You can try to
tell vim, what termcode to use in that terminal, by adding the
following to your vimrc: >
if &term == <termname>
set <C-Right>=<keycode>
endif
where <termname> above should be replaced by the value of 'term'
(with quotes around it) and <keycode> by what you get when hitting
Ctrl-V followed by Ctrl-Right in Insert mode (with nothing around
it). <C-Right> should be left as-is (9 characters). Don't forget that
in a :set command, white space is not allowed between the equal sign
and the value, and any space, double quote, vertical bar or backslash
present as part of the value must be backslash-escaped.
Now you should be able to see the keycode corresponding to the key
and you can create a mapping for the key using the following command: >
:map <C-Right> <your_command_to_be_mapped>
For more information, read
:h map-keys-fails
:h map-special-keys
:h key-codes
I am trying to map my space key to make the Vim go into insert mode from normal mode.
The reason I want to do this is because sometimes I forget that I'm in normal mode and start typing as if I'm in insert mode. When I press the space key in between or even in the start of the page, it moves down and something or the other types due to the possibility of a press a or i in what I just typed.
So to avoid this I want to map my space key to insert mode from normal mode as we press i to do so.
I tried the following:
map space :i
map <space> :i
But these doesnt seem to work.
You're mixing up the modes in your mappings; that's an important concept in Vim. Though there's a :startinsert Ex command in Vim (where your mapping would indeed start with a :), it's more straightforward to use the normal mode i command:
:nnoremap <Space> i
You only want a normal mode mapping here, so :nmap, not :map; cp. :help map-modes. And see :help key-notation for why it's written <Space>.
Finally: You should always use :noremap; it makes the mapping immune to remapping and recursion.
strange requirement, but, you have your reason. :)
try this line out:
nnoremap <space> i
Is there a default key for scrolling in insert mode? I know that I could just
:imap <F5> <ESC><C-e>a
:imap <F6> <ESC><C-y>a
but I'm wondering if there's any key binding there by default.
For completeness, there are two dedicated commands for scrolling in insert mode, CTRLXCTRLE and CTRLXCTRLY. They are probably the proper ones to map.
See the documentation here: :h i_CTRL-X_CTRL-E.
In normal mode CTRLE and CTRLY do the same thing, I use them quite often.
In insert mode, type Ctrl-o, then type zz.
It'll set current line in the middle of the screen.
Actually, you can type any command.