将单个 sed 命令转换为可重用的 Textmate 命令
我有 7 行文本:
a
b
c
d
e
f
g
现在我想在每行末尾添加字符,最终得到:
a,
b,
c,
d,
e,
f,
g,
我发现我可以使用“sed”命令并使用 Textmate 中的“Filter through command”通过 sed 运行我的选择
sed 's/$/,/'
现在,仍然存在一个问题:如何将其转换为以某种方式接受输入的 Textmate 命令(以便它知道要附加什么文本)?
(我的尝试被证明是不成功的)
I have 7 lines of text:
a
b
c
d
e
f
g
Now I want to add characters to the end of each line, to end up with:
a,
b,
c,
d,
e,
f,
g,
I found that I can use the "sed" command and run my selection through sed using "Filter through command" in Textmate
sed 's/$/,/'
Now, one question remains: how do I turn this into a Textmate command that takes input in some sort of way (so it knows what text to append)?
(My tries in doing this have proven unsuccessful)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将其弹出到文本包中的命令中,它将把剪贴板中的任何内容附加到已选择的所有行的末尾:
当前仅限于附加一行文本,如果剪贴板包含多于一行,则它会附加一行文本。将默认为所选行末尾的逗号。
编辑:
为了更进一步,这里的版本提供了一个对话框,提示输入将附加到所选内容中的每一行的字符串:
Pop this into a command within the Text bundle, it'll append whatever is in the clipboard to the end of all lines that have been selected:
It's currently limited to appending one line's worth of text, if the clipboard contains more than one line it will default to a comma at the end of the selected lines.
Edit:
To take this a little further, here's a version that provides a dialog box which prompts for the input of the string that will be appended to each line in the selection:
在文本菜单中已经有一个命令“编辑选择中的每一行”正是执行此操作。 它将把光标放在第一行,并且您在每一行上重复输入的内容。
In Text menu there is already a command "Edit each line in selection" exactly do this. It will put cursor on first line and what you type there repeated on each line.
在捆绑包编辑器中创建新命令
在输入下拉列表中选择所选文本或无
在输出中选择替换现有文本
我刚刚测试了它,它工作正常。
您还可以选择键盘快捷键以提高效率。
Create a new command in the bundle editor
On the input dropdown select Selected text or Nothing
On the output select Replace existing text
I just tested it and it works fine.
You can also choose a keyboard shortcut to make it more efficient.
如果您愿意避免使用命令路径而仅使用“查找/替换”对话框,只需执行以下操作:
'$'
(表示行尾)','
(您想要附加的内容)按住Option
,这会将“全部替换”更改为“选择中”。此技术可以应用于许多其他有用的方式。 例如,如果您想为每行添加前缀,请将
'$'
更改为'^'
。If you're willing to avoid the command route and simply use the Find/Replace dialog simply do as follows:
'$'
(to indicate the end of the line)','
(what you want appended)Option
, this will change "Replace All" to "In Selection"This technique can be applied in a number of other useful ways. For example, changing
'$'
to'^'
if you want to prefix each line.