Atom editor Atom--代码段不工作

Atom editor Atom--代码段不工作,atom-editor,Atom Editor,以下是我在snippets.cson文件中编写的两个代码段: '.source.python': 'print statement': 'prefix': 'pr' 'body' : 'print "${1:Hello world}"' '.source.python': 'Argument variables import': 'prefix' : 'argv' 'body' : 'from sys import argv' 第一个不起作用,但第二

以下是我在snippets.cson文件中编写的两个代码段:

'.source.python':
  'print statement':
    'prefix': 'pr'
    'body' : 'print "${1:Hello world}"'


'.source.python':
  'Argument variables import':
    'prefix' : 'argv'
    'body' : 'from sys import argv'
第一个不起作用,但第二个起作用。请帮忙

附言


当我第一次在我的机器上安装atom时,代码片段文件是空的。我使用Ubuntu 16.04。这正常吗?

我认为问题的根源在于您的作用域
.source.python
被声明了两次

首先回答第二个问题:不,我第一次打开mysnippets.cson文件时它不是空的。相反,它包含以下内容:

# Your snippets
#
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to
# expand the prefix into a larger code block with templated values.
#
# You can create a new snippet in this file by typing "snip" and then hitting
# tab.
#
# An example CoffeeScript snippet to expand log to console.log:
#
# '.source.coffee':
#   'Console log':
#     'prefix': 'log'
#     'body': 'console.log $1'
#
# Each scope (e.g. '.source.coffee' above) can only be declared once.
#
# This file uses CoffeeScript Object Notation (CSON).
# If you are unfamiliar with CSON, you can read more about it in the
# Atom Flight Manual:
# http://flight-manual.atom.io/using-atom/sections/basic-customization/#_cson
(不过,这是在MacOS上)

请注意,它如何指示每个范围只能声明一次。我认为,如果您修改两个代码片段以包含在同一范围内,它们将按预期工作

snippets.cson
更改为以下内容似乎对我有用:

'.source.python':
  'print statement':
    'prefix': 'pr'
    'body' : 'print "${1:Hello world}"'

  'Argument variables import':
    'prefix' : 'argv'
    'body' : 'from sys import argv'

一旦我使
.source.python
作用域唯一,我就可以从snippets import菜单访问这两个代码段。

Ubuntu20.10上的Atom 1.53.0 x64(“groovy gorilla”):

我必须禁用核心包“语言html”(0.53.1)中“设置”中的“内置”代码段。从那里,我复制了前缀代码段,将其粘贴到我自己的本地snippets.cson中,并根据需要进行更改

我还必须重新启动Atom才能让编辑器显示我的自定义代码段以供使用

在我的例子中,原始snippets.cson也是空白的。没有提示,就没有例子。
vi
-感觉:-)

我以前在windows 10上安装过atom,我记得读过类似的内容。但在Ubuntu上,字面上为空。\n哪个声明优先?一个在前面还是后面?我怀疑后面的那个,因为它似乎是一种声明性语言。此外,OP还表示他的第二个代码片段是有效的,但不是第一个,这很有趣。我怀疑这是Ubuntu的一个bug,可能应该提交给Atom项目。不过,我不会怀疑这是一个依赖于平台的问题。@NageshEranki如果这个答案对你有用,我可以随意接受