Is there any feature in Vim which shows me what a keyboard shortcut is bound to in the current context? Something like describe-key in emacs.
I'm trying to find out which keys i can safely rebind and which are bound to something useful.
If your key is manually mapped, you can check the mapping by evoking:
:map <keys>
if it is not, then you can check the manual:
:help <keys>
The first google hit says:
is there anything like "describe-key" (EMacs) in vim ?
The simplest might be the Vim help system. For example:
:h ^X
describes Ctrl-X. You have to type "^X" as two characters, not one.
To see how a key is mapped, you can use :map <whatever key sequence>, or just :map to see all non-default bindings. Mappings of keys may contain non-trivial sequences, so you might need to look up several other keys used in the mapping with :h as said above.
Related
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."
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 have just started using VIM. The one thing that stains me most while using VIM is the Esc key. So after some googling I found this link: Avoid the escape key and used it to map jk to Esc. I put this command in _vimrc file:
imap jk <Esc>
It's working fine. But now my question is if I need to type jk in vim, how should I do it. One way is to type something like jik then remove the i. But is there any better way of doing it?
If you don't want to wait for the timeout, an alternative is pressing Ctrl + V somewhere, i.e. either <C-V>jk or j<C-V>k. This key combination means "insert next char literally". (On Windows, you often need to use <C-Q> instead.)
Wait more than timeoutlen milliseconds (:help timeoutlen, :set timeoutlen?)
Do something else in the meantime (as you suggest)
Don't map key sequences that you're likely to type
jk is a common choice because no English words contain it. If your language does, don't use it, or change it to something you are not likely to bump into.
You can type Ctrl[. For me this is easier than reaching for the escape key.
See:
:h i_CTRL-[
In Vim I (of course) use keymappings to make my life easier, but when making a key mapping of my own I would really know if that key (or key combination) had some purpose before I potentially remap it.
So my question is: which keys/key combinations in Vim does not have a function? and is there by any chance a way to get Vim to list which?
You can generally use :help <key> to see if it's taken in normal mode and :help i_<key> to see if it's used in insert mode. Furthermore, you can use :map <key> to check if anything is mapped by your vimrc or plugins. This also works for imap, nmap, etc.
For example:
:help j
:help i_CTRL-N
:imap <Tab>
As far as a list goes, all of the capital and lowercase letters from A-Z have some meaning assigned to them. Most CTRL+<key> keys have meaning in all modes but some don't. The default <leader> key is \, but many people set that to ,; however, , has a special meaning in normal mode (opposite of ;). I suspect that most people map custom keys to <leader><key> or an <F#>. Often times keys that do have a default meaning aren't ones you actually desire, so looking up :help is a good practice since it not only increases your understanding of vim but also lets you make a judgment call on whether you need that functionality or not.
I've just installed the command-t plugin and what to map it to cmd-t instead of leader-t. I'm fairly new to vim and I don't know what the symbols are for the key mappings. Where can I find a reference for the symbols you use when mapping key combos in vim?
a vim principle is that an undocumented feature is a useless feature. So vim documentation is all you need.
:help :map
:help :map-special-keys
:help <> will give you info on the notation used with :map.
The authors of vim documentation don't always provide links everywhere they ought to (this may not really be practical). Often you end up having to read an entire help file, or at least the first few sections, to get the foundation for what is being explained in a particular entry.
In this case, I found a link to <> in the very first section of the file which contains the info for :help map-special-keys. That file is called map.txt; you can go directly to the top of it with :help map.txt. The documentation for <> is located in intro.txt, which may itself be worth a going-over.
Thanks to another SO post and answer, I found the following reference page:
:help key-notation
Here's an excerpt:
<S-...> shift-key *shift* *<S-*
<C-...> control-key *control* *ctrl* *<C-*
<M-...> alt-key or meta-key *meta* *alt* *<M-*
<A-...> same as <M-...> *<A-*
<D-...> command-key (Macintosh only) *<D-*
<t_xx> key with "xx" entry in termcap
D is the character you need to represent ⌘ in your .vimrc.
For example :
nnoremap <D-t> :MyFunction<CR>
maps ⌘t to MyFunction().
Replace MyFunction by the main function of your plugin and you are set.
Another way would be to look at the plugin's file and see if you can modify some hardcoded mappings.
Another thing to do — the first, I think — would be to consult the plugin's help and see if a "canonical" mapping method is indicated or if there is some variable to put in your .vimrc.