After seeing how doom-Emacs use their leader key for almost everything I wanted to implement something similar to my vimrc.
Specifically the " ws" as a s-split is much more comfortable then the default keybinding "ctrl-w s"
Is it possible to map "ctrl" to my leader key (which is " " space)?
Vim won't let you map the Control key individually.
Instead, you can make custom mappings:
nnoremap <leader>ws <C-w>s
nnoremap <leader>wv <C-w>v
etc.
Related
The vim documention on how to set the default leader key ( :h mapleader) provides one simple example:
:let mapleader = ","
I want to map it to backspace and tried a bunch of options, this being the first one:
:let mapleader="<BS>"
But nothing seemed to work.
To make it work I had to use:
:let mapleader="\<BS>"
Another option is to not override the default \ leader key, but map backspace to it, effectively ending up with two simultaneous leader keys:
map <BS> <Leader>
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.
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.
I'd like to have a left and right hand leader key. If I want both the default \ and , to be my leaders I thought it would be as simple as adding nnoremap , \ or nnoremap , <leader> to my .vimrc. But apparently not. How do I do this?
My <leader> is bound to , and this works for me:
:nmap \ ,
All of my leader mappings are now available using either \ or , as the leader. I think it's the nnoremap that's tripping you up.
You can map one leader key to the other, as in the accepted answer, but if you're going to use <leader> in the first place, you should make the binding to <leader> itself. That way the binding will still work if you change (or remove) the first leader key.
map , <leader>
Note that this still doesn't quite work like a second leader. If the first leader is unset, the binding will still work, but Vim will also revert to using \ as a leader, since there is no longer an "official" leader (ie. valid value for the mapleader variable). (This wouldn't be a problem for the OP, but may be for others.)
<leader> is convenient but you can create mappings like ,mm or \mm without using it. Just duplicate all your <leader>something and remap them with ' and \ directly:
nnoremap <leader>d "_d
would become
nnoremap ,d "_d
nnoremap \d "_d
How exactly would that work? Vim, when it encounters <leader> it replaces it with the mapped key. Were you to use two (keys for <leader>), how would it know which one to replace <leader> with?
What you can do however, is use <leader> and <localleader> but that's just two separate leaders, not mapping two keys to one of them.
So, no ... you can't.
You can map your shortcuts explicitly though.
I am a new user in Vim. How change these keys in Zen Coding,
ctr+y+,
To
ctr+e
And also change in omni,
ctr+x ctr+o
To
ctr+j
How can I do that?
I suggest you to type:
:help map.txt
inside vim, you'll find all the explanation to understand how to do it.
You can't use the same shortcut for 'zencoding' plugin and for an omnicomplete function; anyway you could add to your .vimrc:
imap <C-j> <C-y>
But I suggest not to use 'C-j' as 'j' is always related to movement in vim; use 'leader' (:help leader) which is targeted to user shortcuts, instead.
You may follow the answer provided by #eolo999, but I suggest you to read zencoding documentation and add the following to the vimrc:
" Note the `nore'. You must use it where possible "
" in order not to get remapping problems when your vimrc grows up "
inoremap <C-j> <C-x><C-o>
" from :h zencoding-customize-keymappings "
let g:user_zen_expandabbr_key='<C-e>'