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:
\\ar
I've tested the Tabularize command and it works. 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.
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 |
in your mapping as |
separates vim commands.
xnoremap <leader>ar :Tabularize /'[^']*'\<bar>=>/l1l0<cr>
Some other thoughts:
noremap
unless you are using <Plug>
or <SID>
mappings. v
mode which maps both visual mode and select mode. It is probably best to use xnoremap
instead :Tabularize
will align all the neighboring lines that match your pattern with out a range :AddTabularPattern
can be used to name a pattern. Add :AddTabularPattern routes /'[^']*'\\<bar>=>/l1l0
to your ~/.vim/after/plugin/tabular.vim
. Now you can do :Tabularize routes
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.