tags:

views:

60

answers:

3

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?

+5  A: 

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.

René Nyffenegger
Thanks a bunch! That worked great, with one change - I do not need to make sweeping changes for whole document, that scares me - make changes just for that instance. So,I take off "%" from equation.map r<> :s/<>/◊/ge<CR>.This still helps me to easily replace <> with diamond char "◊" without distracting from vim window to searching it in some X application, like web browser.
+3  A: 

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.

Ressu
Vim is like text Photoshop, so much features... I haven't heard of "digraph feature". But that indeed works!
+2  A: 

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 ''◊''.

WishCow

related questions