How to shorten a diamond symbol in vim

In the dictionary file that I edit, I often need to insert the β€œβ—Šβ€ symbol in place of <>. Is there a way to map "β—Š" to some key so that I press "r" to replace, and then my_shortcut to replace <> with "β—Š"? I found a way to do imap mapping in .vimrc:

:imap <> β—Š 

But switching to insert mode is suboptimal, is it possible to do this in replace mode, and what should I write in .vimrc for this?

+4
source share
3 answers

Using the following card

 :map r<> :%s/<>/β—Š/g<CR> 

you can press r<> , which will replace all occurrences of <> with β—Š in the current buffer.

The map (or rather the substitution that is called with it) will give you error E486 if the template is not found. If you do not want such an error, you will want to specify the e flag with the substitution command:

 :map r<> :%s/<>/β—Š/ge<CR> 

You can put one of these mappings in your .vimrc file.

+6
source

you can also use the vim digraph function, press CTRL-K and then cD and you get a diamond. Or, if CTRL-K maps to something else (some scripts tend to reassign it), you can :set digraph and use c <BS> D in insert mode.

+5
source

Have you tried to use the abbreviation for this? You can do:

 :abbr <> β—Š 

And then every time you enter <> followed by a space (or any character without a keyword) in insert mode, it will be replaced by `` β—Š ''.

+2
source

Source: https://habr.com/ru/post/1308869/


All Articles