I need to do a map for visual mode to apply some commands on the selection only. This implies that the '<,'> needs to appear in the command line.
As they appear automatically when you type :, I did the mappings without delimiters, something like vmap ,{key} :{command}. So far it's working, they are being shown 开发者_如何学Pythonas :'<,'>{command}.
But the question is, is it safe to rely on this behaviour? Or there is a better way to do a visual map and insert the delimiters?
Yes, it's safe to rely on that behavior. Vim always insert the visual range markers ('< and '>) when you press : while in visual mode. Since a map is just a way to store a series of key presses (ignoring <expr> maps), it acts just like you had typed it.
You could use <c-u> at the start of your mapping to clear any range that might be there, and then add the range markers explicitly (:<c-u>'<,'>).
:help omap-info:help c_CTRL-U
加载中,请稍侯......
精彩评论