Show all leader mappings - vim

I have a some command set up in my .vimrc for mapping ,r.
But when I press ,r, vim does not trigger a command immediately but waits a while so I can type more characters. That means I have something set up for longer mapping, e.g. ,re or ,rt.
I don't use any mapping like that, nor see any <leader>rX mappings in my .vimrc. Looks like some plugin is setting it.
Is there a way to show all leader mappings to figure out what mapping is that?

Try with :map command. It shows all current mappings including those created with <leader>.

On my system (vim 7.3 on OS X)
:map ,r
shows all mappings starting with ,r

The output of :map can be a bit too long. Refining the question gives better results:
:verbose map <leader> " all mapping in all modes that use <leader>,
" and where they are defined
:verbose map <buffer> " all mappings defined for the current buffer,
" and where they are defined
:verbose nmap <leader> " all normal mode mappings that use <leader>,
" and where they are defined
More info:
:h :map

Related

vim: Tagbar windows opened when typing <Enter> in normal mode

When typing <Enter> in normal mode in Vim with the Tagbar plugin installed, the Tagbar window is opened automatically. I want to disable this functionality. What must I do?
put the flowing code in you .vimrc
unmap <cr>
Your mapping for <C-m> is actually the cause of the Enter key opening Tagbar. If you remove that map from your vimrc, the enter key will no longer trigger :TagbarToggle.
Mappings for <C-m> and <CR> (Enter) are synonymous in Vim:
The following table shows the mapping between some of the keys on the keyboard and the equivalent Ctrl-key combination:
Ctrl-I Tab
Ctrl-[ Esc
Ctrl-M Enter
Ctrl-H Backspace
If you use one of the Ctrl-key combination in the above table in a map, the map also applies to the corresponding key. Both the keys produce the same key scan code. For example, if you create a map for CTRL-I, then you can invoke the map by pressing Ctrl-I or the Tab key.
This means when you set nmap <C-m> :TagbarToggle<CR>, it is the same as
also setting nmap <CR> :TagbarToggle<CR>.
You'll probably want to choose a new key instead of M. The alternative is to
change the key code sent by <C-m> at the operating system level with some
remapping program.
The terminal key bindings come from readline, the program that processes input text in
your terminal prompt. A full list of key bindings is in the readline
manual.
You can find more info about Vim key codes by typing :help keycodes in Vim, or reading the help docs here.
Try :help tagbar to open the documentation. It sounds like you might have a mapping in your vimrc file that says something like
nnoremap <silent> <CR> :TagbarToggle<CR>
or
nnoremap <silent> <CR> :TagbarOpen<CR>
if you find and remove that mapping will no longer open Tagbar

Map <space> to <leader> in VIM

I want to map the <space> key to <leader> (which is currently the \ key here) in VIM 7.4.
I would also like to be able to use both the <space> and \ keys as leaders.
If possible, it would be great to see the / character appearing in the bottom right corner when I type it (instead of funky stuff like <20>), but I can live without it.
I've tried to
nmap <space> <bslash>
this works for simple <leader>keys commands, but <leader><leader>key commands (like the easymotion maps) don't work.
I also tried to
let mapleader = " "
nmap <bslash> <space>
but analogously to the problem above stated, the <bslash> key doesn't work anymore for <leader><leader>key commands.
I already tried a bunch of stuff in these related questions/wiki pages:
Can I use SPACE as mapleader in VIM?
http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-Tutorial(Part_2)
:h mapleader
I can't see your .vimrc, so I can't guarantee this is the issue, but I would bet that the issue comes from using nnoremap. The following works for me:
let mapleader =" "
nmap <leader>i iHello World<esc>
nmap <bslash> <space>
I can use either <space>i or <bslash>i and both of them run the iHello World<esc> mapping. But this:
let mapleader =" "
nnoremap <leader>i iHello World<esc>
nnoremap <bslash> <space>
Does not work. <space>i runs the mapping, but <bslash>i does not, which is exactly what should be expected, since nnoremap is used to avoid nested/recursive mappings. So one possible solution would be to use nmap everywhere. I would definitely not recommend this, since you'll likely end up in a map loop. This solution should work better:
let mapleader =" "
nnoremap <leader>i iHello World<esc>
nmap <expr> <bslash> mapleader
Note that if you change the mapleader setting, this will break because, as :h mapleader says:
Note that the value of "mapleader" is used at the moment the mapping is
defined. Changing "mapleader" after that has no effect for already defined
mappings.

What the D-S-Up means in vim?

I find a .vimrc file config:
" Move selection up/down (add =gv to reindent after move)
:vmap <D-S-Up> :m-2<CR>gv
:vmap <D-S-Down> :m'>+<CR>gv
I know the D-S-Up must be a key, but what is the key?
I type:
:help D-S-Up
nothing happened
:help key-notation tells you the meaning of all those <key> notations.
You can't expect :help D-S-Up to do anything because:
it doesn't follow established patterns like i_ctrl-r,
it is a custom mapping and Vim only provides documentation for its own commands.
<D> is the Cmd key on Mac keyboards, <S> is the Shift key, and <Up> is the Up arrow key.
So <D-S-Up> means Cmd + Shift + Up.
The Cmd key only works in the MacVim GUI.
Non-portable mappings are worthless.
One should use :xmap or :xnoremap for visual mode mappings, not :v*.
Non-recursive mappings should be used by default unless one really wants recursion.
Using someone else's vimrc is a bad idea.
By the way, here are enhanced versions of those mappings:
nnoremap <silent> <D-S-Up> :<C-u>move-2<CR>==
nnoremap <silent> <D-S-Down> :<C-u>move+<CR>==
xnoremap <silent> <D-S-Up> :move-2<CR>gv=gv
xnoremap <silent> <D-S-Down> :move'>+<CR>gv=gv
where:
<silent> prevents the commands in the mapping from echoing useless info,
<C-u> removes any default range inserted by Vim,
move-2<CR> is a more readable version of m-2<CR>,
== re-indents the line,
gv=gv reselects the lines, re-indents them, and re-selects them again.
Have a look at Move entire line up and down in Vim
In an answer you can read (concerning the line :vmap <D-S-Up> :m-2<CR>gv):
According to the shortcuts above, pressing Cmd-Shift-Up/Down will shift the block selection up/down. "D" is the Command key in MacVim, for Windows try "C" (Control), or "A" (Alt) (eg. would be Control Alt f).
Since I don't have a Mac myself, I can't check, but it's most certainly true.

Vim key map not registering

I am trying to map Alt-r in Vim to save then execute the current file, and Alt-R to save then execute, but allow for extra parameters to be passed to the script.
In my vimrc I have the following (key mappings at the end of the file):
" Basic setup
set modeline
syntax on
filetype plugin indent on
" Load pathoen
execute pathogen#infect()
" Solarized colourscheme
if has('gui_running')
set background=light
else
set background=dark
endif
colorscheme solarized
" Map Alt-r to run current file as if it were a script
nmap <M-r> :w<CR>:!./%<CR>
nmap <M-R> :w<CR>:!./%<Space>
" Allow Alt-<CursorKey> to move around windows
nmap <M-Up> :wincmd k<CR>
nmap <M-Down> :wincmd j<CR>
nmap <M-Left> :wincmd h<CR>
nmap <M-Right> :wincmd l<CR>
The key mappings for window movement work fine, but Alt-r doesn't seem to do anything while Alt-R puts Vim into replace mode. I checked with :help M^r and :help M^R but they didn't list any mappings, nor does :map list those keys as taken. I have also already disabled Alt key mappings in the Gnome terminal.
Any suggestions??
This could be a problem with your terminal emulator which may encode the alt key different from what vim expects.
Ctrl+v causes vim (and most shells) to output the next character or key combination verbatim (literally). This way, you can insert the keycode produced when you press Alt+r directly into your configuration file by adding
set <M-r>=^[r
set <M-R>=^[R
where the escaped characters like ^[x have to be entered by pressing Ctrl+v and then Alt+x and may produce a different result on different terminal emulators.
Notice that there are no spaces around the equal signs. Vim would interpret additional spaces as part of the assignment which would make the directive misbehave.

Mapping a sequence of keystrokes to command-line commands

Is there a way to map a sequence of keystrokes to a command-line commmand (a command entered after : in the Ex mode) in vim?
Yes, and it's intuitively called :map
Example:
:map foo :echo "bar"<CR>
No when in insert mode you press the keys foo vim will respond with "bar".
Type :help :map in vim for more information.
You can place mappings you want to load by default in your .vimrc file.
You can independently map keystrokes for different modes, such as insert mode (:imap) and visual mode (:vmap). See also vim help on the subject of remapping (:noremap)
Update
If you want to use an alias for command mode (but this can be done for insert mode too), you'll want to use abbreviations.
To define an abbreviation for command mode, use :ca (which is a shorthand for :cabbrev). See vim help :help :ca and for more info :help :abbreviations.
Notice that unlike map, abbreviations are not replaced by vim commands but by literal characters. Abbreviations are triggered when you press space or enter.
Examples:
" let me type :syn=cpp instead of :set syntax=cpp
"
:ca syn set syntax
" fix my favorite spelling error
"
:abbr teh the
" this does something different than the :map example above
"
:iabb foo :echo "bar"<CR>
" this is ugly, misusing an abbreviation as :map by simulating ESCAPE press
"
:iabb hello <ESC>:echo "world"<CR>

Resources