有没有一个好的Vi(m)命令来调用参数在函数调用?奖励积分为Emacs

编程入门 行业动态 更新时间:2024-10-25 08:23:13
本文介绍了有没有一个好的Vi(m)命令来调用参数在函数调用?奖励积分为Emacs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 例如,如果我有一些代码,如:

foo = bar(abc,def,true,回电话);

有没有一个很好的命令来移动到第一或第二位置,留下逗号不变? p>

PS作为奖励我的朋友想知道这是否在Emacs中有效。

解决方案

在Vim中,如果将光标放在第一个单词的开头,并执行 dWWP ,那么它将具有所需的效果。这是一个细分:

dW删除当前单词,包括逗号和以下空格 W移动到开始下一个单词 P在光标前插入删除的文本

在要交换的对之后还有其他参数 - 如果只有两个参数需要修改,或者您想要交换最后两个参数,因为它将在结束括号后粘贴文本。

或者您可以使用正则表达式替换:

:%s /(\([ ^,] \ + \),\s * \([^,)] \ + \)/(\2,\1 / / pre>

这将在打开括号后面找到前两个参数,并交换它们。

更新:

搜索vim发现 swap参数插件,其中你可以做你想要的,可以处理上述两种方法之一的情况。

For example if I have some code like:

foo = bar("abc", "def", true, callback);

Is there a nice command to move true to the 1st or 2nd position leaving the commas intact?

P.S as a bonus my friend want to know if this works in Emacs too.

解决方案

In Vim if you place the cursor at the start of the first word and do dWWP then it will have the desired effect. Here is a breakdown:

dW delete the current word, including the comma and the following whitespace W move to the start of the next word P insert the deleted text before the cursor

This will work if there are further parameters after the pair to be swapped - it will need to be modified if there are only two parameters or you want to swap the last two parameters, since it will paste the text after the closing bracket.

Alternatively you could use a regex substitution:

:%s/(\([^,]\+\),\s*\([^,)]\+\)/(\2, \1/

This will find the first two arguments after the open bracket and swap them.

update:

A search of vim found the swap parameters plugin, which should do exactly what you want and can handle situations that either of the above methods cannot.

更多推荐

有没有一个好的Vi(m)命令来调用参数在函数调用?奖励积分为Emacs

本文发布于:2023-11-30 16:46:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650749.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   命令   积分   参数   Vi

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!