如何在 Atom 中编写自定义命令? [英] How do I write a custom command in Atom?
本文介绍了如何在 Atom 中编写自定义命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为 Atom 编写一个命令,该命令由两个或多个预先存在的命令组成,例如选择行"和剪切".我该怎么做?
I want to write a command for Atom that composes two or more pre-existing commands, like "Select Line" and then "Cut". How do I do that?
推荐答案
您可以将以下代码添加到您的 init.coffee
文件中:
You can add the following code to your init.coffee
file:
atom.commands.add 'atom-text-editor', 'custom:cut-line', ->
editor = atom.workspace.getActiveTextEditor()
editor.selectLinesContainingCursors()
editor.cutSelectedText()
您可以通过在命令面板中搜索字符串来从源代码中获取要执行的代码.一旦你创建了一个命令,你可以通过编辑你的 keymap.cson
文件来将一个键映射到它:
You can get the code to execute from the source by searching for strings in the command palette. And once you have a command created, you can map a key to it by editing your keymap.cson
file:
'atom-text-editor':
'alt-cmd-z': 'custom:cut-line'
这篇关于如何在 Atom 中编写自定义命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文