简体   繁体   中英

Wrap html tag around next word with one key in emacs

I need to insert <code> ...</code> around a bunch of different words in multiple HTML documents. For example, if I have text like:

The clear command clears the current register

Then I would like to be be able to position the mark just before the first "clear", execute a quick keystroke like say Cc c , and have the text changed to

The <code>clear</code> command clears the current register

I have to do this a lot.

I'm using html-mode in emacs 25.

Note: I also wouldn't mind a command for wrapping <code>...</code> around the current region.

wrap-region-mode will do what you want. You can install it with package manager.

Wrap Region is a minor mode for Emacs that wraps a region with punctuations. For "tagged" markup modes, such as HTML and XML, it wraps with tags.

It has default "wrappers" defined but you can add wrappers like your <code> tag.

By default, at least as of Emacs 27.1, if you open an html file, you have the sgml-mode commands available to you. This includes the command sgml-tag which is bound to Cc Co .

If you select a region, then do Cc Co , if will prompt you to type the name of the tag and then for attributes. So if you entered "code" for the tag and then hit enter for no attributes, that would do what you wanted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM