vim keymap with ":" key - vim

How to change functionality of : key to / or comma
What is name of this functional key?
When i press <S-:> I would like to use this:
nmap <S-:> >>

I'm absolutely at a loss on what you are trying to achieve here, but you could just
:nnoremap , :
:nnoremap : ,
I included the reverse mapping, because, you know, : to start command-mode is kind of important to have working in vim.
Just in case you get stuck, ZZ is usually another way to close a window in vim (if the buffer is unmodified, usually)

Related

Change command line mode key ":"

I'd like to change the way to enter command line mode. In particular, I want to change the : key to ;, since : is just Shift + ; for me. I've tried, so far,
nnoremap ":" ";"
nnoremap "<S-;>" ";"
nnoremap : ;
but they've not worked.
Mappings are thoroughly documented under :help mapping, and introduced in the gentlest way possible in chapter 5 of the user manual: :help 05.4, the reading of which is pretty much mandatory if you ever hope to use Vim efficiently.
Case in point…
The left-hand side of a mapping is what you want to press and the right-hand side is what you want to happen instead, so all your attempts are in the wrong order.
Both sides of a mapping are the exact key you would press so ";" in a mapping is not ;, it is ", then ;, then ". If you wanted ;, you should have used ;. Besides, you are very unlikely to find even one resource on the web suggesting that notation.
You won't extract any value from Vim by trying random things and turning to the internet for help when you are lost. Vim must be learned to be used and there is no way around that.
See :help user-manual.
Looks like you got : and ; the wrong way around. nnoremap ; : does the trick for me.

Translucent Vim map for short manual about keys after it

In (Neo)Vim, I want to configure a key as if it passed through one-way mirror.
For example, in normal mode, when I type <Leader>, the command :echo "w: Separate Window f: Open File c: Configure Settings" run (so I can get help from at the bottom of the screen), but the <Leader> still has influence on following keys --- such as w, f, c, and so on --- and <Leader><KEY> works properly.
I mapped lots keys with <Leader>, so it will be very helpful for me to display a short manual about keys follow <Leader> at the bottom of the screen when I type <Leader>.
Thanks.
First, <leader> is not a special key at all. It's a placeholder expanded by Vim to the current value of mapleader whenever it is used. Assuming your mapleader is , (as instructed in :help mapleader), the mapping below:
nnoremap <leader>f :find *
will be registered as:
nnoremap ,f :find *
Second, when Vim detects that the key you just pressed is part of several custom or built-in commands it waits a bit for you to press more keys in order to decide what to do. With , as your mapleader, pressing , will always puzzle Vim because , is an actual command in its own right and you have a bunch of custom mappings starting with ,. In this situation, Vim waits for a full second before deciding you actually wanted , and not ,f.
Third, you would almost certainly need to write a completely separate mapping mechanism for achieving you idea. A mechanism that would:
listen to key presses,
trigger a specific function when you press <leader>,
that prints something helpful in the command-line,
and waits indefinitely for another key to be pressed.
This doesn't sound trivial at all. Did you take a look at the "scripts" section of http://www.vim.org?
Four, the whole point of a mapping is to map a common action to an easy to remember shortcut. You definitely have too many mappings if you can't remember all of them. Maybe it's time to reconsider the root issue instead of looking for a workaround?
You can do that with the following mapping:
:nnoremap <Leader> :echo "w: Separate Window f: Open File c: Configure Settings"<Bar>call feedkeys((exists('g:mapleader') ? g:mapleader : '\'), 't')<CR>
This uses feedkeys() to send the <Leader> again after the help has been shown. However, this solution has the key timeout downsides already mentioned by #romainl: The message will only appear after the 'timeoutlen' delay, and then you have to press the correct mapping key within 'timeoutlen'.
alternative
I would rather print the help on <Leader><Leader>. There are no timeout issues here. If you have pressed <Leader> and then fail to remember what's the next key, just press <Leader> again, read the help, and then start again with the (now memorized) full mapping!

Remapping ; and : in Vim breaks it

I've just discovered that some people tend to remap their : to ; in Vim (since ; is only used for search, and : is used all the time, not having to press Shift all the time is great).
EDIT (forgot to show what I did):
nnoremap ; :
nnoremap : ;
I tried it, and I love it. However, it does come with a price. It kind of breaks my configs, eg:
map <leader>G mG:Git!
Commands like the one seen above no longer work.
So my question is, to those who remap their semicolons, what is the remedy for this? Should I just remap : and ; on system level via xmodmap instead?
Decision:
Ultimately, I've decided to remap colon and semicolon at system level, for consistency purposes.
nnoremap <leader>G mG:Git!
allows you to use : in its original meaning.
(edit) Obligatory reference in LVHW.

remap or ignore spacebar in vi

Vim/vi shortcuts are awesome, but there is one behavior that I would be very happy if it could be configured. My machine uses Brazilian Portuguese(abnt2) keyboard map,and some accents(like caret) needs an extra spacebar to be print, obviously because they wait/expect another character, mostly vowels. Example of the "cut until you find an empty line":
d/^$
Keystrokes actually needed on br-abnt2:
d / <shift + ~ , spacebar>(to result ^) $ <enter>
I could use { d } as it is explained on this awesome thread, but i would benefit much more on other accents(backslash) where the extra backspace trick is needed, and most important, without change my keyboard mapping to "US" for example.
Edit: I also know that this is a keymap limitation, since our language expect something after the accent, and this is why i'm asking if there is a way to circunvent this limitation inside vim.
Any ideas?
The problem does not come from the editor, but your keymap. In fact, the caret is set to be a "dead key". Meaning that it should wait for other input before being printed.
What you probably need is a new keymap that has the caret as a non dead-key. As for example, uk-gb map has caret on the key as well as another dead-key ( if I remember correctly).
If you don't want/can't remap your keyboard, you can use vim mapping function do act so.
Just choose an unused key and map it like this:
imap g ^
This will insert ^ while typing g on insert mode (other mapping for other- mode exists, nmap, ...).
For example, to use the vim mapping in the vim command-line, you shall use :
cmap g ^
Then your example will be working.

map alt+shift+] in vim

I want to map Alt+Shift+] and Alt+Shift+[ to gt and gT (so it works like on Mac)
How do I do it because it doesn't seem to work if I simply do this:
map <A-S-]> gt
Somehow ] needs to be escaped or something
There is nothing wrong with your definition there. Vim will correctly map that combination but it doesn't do it in quite the way you expect. What that mapping essentially says is
When Shift + Alt is hit in addition to ]
On a standard keyboard the ] character when combined with Shift will produce }. This means that Vim won't ever see the ] in combination with Shift but instead sees just }. You can leverage this though to get the behavior you're looking for. Try the following mappings instead (assuming standard QWERTY keyboard)
:map <A-}> gt
:map <A-{> gT
When you want to remap keys in vim, it is often a good idea to go to insert mode, hit Ctrl+V, and then type the key you want to remap. In this case, I get an Escape character (Ctrl+[) followed by }.
I do like using the <A-}> notation, but you could have solved the problem by editing your .vimrc file, entering the map text, then hitting Ctrl+V and hitting Alt+Shift+] and then adding gt. You would end up with a line like
map ^[} gt
(but with an actual Escape character rather than a ^ and a [ as I had to type here) and it would work.
P.S. When I tried this, Alt+Shift+[ worked fine, but Alt+Shift+] seems to be already in use in my copy of vim. I'm not sure exactly what it does but remapping it isn't working for me. When I type
:map <A-}>
it prints No mapping found.

Resources