如何在Atom中编写自定义命令? [英] How do I write a custom command in Atom?

查看:53
本文介绍了如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆