I would like to swap my left shift key with my left alt key, and I would like to know if it’s possible to achieve this with vim key mapping.
Maybe not swapping but copy the whole shift key map to alt?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
In vim, nvi, vi, and so forth (all of the terminal vi clones, to be precise), no. A terminal session doesn't transmit the modifier key presses separate from the keys they're modifying. It's true that terminal emulators have come a long way since when they were first made, and they have a lot more capabilities now. But that's something that's pretty fundamental to the data flow on how old terminals worked, and I don't see it as something that would be possible to change without breaking compatibility with all sorts of things they're supposed to be compatible with.
I've checked to see if there's a gvim capability to do this. As of 8.2, based on my reading of
:help :map, especially the section
:help :map-alt-keys, there does not appear to be. gvim does recognize the modifier keys itself, but it appears to fundamentally not make a distinction between the left or right modifier key of any set that has a pair, and it fundamentally doesn't recognize the modifier key presses except when there's also a non-modifier key pressed.
The only things that would stop you from doing a full list of
:noremap <A-A> <A-a> :noremap <A-a> <A-A> :norelmap <A-A> <A-a> :norelmap <A-a> <A-A> :noremap <A-B> <A-b> :noremap <A-b> <A-B> :norelmap <A-B> <A-b> :norelmap <A-b> <A-B> ...
would be your patience with going through all of them and the confusion factor from the amount that you've already gotten used to them being the thing they are by default. I don't know of a way to get a listing of all of the keycodes that actually do something, so there's no way I know of to be thorough for all the keys that matter but not bother with the ones that don't.
Of course, simply mapping the shifted alt keys to the unshifted alt keys would cause you to lose access to the shifted alt keys' functions, unless you mapped something else to get there.
Note that I'm using the
:noremap command there because a simple
:map both directions like that would result in an infinite loop. I'm using both
:norelmap because you didn't indicate what contexts you want the remap to happen, and that's the simplest way to get virtually all contexts.
There's a table of map commands at
:help map-modes, which was very confusing to me when I first started using vim, but it should be helpful to you here. My confusion was because the three columns of commands aren't marked. The first column is recursive mappings (that is, after the key press is translated, the new code gets looked up to see if it gets mapped in some way, too), the second column is non-recursive mappings (what I naturally expected from map commands), and the third is how to undo either type of mapping.
That having been said, if you have access to your OS keyboard layout, you can do that sort of change. The simplest way would make that change for everything on the system. The details of how to do that would probably be under either an OS specific SE, or Super User SE.
Is this close to what you want?
let s:str='abcdefghijklmnopqrstuvwxyz' for i in range(len(s:str)) let s:c=s:str[i] exe 'map <A-'.s:c.'> <S-'.s:c.'>' exe 'lmap <A-'.s:c.'> <S-'.s:c.'>' exe 'tmap <A-'.s:c.'> <S-'.s:c.'>' endfor
s: specify the scope of the variables (see
:help s:) and command
exe executes the string following it.
. concatenates strings together. For example, if
i is 3, then
map <A-d> <S-d> will be executed.