map <Alt>q <Esc>la
This line in my vimrc seems not working after the Esc key. It do exits the insert mode but doesn't enter insert mode again. I also tried
inoremap <Alt>q <Esc>la
map <Alt>q <Esc><Ctrl-A>
map <Alt>q <Esc><Ctrl>A
Basically I want to have something within the normal typing position to have the same effect as key. Say
(i>5[cursor])
->
(i>5)[cursor]
Solution:
I figured out the problem. Its cuz my terminal doesn't properly recognize alt as the alt, instead as a system level alt somehow. see
Alt key shortcuts not working on gnome terminal with Vim
As far as I can see there are two problems:
<Alt> isn't a thing. If you want to map Alt+q, that's <M-q>.
:map doesn't apply to insert mode.
You haven't explained what you're trying to do, so I can't tell you what to do instead.
Related
The following items are useful to me in editing text, and I was wondering if vim had something for this built out of the box (though I didn't see it on the https://vimhelp.org/index.txt.html#index.txt page), or I had to create mappings for it:
Forward-delete a character. This is X in normal mode.
Forward-delete all text to the right of the cursor on the line. This is the inverse of ctrl-u.
Are either of these mappings available? And if not, are there 'standard' mappings for this that are common (for example, how it might be done in another unix program).
Note that this is the keyboard I have -- there is only one delete key (which acts like a normal backspace key) and there is no backspace key:
Note: for forward-delete, I am currently mapping ctrl-d as:
"Ctrl-d to forward-delete when in insert or command mode
noremap! <C-d> <Delete>
However, this interferes with the tab in insert mode (which I don't use) and the help-options in command mode (which I do use!) so I may have to modify this later, or hopefully someone suggests a better solution.
though I didn't see it on the https://vimhelp.org/index.txt.html#index.txt page
If you can't find it in the documentation, then it doesn't exist.
You can use fn+delete for "Forward-delete a character".
"Forward-delete all text to the right of the cursor on the line" is ctrl+k in MacOS, but Vim has its own use for that combo, :help i_ctrl-k so it is up to you to create a mapping for it.
Something like:
inoremap <key> <C-o>ld$
I am trying to modify my vimrc in the following way:
map <S-Up> <C-U>
map <S-Down> <C-D>
map <S-.> G
in order to :
move the screen up by pressing Shift+Up
move the screen down by pressing Shift+Down
go to a specific line by typing the line number then Shift+. (instead of typing line number then G)
But none of those mappings work.
I've browsed google and SO to figure out what I'm doing wrong but no luck.
Anyone can give any pointer?
Instead of <S-.> (assuming an US-English keyboard layout that has . and > on the same key), you can just write >. Then, the mapping will work.
In the graphical GVIM, your <S-Up> will work as well. In the terminal, things are complicated. For me (gnome-terminal), pressing Shift + ↑ does not send anything to Vim (to check, press :<C-v>, then the keys, and observe what gets inserted literally). For (unshifted) <Up>, I get ^[OA, the expected keycode.
So, if this is mostly about the terminal, it may make sense to select different (more ordinary) keys (cursor keys are frowned upon by Vim users, anyway :-).
I have a chromebook that I've modified to run Arch Linux on. I have a 'search' key just under the tab key that I'd like to map as autocomplete when in insert mode. xev tells me the value of the key is XF86Search. However this doesn't seem to be working:
#.vimrc
inoremap <XF86Search> <c-n> mapmode-i$
How can I make this mapping with an XF86 key?
edit: In fact, using AutoComplPop from this answer proved to be a better solution, but Ingo pointed me in the right direction. This question on superuser discusses remapping keys for vim and/or terminal using xmodmap and that's the way I would have had to go.
In insert or command-line mode, try typing the search key (maybe preceded by <C-V> for literal input). If nothing happens / is inserted, you cannot use that key combination directly in Vim. You would have to remap it outside to some unused key (e.g. <F13>) that is supported by Vim. Else, just insert the key literally into your .vimrc mapping definition, without the special <...> key notation.
I want to use the following code to quickly go from insert mode -> command mode. The problem is it just doesnt seem to be registering my keys. I've tried with control (nothing happens) and i've also tried with command (D) and it just says spellcheck not activated.
" Quick command mode from insert
imap <C-;> <esc>:
How do i go about doing this? is there an easier vim way that I'm not aware of?
Certain Ctrl chords can't be mapped, including Ctrl-;.
This is mentioned in this FAQ, see also the Vim FAQ:
20.4. I am not able to create a mapping for the <xxx> key. What is wrong?
First make sure that the key is passed to Vim. In insert mode, press Ctrl-V
followed by the desired key. You should see the keycode corresponding to
the key. If you do see the keycode, then you can create a mapping for the
key using the following command:
:map <C-V><xxx> <your_command_to_be_mapped>
For more information, read
:help map-keys-fails
:help :map-special-keys
:help key-codes
The tip about trying to print the character using Ctrl-V is good to remember if you run into this problem with another key combo.
I tried it, however it doesn't seem to work, also as pb2q said, it just can't be mapped. But there are other ways to escape using a Ctrl key combination.
For example, you can also escape insert mode with the following key presses:
Ctrl-[
Ctrl-c
On OS X (I think Lion and above), you are able to map alt - ; using this method, alt - ; on OS X outputs ç, which you can map.
But at a MacBook, I prefer to use PCKeyboardHack to map caps lock to esc. Or at Windows, use a tool I've created myself for that or even Ctrl2Cap.
EDIT
oh sorry, I thought you wanted to switch to normal mode, that's why I talked about caps lock mappings.
I use capslock as control so it is more natural to use as : but noremap <C-;> : does not work. Is it possible to do such mapping in vim?
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.
Trying the above with <C-;> shows that it is not captured by vim/gvim...