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.
Related
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.
all. I am trying to use youcompleteme for code completing in vim. Generally, it works well except that when i need to jump between source files.
First. I use the subcommand
:YcmCompleter GoToDefinition
it can find the definition. BUT it seems so verbose. Then I want to map this subcommand into some shortcut key according to the YCM's instruction:
nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>
nnoremap <leader>gf :YcmCompleter GoToDefinition<CR>
nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
I am a little confused. what is short cut key? l or gl ?
When you create a mapping with <leader>, <leader> is replaced by whatever is in your "mapleader" variable (by default \).
If you have this in your vimrc:
let mapleader=","
nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>
It acts the same as:
nnoremap ,gl :YcmCompleter GoToDeclaration<CR>
Thus you could run the YcmCompleter GoToDeclaration command by pressing ,gl
You can type \gl to go to the definition. The default <leader> is the key \. So if you type \gl, you can go to the definition.
And another shortcut you can try, Ctrl+o -> you can return back where you came from.
When I make a .vimrc entry,
nnoremap <silent> <leader>c :colorscheme <tab>
The tab is applied if I understand the terminalogy, as a literal, that is, upon typing ,c, I get in Vim command line,
:colorscheme ^I
I tried to internet the search terms, but mostly I get results about remapping Vim Tabs; the closest I found was somebody putting quotes around their <tab>, but I think that is for a different desired outcome.
I also have this, which is why I want the tab in my shortcut,
set wildmenu
set wildmode=longest:list,full
You'll need the 'wildcharm' option:
set wildcharm=<C-z>
nnoremap <silent> <leader>c :colorscheme <C-z>
See :help 'wildcharm'.
As a side note, I use that option with great effect for switching buffers:
nnoremap <leader>b :buffer <C-z><S-Tab>
and a file-opening variant would be just as easy and just as useful:
nnoremap <leader>e :edit <C-z><S-Tab>
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
I would like to map ctrl+leader key. Is it possible?
Tried: :nnoremap <c-leader> :CtrlP<CR>
And it does not work.
(ctrlp bindings conflict with yankring bindings)
<Leader> is a special key notation in Vim; as such, it cannot be combined with modifiers such as C-. Assuming the default setting for it (i.e. \), you can use this:
nnoremap <c-\> :CtrlP<CR>
There are two issues, here:
You didn't read CtrlP's documentation where you would have found this:
Use this option to change the mapping to invoke CtrlP in Normal mode:
let g:ctrlp_map = '<c-p>'
<leader> is supposed to be a cross-platform alternative to using the common modifier keys (Alt, Ctrl, Shift, Cmd) in mappings.
Normally, you would use <leader> in place of <Ctrl> as in:
nnoremap <leader>p :CtrlP<CR>
This line in your ~/.vimrc will probably solve your problem:
let g:crtlp_map='<F11>'
Though it won't help much here are my mappings for CtrlP:
nnoremap <leader>f :CtrlP<CR>
nnoremap <leader>b :CtrlPBuffer<CR>
nnoremap <leader>m :CtrlPMRUFiles<CR>
nnoremap <leader>t :CtrlPTag<CR>
For example to map leader key to space try this ...
let mapleader=" "