[英]How to add a map leader mapping for visual linewise mode in vim?
I'm having some trouble making this mapping work: 我在使此映射工作时遇到了一些麻烦:
if exists(":Tabularize")
"rails routes file alignment in visual mode
vmap <Leader>ar :Tabularize /'[^']*'\|=>/l1l0<CR>
endif
When I source my vimrc and then: 当我获取vimrc时,然后:
\\ar
\\ar
I've tested the Tabularize command and it works. 我已经测试过Tabularize命令,它可以正常工作。 I now want to map it to a leader combination but it just doesn't work through the mapping.
现在,我想将其映射到领导者组合,但是它不能通过映射工作。 Only if I actually input the whole command in vim's CLI.
仅当我实际上在vim的CLI中输入了整个命令时。
Note: I've gone through a bunch of map leader questions but none had a solution to my particular issue. 注意:我经历了许多地图负责人问题,但没有一个解决我的特定问题的方法。
The issue is you need to use <bar>
instead of |
问题是您需要使用
<bar>
而不是|
in your mapping as |
在您的映射中
|
separates vim commands. 分隔vim命令。
xnoremap <leader>ar :Tabularize /'[^']*'\<bar>=>/l1l0<cr>
Some other thoughts: 其他一些想法:
noremap
unless you are using <Plug>
or <SID>
mappings. <Plug>
或<SID>
映射,否则您可能应该使用noremap
。 v
mode which maps both visual mode and select mode. v
模式,该模式同时映射可视模式和选择模式。 It is probably best to use xnoremap
instead xnoremap
代替 :Tabularize
will align all the neighboring lines that match your pattern with out a range :Tabularize
会将与您的模式匹配的所有相邻线对齐,但不超出范围 :AddTabularPattern
can be used to name a pattern. :AddTabularPattern
可用于命名模式。 Add :AddTabularPattern routes /'[^']*'\\<bar>=>/l1l0
to your ~/.vim/after/plugin/tabular.vim
. :AddTabularPattern routes /'[^']*'\\<bar>=>/l1l0
到您的~/.vim/after/plugin/tabular.vim
。 Now you can do :Tabularize routes
:Tabularize routes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.