第十三章 个人渣翻译 spf13插件---surround 使用教程

来源:互联网 发布:淘宝手机端发布宝贝 编辑:程序博客网 时间:2024/06/16 19:00

先看看spf13中对surround的介绍:


This plugin is a tool for dealing with pairs of "surroundings." Examples of surroundings include parentheses, quotes, and HTML tags. They are closely related to what Vim refers to as text-objects. Provided are mappings to allow for removing, changing, and adding surroundings.

Details follow on the exact semantics, but first, consider the following examples. An asterisk (*) is used to denote the cursor position.

 

渣翻译:

这个插件工具用来处理结对符。例如成对的括号,引号,和HTML 标签。

它也和vim 引用文本对象紧密相关,提供移除,改变和增加结对符的映射。

但首先,要考虑到以下示例,星号(*)用来指代光标位置。

Old text                        Command         New text ~  "Hello *world!"                ds"              Hello world!  [123+4*56]/2                   cs])             (123+456)/2  "Look ma, I'm *HTML!"     cs"<q>      <q>Look ma, I'm HTML!</q>  if *x>3 {                           ysW(             if ( x>3 ) {  my $str = *whee!;           vllllS'            my $str = 'whee!';

比如,如果光标在“foo bar”,你可以输入cs”’把它转换为 ‘foo bar’

更多详情 :help surround


再看看surround官网是怎么说的:

 

Surround.vim is all about "surroundings": parentheses, brackets, quotes, XML tags, and more. The plugin provides mappings to easily delete, change and add such surroundings in pairs.

It's easiest to explain with examples. Press cs"' inside

"Hello world!"
to change it to

'Hello world!'
Now press cs'<q> to change it to

<q>Hello world!</q>
To go full circle, press cst" to get

"Hello world!"
To remove the delimiters entirely, press ds".

Hello world!
Now with the cursor on "Hello", press ysiw] (iw is a text object).

[Hello] world!
Let's make that braces and add some space (use } instead of { for no space): cs]{

{ Hello } world!
Now wrap the entire line in parentheses with yssb or yss).

({ Hello } world!)
Revert to the original text: ds{ds)

Hello world!
Emphasize hello: ysiw<em>

<em>Hello</em> world!
Finally, let's try out visual mode. Press a capital V (for linewise visual mode) followed by S<p class="important">.

<p class="important">
  <em>Hello</em> world!
</p>
This plugin is very powerful for HTML and XML editing, a niche which currently seems underfilled in Vim land. (As opposed to HTML/XML inserting, for which many plugins are available). Adding, changing, and removing pairs of tags simultaneously is a breeze.

 

渣翻译:

surround适用于各种结对符号: 括号,括弧,引号,XML标签等等。

插件提供了简单的删除,修改和增加结对符的映射。

最容易解释用法是示例:内部按下cs”’

"Hello world!"
会改变为
'Hello world!'

现在按下cs’<q>修改为:
<q>Hello world!</q>
转回去,按下cst”变成
"Hello world!"

完全移除分隔符,按下ds”
Hello world!


现在把光标停留在hello处,按下ysiw](iw是一个文本对象)
[Hello] world!

用{}来替代[],按下cs]}
{ Hello } world!

用括号整个包围,按下yss)
({ Hello } world!)

恢复原状:ds{ds)
Hello world!

突出hello:ysiw<em>
<em>Hello</em> world!

最后,让我们实验可视模式,在按下V之后,S<p class="important">
<p class="important">
  <em>Hello</em> world!
</p>
这个插件对于编辑HTML和XML非常强大,无论添加,修改和删除结对符轻而易举。


个人总结实践:


该插件就是用来快速添加,修改和删除结对符。
避免了缓慢移动光标,再键盘输入修改的方式,提升效率。


所有的命令都在普通模式下生效。
有两点需要注意,第一是按键cs”’的速度不能太慢,否则无效。
第二是光标要么停留在结对符上,要么停留在中间空格处,否则无效。

对于一行文本,其中单个字需要加结对符时,使用ysw。

ysw和ysW的区别在于,前者只给单个字加符号,而后者作用从光标处开始一直到行尾。
多个字需要添加结对符时,用可视模式,移动光标选定需要修改的部分,再按大写S进入插件功能。
但容易误操作!因为进入可视模式后,按小写s就会删除掉被选部分,并进入插入模式!

一旦忘记大小写切换,很容易出错,而大小写切换也不方便。

有没有不进可视模式,还能对多个字进行处理的办法?

比如想在x+3之间添上括号,形成(x+3)*20




不进可视模式,该插件没办法完成,只能老实移动光标,手工输入。


而要在光标所处的整行添加符号时,使用yss。
ds删除时,先删除最里面的符号,再删除最外面的。
总之,对于c/c++来说,还是可以提升效率的,事实上最合适的用处在于HTML以及各种脚本语言里。

为了方便,最好还是将插件的ysiw和yss映射成某个快捷键。


0 0
原创粉丝点击