[英]How to use a loop in Vim to define multiple mappings
在Vim中有一种方法可以用循环定义多个映射吗?
例如,这是在没有循环的情况下定义它的方式。
nnoremap<leader>1 1gt
nnoremap<leader>2 2gt
nnoremap<leader>3 3gt
但我想用循环来做这样的事情。
for i in [1, 2, 3]
nnoremap<leader>${i} ${i}gt
endfor
有没有办法做某种插值?
是的, :execute
命令:
:exe[cute] {expr1} .. Executes the string that results from the evaluation
of {expr1} as an Ex command.
所以你的榜样就是
for i in [1, 2, 3]
execute 'nnoremap <leader>'.i.' '.i.'gt'
endfor
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.