Key repeats and ranges in Vim mappings
Question
I want to define a mapping in my .gvimrc such that if the last key pressed is held, the triggered action is repeated. Specifically, I want to do something like
map <SPACE>t :set transparency-=1
map <SPACE>T :set transparency+=1
for MacVim, but I want the transparency to continue to be decreased/increased when t/T are held (don't want to have to keep pressing the spacebar).
If you have a suggestion for a nicer way to adjust the transparency, I would appreciate that also.
Separately, it would be nice to be able be able to type 20 SPACE t and have the transparency decreased by 20; however, when I try I get an
E481: No range allowed.
How do I enable range specification?
Thanks a lot.
Solution
I am not sure about the first part of your question, but to get 20 <Space>
t to be able to do its job:
:map <space>t :<C-U>exe "set transparency-=".v:count1<CR>
- With
<C-U>
you remove the line range that is added to your ex command when you type 20 in Normal mode. - With
exe
you execute 'dynamic' vimscript. v:count1
is the count given for the last Normal mode command (20 in this example). And if there is no count given it defaults to 1.
For additional information see
:h v:count
:h v:count1
Update:
You can omit exe
using let
form instead of set
one:
:map <space>t :<C-U>let &transparency-=v:count1<CR>
See :h :let-&
.