简体   繁体   English

用emacs中的一个键将html标签包裹在下一个单词周围

[英]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.我需要在多个 HTML 文档中的一堆不同的单词周围插入<code> ...</code> 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然后我希望能够在第一个“清除”之前定位标记,执行像 Cc c 这样的快速击键,并将文本更改为

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

I have to do this a lot.我必须经常这样做。

I'm using html-mode in emacs 25.我在 emacs 25 中使用 html-mode。

Note: I also wouldn't mind a command for wrapping <code>...</code> around the current region.注意:我也不介意在当前区域周围包装<code>...</code>的命令。

wrap-region-mode will do what you want. wrap-region-mode会做你想做的。 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.它定义了默认的“包装器”,但您可以添加诸如<code>标签之类的包装器。

By default, at least as of Emacs 27.1, if you open an html file, you have the sgml-mode commands available to you.默认情况下,至少从 Emacs 27.1 开始,如果您打开一个 html 文件,您就可以使用 sgml-mode 命令。 This includes the command sgml-tag which is bound to Cc Co .这包括绑定到Cc Co的命令sgml-tag

If you select a region, then do Cc Co , if will prompt you to type the name of the tag and then for attributes.如果您选择一个地区,然后执行Cc Co ,如果会提示您输入标签的名称,然后输入属性。 So if you entered "code" for the tag and then hit enter for no attributes, that would do what you wanted.因此,如果您为标签输入“代码”,然后在没有属性的情况下按回车键,那将执行您想要的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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