译:Sublime Text 2 项目设置

Remy Bach 发表于 2012.09.18
原文标题: Sublime Text 2 Project Bliss
原文网址: http://net.tutsplus.com/tutorials/tools-and-tips/sublime-text-2-project-bliss/

One of the many things that led me to decide that Sublime Text was going to be my text editor of choice was the way you could customize what’s shown in the file list on the left. I had no idea that this level of customization was available. Here’s a short tutorial that I hope will help you as much as it did me.
让我在许多选择中决定使用作为我的文本编辑器的原因这一,就是可以自定义左侧栏中如何显示文件列表。起初我并不知道这种级别的自定义是可行的。
这里是一篇短教程,我希望它能像给我带来的帮助一样对您有所帮助。

Step 1 – Adding a Folder
第一步 – 添加一个文件夹

Note: If you already have a project set up, skip to Step 3.
注: 如果你已经有一个项目了,请直接跳至第三步

Upon opening up Sublime Text, add a folder to the project by pressing Ctrl+Shift+P (Cmd+Shift+p on Mac) to bring up the über handy Command Palette, typing “Add”, and then hitting Enter.
打开Sublime Text,按下 Ctrl+Shift+P(Cmd+Shift+P on Mac)打开命令面板,输入”Add”后回车。

添加文件夹

Step 2 – Save the Project
第二步 – 保存项目

Now that you’ve added a folder to the project, bring up the command palette again, and type “Save” (or Project: Save As) to save your project. We’re going to be editing this file in the next step.
至此,你已经添加到项目中一个文件夹,再次打开命令面板,输入”Save”(或 Project: Save As)来保存你的项目。在下一步我们将修改这个配置文件。

保存项目

Don’t forget to give your project file the .sublime-project extension. Likely, this will be provided for you.
不要忘记项目配置文件的扩展名是.sublime-project。一般情况下会默认添加的。

项目文件扩展名

Step 3 – Get to Know the Project File
第三步 – 了解项目配置文件

From the menu, select Project -> Edit Project to edit the project file you saved in Step 2. Or, of course, access this from the command palette.
在菜单中,选择Project -> Edit Project来修改第二步中生成的项目配置文件。当然你也可能通过命令面板来打开它。

You should now see something similar to the following in your editor window:
现在你应当在编辑器中看到与下面图片类似的界面:

{
  "folders":
    [
      {
        "path": "/C/wamp/www/wordpress"
      }
    ]
}

Fairly self explanatory, right? You’ll notice that, as with all Sublime Text goodies, this file is formatted as JSON. Don’t stress too much, if you don’t know much about JSON. You should be able to figure it out as you go along.
根据字面意思,很容易理解, 是吧?你也会注意到,和其他Sublime Text的配置文件一样,这个文件是JSON格式的。如果你不太熟悉JSON也不用紧张,当你使用时肯定能理解它。

3.1 – Displaying a Particular Folder
3.1 – 显示指定的文件夹

Let’s now update it so that it points to our theme folder/directory:
现在让我们修改以指向我们的主题目录:

{
  "folders":
    [
      {
        "path": "/C/wamp/www/wordpress/wp-content/themes/twentyeleven"
      }
    ]
}

Now, keep an eye on the sidebar on the left and hit Ctrl+S (Cmd+S on a Mac) to save the file. The sidebar will be updated instantly with the new folder.
现在,看一眼左侧的边栏,并按下 Ctrl+S(Cmd+S on Mac)保存文件。左侧边栏马上更新为新的文件夹。

The next thing worth pointing out (if you haven’t already noticed) is that the folders object is made up of an array literal (notated by the square brackets). If you’ve figured out that this means that we can specify more than one folder for our project, then you’d be absolutely correct. Let’s go ahead and give it a go.
另外一件(如果你还没注意到)值得强调的是这个文件的配置是以数组格式([])来定义的。意味着你可以为项目定义多个
文件夹。让我们现在试验一下。

3.2 – Adding Multiple Folders
3.2 – 添加多个文件夹

Fear not plugin developers, we care about you too, so let’s add our plugins directory as well as the theme folder:
害怕不是插件开发者,同时我们也考虑到你,所以让我们像添加主题文件夹一样添加插件目录:


{
"folders":
[
{
"path": "/C/wamp/www/wordpress/wp-content/themes/twentyeleven"
},
{
"path": "/C/wamp/www/wordpress/wp-content/plugins"
}
]
}

Save the file again, and you should see the following:
再次保存文件,你将看到如下图所示:
2个文件夹

Step 4 – What Else Can We Do?
第4步 – 还能做些什么?

I’m glad you asked! For starters, within each object in the folders array, there are a few different options available to us:
非常高兴你能这样问! 对于新手,在每个项目的文件数组配置中,可以设置不同的内容:

1. path (string): As we’ve seen, lets you specify the folder/directory to show in the sidebar
path (string): 正如我们所见,指定左侧文件所在的目录路径

2. name (string): Specify a name for the item in the sidebar
name (string): 为左侧边栏这一项指定一个名字

3. file_exclude_patterns (array): Specify files to exclude
file_exclude_patterns (array): 指定排除的文件

4. folder_exclude_patterns (array): Specify folders to exclude
folder_exclude_patterns (array): 指定排除的目录

The path is already familiar to us, and the name is self explanatory, so let’s dig in to the last two.
我们已经很熟悉目录路径(path)了, 而且名字(name)也是显而易见的,所以让我们重点看一下后两点。

4.1 – Excluding Files
4.1 – 排除文件

Admit it: there are some files that you will simply never edit, and these files are probably cluttering your project view. Instead, why don’t we hide them, and then, on the very odd occasion that you actually do need to edit them, open them manually.
相信: 有些文件你从不修改它,但这些文件很可能影响你项目的显示。因此,为什么不隐藏这些文件呢。 即使在极少时候,
你的确需要修改他们时,也可以手动打开。

This bit comes down to preference, but here are the files that I typically exclude: ‘._’, .bak, .ico, .sample, .swf, .tar, .tgz, files beginning with ‘wp-’ (let’s not go editing the WordPress core files), and finally, .zip files. To do this, our file_exclude_patterns array should look as follows:
这个应该算是偏好设置,下面是我通常排除的文件: ‘._’, .bak, .ico, .sample, .swf, .tar, .tgz, 以’wp-’开头的文件(我们最好不要个性WordPress的核心文件),最后还有 .zip文件。实现这些,我们的file_exclude_pattern
数组应该如下:


"file_exclude_patterns":[
"._*",
"*.bak",
"*.ico",
"*.sample",
"*.swf",
"*.tar",
"*.tgz",
"wp-*.php",
"*.zip"
]

4.2 – Excluding Folders
4.2 – 排队文件夹

If you don’t want to specify each file individually, you can instead choose to exclude folders. This is the list that I generally use:
如果你不想逐个指定这些文件,你可以换为排除目录。下面这个是我通常使用的:


"folder_exclude_patterns": [
"cgi-bin",
"wp-admin",
"wp-includes"
]

Note: You need to specify the file_exclude_patterns and the folder_exclude_patterns for each folder (see the final example below).
注:你需要为每个目录配置 file_exclude_patterns和folder_exclude_patterns(请看下面最后一段示例代码)。

Step 5 – But Wait… There’s More!
第5步 – 等等… 还有更多!

Other than the folders option, you can also specify two others:
1. settings: Any of the usual list of settings that you would like to apply on a project specific basis can go in here (for example: tab_size).
settings: 任何通用设置,你可以添加到项目设置上来(如: tab_size)。

2. build_systems: This allows you to add project-specific build system (which is beyond the scope of this tutorial).
build_systems: 你可以添加项目指定的编译系统(这个超出了本文范畴)

Our Final Project File
我们的最终配置文件

Here is an example of what your final .sublime-project file might look like (shortened slightly to be more succinct):
这个是你最终.sublime-project文件的示例代码(稍微缩短会更加简洁):


{
"folders":
[
{ // theme
"path": "/C/wamp/www/wordpress/wp-content/themes/twentyeleven",
"name": "Twenty Eleven Theme",
"file_exclude_patterns":[
"._*",
"*.ico",
"*.swf"
],
"folder_exclude_patterns": [
"images"
]
},
{ // plugins folder
"path": "/C/wamp/www/wordpress/wp-content/plugins",
"name": "Plugins Folder",
"file_exclude_patterns":[
"._*", // you need to specify this *again*
"*.bak",
"*.sample",
"*.tar",
"*.tgz",
"*.zip"
],
"folder_exclude_patterns": [
"akismet"//,
// add any other plugins you wish to exclude
]
}
],
"settings":
{
"tab_size": 4
}
}

To Conclude
结语

Note: If you’re itching to further harness your Sublime Text 2, stay tuned for “Perfect Workflow in Sublime Text 2″ – a free-to-all course from Tuts+ Premium, coming late September.
注:如果你希望进一步了解你的Sublime Text 2, 敬请关注9月下旬推出的”使用Sublime Text 2的完美工作流” -
一个Tuts+ Premium的免费课程

Sublime Text 2 is an amazing tool in your web development arsenal, and it’s features and possibilities reach way beyond this tutorial. For more on what it can do, be sure to dig around in the documentation… you’re guaranteed to find some real gems hiding away in there.
Sublime Text 2在你的Web开发工具库中是一个非常了不起的工具,它的特性和能做的远远超出本文内容。它还能做些
什么,一定要围绕它的文档细细研究… 你肯定可以找到一些隐藏其中真正的宝石。

Links:
链接:

  • Documentation: Seeand
  • for this article
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值