How to find what vim default key binds does? - vim

Apparently <c-space> doing something by default in vim but I can't figure out a way to check what it's doing.
:imap <c-space>
> No mapping found
:h <c-space>
> Sorry, no help for <c-space>

It's a little hard to give a fully generic answer here and sometimes your specific platform or terminal emulator might have an effect on how specific keys are seen by Vim.
One way to try to figure out which key code is seen by Vim is to go into Insert mode and then press Ctrl+V followed by your specific key. (See :help i_CTRL-V, which will tell you Vim will insert the next symbol literally.)
In my case, typing Ctrl+V followed by Ctrl+Space in Insert mode shows me ^#, which symbolizes the Ctrl+# sequence, which shows me that's how Vim is seeing this key sequence.
(I believe this is mostly universal, and Ctrl+Space will always generate Ctrl+# everywhere, but as I mentioned there are platform differences, so I can't guarantee it works that way everywhere, but you should be able to use the same Ctrl+V trick to find out if it's the same or not in your case.)
Following that finding, you can then look at :help i_CTRL-# to see that the Ctrl+# sequence (which should be equivalent to Ctrl+Space) will "insert previously inserted text and stop insert."

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$

Vim backslash in command

I feel like this is a very stupid question, but I can't seem to find the answer to this anywhere. I'm relatively new to vim. After a fresh install I installed the vim-LaTeX plugin, or the LaTeX-suite for vim. It works correctly apart for the fact that there are some commands I don't understand. It gives the following instruction:
To do this, visually select a portion of the text and press \ll while in visual mode. The visually selected portion will be saved to a temporary file with the preamble from the current document prepended. Latex-Suite will then switch focus to this temporary file and compile it
But if I press '\' it does nothing and double l moves the cursor to the right. I don't understand what I'm supposed to be doing, and I feel incredibly stupid. Sorry if off-topic.
The \ is the default value for the :help <Leader> key. Plugins are encouraged to start all default mappings with <Leader>. If you've redefined it, you need to use that key instead.
Otherwise, you need to press V \ L L (without Shift) in quick succession (by default within one second).
If you want to find out whether the plugin has been successfully installed and there's actually an action behind those keys, you can use either:
:verbose vmap <Leader>ll
:verbose vmap \ll
If Vim says No mapping found, or just lists other mappings starting with some of the keys, the plugin isn't installed properly, or you're not using it right.
Press v to go into visual mode. Then you can use your arrow keys to select text. After you've selected the text you want, type \ll.
That should be it.

How to map keys to a different key

I have just started learning VIM using gvim. When I am in the insert mode, and after I have copied stuff ,I usually use CTRL+R + Shift * key combination to paste the stuff in. I would like to map those keys to CTRL+V .
Can you please let me know what I should be doing in my vimrc to achieve my desired goal?
I am on a Windows OS.
Thanks
The key combination
:map < c-v > P
should set the paste shortcut to Ctrl+V.
There is a tutorial for creating VIM keymaps here.
You can also try the 3rd chapter of the free book "Learn Vimscript the Hard Way". It gives a very good example of mapping "dd" to "-". I would actually visit this link first and maybe afterwards take the tutorial above.
I have 0 Experience with vim on windows. But you can try inoremap <c-v> <c-r>*
And on my linux box, the insert mode Ctrl-v is very important, it can let me input next non-digit literally. It is very handy to input special keys. So if it is same to you, consider to use other keys.

map to XF86 keys in vimrc

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.

Vim key mapping with < and > symbols

I am trying to define a vim key map for putting the selected line inside an HTML p tag:
vnoremap <leader>bp c<p><cr></p><esc>P
It doesn't work, I think vim is interpreting <p> in a special way. How can I solve this?
It looks like you are using Vim in "compatible mode" which is something only hopelessly masochistic people do. In "nocompatible mode", your mapping works as expected so you should probably make sure nocompatible is set (creating a blank ~/.vimrc should be enough).
Anyway, your <p>s are not where the problem is because they are inserted normally, it's your <cr> and your <esc> that are causing a mess: since you are running Vim in "compatible mode", the cpoptions option includes < which causes Vim to not recognize <CR> and friends as special keys.
Running Vim in "nocompatible mode" is the best way to go but you can also use the following notation if you really insist on going "compatible":
vnoremap <leader>bp c<p>^M</p>^]P
where ^M is inserted with <C-v><CR> and ^] is inserted with <C-v><Esc>.
You may want to look into Tim Pope's Surround plugin. Then you can do S<p> and surround the visually selected text with <p> tags.
However the answer please see #romainl answer. I would also suggest you read up on key-notation via :h key-notation

Resources