Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to shortcut diamond character in vim

Tags:

vim

mapping

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 key 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?

like image 722
Temujin Avatar asked Dec 12 '22 22:12

Temujin


1 Answers

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.

like image 109
René Nyffenegger Avatar answered Jan 14 '23 19:01

René Nyffenegger