How to map two consecutive Shift in Vim? - vim

Total vim newbie here, is there a way to map two consecutive <Shift> to execute :FZF? I try the following config in .vimrc but no luck
nmap <S><S> :FZF<Enter>

Unfortunately you can't atleast not without some serious hacking. To quote from the vim wiki
Note that you cannot map the Shift or Alt or Ctrl keys alone as they
are key modifiers. You have to combine these key modifiers with other
keys to create a map.
http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-Tutorial(Part_2)
Also i'd recommend you use nnoremap rather than plain nmap, unless you explicitly want your map to be recursive.
On a personal note i use the following mapping for :FZF which is basically a space followed by a 'f' in normal mode. I find it quite nice.
nnoremap <Leader>f :FZF
Happy Vimming.

Related

Can some share how to write vim map

new to vim, recently came across mapping keyboards issues, what get on google and stackoverflow is only something like this map <C-\> :tab split<CR>:exec("tag ".expand("<cword>"))<CR> and map <A-]> :vsp <CR>:exec("tag ".expand("<cword>"))<CR>, then I searched Vim documentation: map http://vimdoc.sourceforge.net/htmldoc/intro.html#<>, but what it also does not explains the syntax, the meanning of the symbols, can someone suggest some reference materials for this? Thanks very much!
A mapping like the ones you mentioned has three parts:
the type of mapping (map/nmap/imap/vmap/... and the corresponding noremap versions). This determines in what modes the mapping is active. map means normal mode, visual mode and operator-pending mode. When using noremap/nnoremap/... the mapping is made with respect to Vims standard keybindings, otherwise the mappings can themselves call mappings.
The key(s) to bind. This can be a normal key, a control character like <C-\>, or a sequence of keys.
a key sequence to map to.
In your first case, you map the key <C-\> (control-backspace) to :tab split<CR>:exec("tag ".expand("<cword>"))<CR> in normal, visual, and operator-pending mode.

in Vim key mapping, is there a way to repeat a key for multiple times?

I want to add quick key macro in vim for fast editing. Something like
imap <buffer> <A-S-p> printf("\n");<Left><Left><Left><Left><Left>
My question is, is there a multiply operand in key mapping? Something like
imap <buffer> <A-S-p> printf("\n");<Left>x5
Every key in :help key-notation needs to be specified on its own. Most movement commands (like h) take a (prepended, optional) [count], but not <Left>.
If you're looking for a way to type the mapping faster, stop inserting after the ;, and then append the following multiple times: 5a<Left>Esc.

VIM, mapping, Why doesnt nmap <Alt><Right> <C-w><Right> work?

How can i use ALT key in key mapping?
And how can i make double key commands? for example i tried
<Alt-Right> <C-w><Right>
and it didnt work either.
And as far as i know, some keys are bad to be used for mapping in VIM, Space key for example. if possible, write also please keys which usually do not work in key mapping in Vim.
This should work in a graphical Vim (GVim, MacVim):
nnoremap <M-Right> <C-w><Right>
"Alt" is a new invention, which Vim doesn't know - it knows about "Meta", a key that once existed, and keeps calling the newfangled invention by the old key's name.
However, terminal is trickier, as Alt-Right is typically bound to some key sequence that is useful in Terminal, like Escf (move one word right); you can see what it is in Vim by preceding it by Ctrl-V: nnoremapCtrl-VAlt-Right<C-w><Right>, which will probably come out as
nnoremap ^[f <C-w><Right>

Two key maps conflict in vim, need to know why

from cscope i got this nmap:
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
and i had these maps originally:
nmap <tab> v>
nmap <s-tab> v<
vmap <tab> >gv
vmap <s-tab> <gv
Now if i type s, then it will jump to the definition with one side effect:
it will tab the target line or target function/class content.
I can't find out where is this conflict. It seems that these two maps have no relationship.
I have tried out your mappings w/o any issue, so I assume there might be some kind of trailing charter issue like #glts suggested in his comment. Use :set list to show invisible characters.
However there are somethings you may want to consider:
Unless you are mapping to a plugin or a very special need you should almost always use nnoremap over nmap to prevent recursive mappings.
The vim way to indent/unindent is to use >> / << (or > / < in visual mode). If you want to repeat the command then use .. The dot command will redo the last change. You can use u to undo if you have gone to far. Although I understand the want for mappings such as these, learning and making a habit to use . will help you in your journey to vim nirvana.
Example of nice usage of the . command by showing off quick and dirty substitution.
Search for a common pattern in you file /pat
Change text to something else via c. e.g. cgnfoo<esc>
The gn motion will select the current pattern
repeat with . command.
For more help see:
:h mapping
:h .
:h u
:h >>

Combine two vim commands into one

I'm having trouble combining two vim commands, specifically <C-w>s and <leader>x into <leader>r (i.e. split window and open spec counterpart of current file). Any help?
Thanks!
It would help if you'd post what exactly you've tried that didn't work. Generally, doing what you describe should be simple. It should be enough to put this in your .vimrc file:
nmap <leader>r <c-w>s<leader>x
This maps <leader>r to expand to the key sequence <c-w>s<leader>x. Note that these are not "commands", as you call them in your question, they're "mappings". A "command" is something completely different in vim, you can read up on that with :help user-commands.
One thing to be careful of is using nmap instead of nnoremap. The command nmap maps the sequence on the left to the sequence on the right while re-using mappings that have already been defined. On the other hand, nnoremap creates a mapping with the original meanings of the keys, so in your case won't work (since <leader>x is defined by some plugin). This is one possible reason you may have failed while trying to do it, but I can't tell from your question.

Resources