I am documenting Code a lot. For exporting purposes I often have to add a '~' infront and after an Expression. For Example "Adc_Cfg.c" needs to get "~Adc_Cfg.c~". That way the Export to PDF via latex is not making some indexes out of it. Now I have to do it manually. Often its about 100 to 200 Expressions Thats consuming a lot of Time. What I want ist something like this

'!' is the point:

Set Mark => '!'Adc_Cfg.c  => Move forward => Adc_Cfg.c'!' => Press some shortcut and get => ~Adc_Cfg.c~ 

Is there already a functionality for that, if not can someone help me with an elisp function?

In Addition: Is there anything like that for bold, italic...

Thank you


If I understand well, you want to surround an expression with a given character (~).

Maybe emacs-surround will satisfy your needs.

If you use evil, there is also evil-surround that I use and confirm you I can select a word and surround it with ~ by pressing S-s ~

  • Thank you that was exactly what I was searching for – 7ie7an Jul 18 '19 at 9:00

An alternative is smartparens (https://smartparens.readthedocs.io/en/latest/).


Org Mode has a function for this, as you might expect. Mark a region and run org-emphasize (bound by default to C-c C-x C-f in Org buffers), it will prompt you for an emphasis marker (one of */=~+) and will then wrap the region with that character. If the region is already wrapped in a different one of those characters, the function replaces it with the one you type. If you use the function without marking a region, it inserts two copies of the character and places the cursor between them.

I find it very useful and bind to something shorter (I use C-').

Your Answer

