vim simple mapping of shift key - vim

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 :-).

Related

Insert mode default keys in vim

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$

vimrc key mapping not working after the Esc key

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.

Vim: Geting out of insert mode. When I map alt-key combinations in insert mode, the character associated gets mapped, not the alt-key-combination

Background: I use alt-h j k l etc. to get out of insert mode.
The reason to do such a thing is explained
here.
In my XTerm this worked by default, but in gvim it doesn't.
I guess you can see the life-threatening gravity of this problem to me, as finding a good solution to get out of insert mode is absolutely essential to flow -- and I thought I found it for me... (edited my Formulation in response to Amandan...).
Is there a was to have gedit behave in a "alt sends escape"-kind of way?
There might be other solutions, but they seem pretty ugly:
My strategy for now was that I tried mappings (w,e,d,c,r,A and whatever) so that for instance alt-dw in insert mode would get me to normal mode and delete the word after the cursor by simple mappings like:
inoremap <m-d> <Esc>ld
inoremap <m-x> <Esc>lx
inoremap <m-X> <Esc>lX
inoremap <m-u> <Esc>u
inoremap <m-p> <Esc>p
(the l before the command corrects the placement of the cursor)
This works very well, but these mappings do not map the alt-key-combinations, but the caracters associated (in utf-8-encoding).
In the above exemple:
ä, ø, Ø, õ, ð
The problem is, that when I tap ä for exemple (I'm german, so it's right on my keyboard AND I NEED IT BADLY), vim will get out of insert mode and start a "delete"-operation. Meaning that I loose every possibility to enter an ä (or é, ê, ö, etc. all of wich are vital to me).
Is there a way to map alt-key-combinations and not the caracter associated? (This question is secondary. It's only interesting inasmuch it serves the primary one: use alt-stuff to get out of insert mode)
Other stuff that I tried or checked:
-- I did
set termencoding=ascii
but it didn't have any effect (in gvim-gui - when I run it in a terminal, it has an effect, but it's not there that I need it).
-- My enoding options are set way before my mappings so it is not a parsing problem.
-- I tried
unmap <M-J>
inoremap <M-J> <Nop>
No effect.

How can I map Ctrl + semicolon to add a semicolon to the end of the line?

I'm trying to map pressing [ctrl] + [semicolon] in insert mode to move to the end of the line and add a semicolon. It's something I find myself doing a lot after installing the surround plugin.
I tried running this command
inoremap <c-;> <esc>A;<esc>
but when I try it, it exits me out of insert mode, and goes into command mode. Trying with another modifier d yields the same result too.
Can semicolon not be mapped with a modifier?
What am I doing wrong?
I didn't read your question carefully, just saw your mapping took you out of the insert mode and the last <esc>... my fault.
You want to map ctrl+; vim cannot capture the keycode. there are some key combination cannot be mapped in vim. ; is one of them, another example like ctrl+=.
so you may want to choose another mapping.
btw, you can try in insert mode press ctrl-v then the keycombination to see if it could be used.
Depending on your terminal it is possible to set up mappings. For example if you use urxvt, in ~/.Xresources add:
URxvt.keysym.C-semicolon: \033[;
And in ~/.vimrc add:
map <Esc>[; <C-Semicolon>
map! <Esc>[; <C-Semicolon>
Then you should be able to map it like this (not tested):
inoremap <c-Semicolon> <Esc>A;<Esc>
I use this to map split window movement like this (this works for me):
noremap <C-Semicolon> <C-w>l

Is it possible to map <C-;> to : in vim?

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...

Resources