. Is there a way to map \"◊\" to some ke开发者_JS百科y so that I press \"r\" for replace and then m" />
开发者

How to shortcut diamond character in vim

In the dictionary file, which I am editing I often need to insert character "◊" on place of <>. Is there a way to map "◊" to some ke开发者_JS百科y so that I press "r" for replace and then my_shortcut to have <> replaced by "◊"? I found a way to make imap mapping in .vimrc:

:imap <> ◊

But changing to inset mode is sub-optimal, would that be possible to make it all in replace mode and what should I write in .vimrc for that?


With thhe following map

:map r<> :%s/<>/◊/g<CR>

you can press r<> which will replace all occurences of <> with ◊ in the current buffer.

The map (or rather the substitution that is invoked with it) will give you an error E486 if the pattern is not found. If you don't want such an error, you'll want to specify the e flag to the substitution command:

:map r<> :%s/<>/◊/ge<CR>

You can place one of these mappings into your .vimrc file.


you can also use the digraph feature of vim, press CTRL-K followed by cD and you get a diamond. Or if CTRL-K is mapped to something else (some scripts tend to remap it) you can :set digraph and use c <BS> D in insert mode.


Did you try using an abbreviation for it? You can do:

:abbr <> ◊

And then each time you type <> followed by space (or any non-keyword character) in insert mode, it will be replaced with ''◊''.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜