加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

GoLang及Sublime Text 2之Mac OS X 10.8.4开发环境安装

发布时间:2020-12-16 18:59:05 所属栏目:大数据 来源:网络整理
导读:2013-09-21 wcdj 1 golang简介 Go is an open source programming environment that makes it easy to build simple,reliable,and efficient software. golang的主页:http://golang.org/ 2 Mac OS X 10.8.4环境安装 (1) 下载安装包(详细可参考:http://gol

2013-09-21 wcdj


1 golang简介

Go is an open source programming environment that makes it easy to build simple,reliable,and efficient software.

golang的主页:http://golang.org/


2 Mac OS X 10.8.4环境安装

(1) 下载安装包(详细可参考:http://golang.org/doc/install)

在 http://code.google.com/p/go/downloads/list 链接中选择安装包: go1.2rc1.darwin-amd64-osx10.8.pkg

https://code.google.com/p/go/wiki/Downloads?tm=2 下载页面

(2) 安装

打开下载好的pkg文件,根据安装向导完成安装。默认的安装路径是:/usr/local/go。

mba:go gerryyang$ pwd
/usr/local/go
mba:go gerryyang$ ls
AUTHORS		PATENTS		api		doc		lib		robots.txt
CONTRIBUTORS	README		bin		favicon.ico	misc		src
LICENSE		VERSION		blog		include		pkg		test
(3) 设置环境变量

将/usr/local/go/bin添加到PATH环境变量中:

a. 在home目录下打开.bashrc文件,并将添加:export PATH=$PATH:/usr/local/go/bin,然后保存关闭;

b. 执行 . .bashrc 使环境变量生效;

在command line测试会显示如下内容:

mba:~ gerryyang$ go
Go is a tool for managing Go source code.

Usage:

	go command [arguments]

The commands are:

    build       compile packages and dependencies
    clean       remove object files
    env         print Go environment information
    fix         run go tool fix on packages
    fmt         run gofmt on package sources
    get         download and install packages and dependencies
    install     compile and install packages and dependencies
    list        list packages
    run         compile and run Go program
    test        test packages
    tool        run specified go tool
    version     print Go version
    vet         run go tool vet on packages

Use "go help [command]" for more information about a command.

Additional help topics:

    c           calling between Go and C/C++
    gopath      GOPATH environment variable
    packages    description of package lists
    remote      remote import path syntax
    testflag    description of testing flags
    testfunc    description of testing functions

Use "go help [topic]" for more information about that topic.

mba:~ gerryyang$ 

3 测试

下面使用MacVim编辑:

package main

import "fmt"

func main() {
    fmt.Printf("hello,golang!n")
}


If you see the "hello,world" message then your Go installation is working.


4 配置Sublime Text 2编辑环境

(1) 下载st2 http://www.sublimetext.com/

(2) 安装gosublime插件 http://my.oschina.net/Obahua/blog/110767

(3) st2个性化配置及入门使用(比如,更改图标)

英文原文 http://net.tutsplus.com/tutorials/tools-and-tips/sublime-text-2-tips-and-tricks/

中文版 http://lucifr.com/2011/08/31/sublime-text-2-tricks-and-tips/


st2的一些优点:

(a) 快捷的命令面板 shift+command+p

(b) 即时的文件切换 command+p

(c) 随心所欲的跳转 command+p @ (函数) #(搜索) : (行数)

PS: 让人叫绝的是,这些切换定位方法可以配合在一起使用

(d) 多重选择 (这个功能确实爽,对于不熟悉正则匹配的人)

激活多重选择的方法有几种:

  • 按住 CommandAlt,然后在页面中希望中现光标的位置点击。
  • 选择数行文本,然后按下 Shift + Command + L
  • 通过反复按下 Control/Command + D 即可将全文中与光标当前所在位置的词相同的词逐一加入选择,而直接按下 Alt+F3(Windows) 或是 Ctrl+Command+G(Mac) 即可一次性选择所有相同的词。
  • 按下鼠标中键(Mac上是option键)来进行垂直方向的纵列选择,也可以进入多重编辑状态。

(e) 代码缩进显示

缩进指示已经被集成进 Sublime Text 2 中,不需要安装插件了,之前需要安装 IndentGuides 插件。

(f) 安装包控制

安装 Package Control 的方法:

https://packagecontrol.io/installation

  • 打开 Sublime Text 2,按下 Control + ` 调出 Console
  • 将以下代码粘贴进命令行中并回车:

    import urllib2,os; pf='Package Control.sublime-package'; ipp = sublime.installed_packages_path(); os.makedirs( ipp ) if not os.path.exists(ipp) else None; urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler( ))); open( os.path.join( ipp,pf),'wb' ).write( urllib2.urlopen( 'http://sublime.wbond.net/' +pf.replace( ' ','%20' )).read()); print( 'Please restart Sublime Text to finish installation')
  • Sublime Text 3 请使用以下代码:

    import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp,'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())

  • 重启 Sublime Text 2,如果在 Preferences -> Package Settings中见到Package Control这一项,就说明安装成功了。

使用 Package Control 安装 Package 的方法:

第一步:按下 Shift + Command + P 调出命令面板

第二步:输入 install 调出 Package Control: Install Package 选项,按下回车

第三步:在列表中找到 xxx插件,按下回车进行安装

第四步:重启 Sublime Text 2 使之生效

PS: 详细的package列表可以在 https://sublime.wbond.net/ 查询。


(g) 对齐

在 Sublime Text 2 之中,一个 Sublime Alignment 插件也可以轻松实现。


(h) Vim模式 (方便Vimer过度使用)

Sublime Text 2 dev 版已经支持 Vim 的编辑模式了,如果更喜欢 Vim 的编辑模式,可以通过以下方法来激活 Vintage mode。

第一步:按下 Shift + Command + P 调出命令面板

第二步:输入 settings user 调出 Preferences:Settings - User,并按下回车

(以上两步等价于:command +,)

第三步:这时会打开一个 Preferences.sublime-settings 的文件,如果是第一次修改,它应该是个空文件,把以下文本粘贴进去

{
    "ignored_packages": []
}

第四步:保存这个文件,这时按下 ESC 键,再按下一些你熟悉的 Vim命令。

说明:gd命令好像不能用,跳转、查询等是相同的,Vintage 模式本身就是通过 keybinding 实现的,可以参考修改: http://sublimetext.info/docs/en/reference/key_bindings.html


(i) 无干扰模式(Distraction Free Mode)(自己还是习惯全屏模式 control + command + f)

在 Sublime Text 2 中,只要按下 Control + Shift + Command + F 或是在菜单 View 中选择 Enter Distraction Free Mode 就可以进入这个 UI 最小化模式了。如果是在用 Mac OS X Lion 的话,Sublime Text 2 还同时支持 Lion 的原生全屏模式。

通过修改 “Preferences” -> “File Settings - More” -> “Distraction Free - User” 可以对防干扰模式进行一些设置:

{
    "line_numbers": false,//是否显示行号
    "gutter": false,//是否显示边列
    "draw_centered": true,//是否居中显示
    "wrap_width": 80,//换行宽度(单位:字符)
    "word_wrap": true,//是否自动换行
    "scroll_past_end": true     //滚动能否超过结尾
}

(j) 一些编辑显示技巧

(1) 在左侧栏显示打开的文件列表

command + k; command + b 实现打开和关闭之间的切换。

(2) 字体大小动态调整

command + = 调大

command + - 调小

(3) cmd + option + 数字

实现多个tab并行编辑和对比。

(4) 通过参考默认配置文件 Perferences.sublime-settings 中的参数,可进行个性化设置。


(k) 主题

这里所讲的主题不同于针对代码的 Color Scheme,是指针对 Sublime 程序本身的主题,目前可以安装的是 Ian Hill 的 Soda。


(l) 必备的扩展插件

(a) ConvertToUTF8

ST2只支持utf8编码,该插件可以显示与编辑 GBK,BIG5,EUC-KR,EUC-JP,Shift_JIS 等编码的文件。

https://sublime.wbond.net/packages/ConvertToUTF8

https://github.com/seanliang/ConvertToUTF8

(b) gosublime

GoSublime is a Golang plugin collection for the text editor SublimeText providing code completion and other IDE-like features. Both Sublime Text versions 2 and 3 are supported.

https://sublime.wbond.net/packages/GoSublime



(m) 文档

Sublime Text Unofficial Documentation

http://www.sublimetext.com/docs/2/


(n) 把subl添加在命令行中

在 .bashrc 配置中添加如下别名:

# Sublime Text 2
alias subl='/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl'

然后 . .bashrc 使配置生效。然后输入 subl -h则显示如下:
mba:bin gerryyang$ subl -h
Sublime Text 2 Build 2221

Usage: subl [arguments] [files]         edit the given files
   or: subl [arguments] [directories]   open the given directories
   or: subl [arguments] -               edit stdin

Arguments:
  --project <project>: Load the given project
  --command <command>: Run the given command
  -n or --new-window:  Open a new window
  -a or --add:         Add folders to the current window
  -w or --wait:        Wait for the files to be closed before returning
  -b or --background:  Don't activate the application
  -s or --stay:        Keep the application activated after closing the file
  -h or --help:        Show help (this message) and exit
  -v or --version:     Show version and exit

--wait is implied if reading from stdin. Use --stay to not switch back
to the terminal when a file is closed (only relevant if waiting for a file).

Filenames may be given a :line or :line:column suffix to open at a specific
location.

mba:bin gerryyang$ subl -v
Sublime Text 2 Build 2221

mba:bin gerryyang$ 

在st2编写golang的模样:



5 进一步的使用

Start by taking A Tour of Go.

Build a web application by following the WikiTutorial.

Read Effective Go to learn about writingidiomatic Go code.

For the full story,consult Go's extensive documentation.

Subscribe to thegolang-announcemailing list to be notified when a new stable version of Go is released.


6 参考

[1] http://golang.org/

[2]https://github.com/Unknwon/go-fundamental-programming go编程基础

[3] http://www.sublimetext.com/ st2主页

[4] http://lucifr.com/2011/08/31/sublime-text-2-tricks-and-tips/ Sublime Text 2 入门及技巧

[5] http://lucifr.com/tags/sublime-text/ 更多st2的文章

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读