這是一個建立於
的文章,其中的資訊可能已經有所發展或是發生改變。
ctags(Generate tag files for source code)是vim下方便代碼閱讀的工具。儘管ctags也可以支援其它編輯器,但是它正式支援的只有VIM。並且VIM中已經預設安裝了Ctags,它可以協助程式員很容易地瀏覽原始碼。
參考:
http://baike.baidu.com/view/9340968.htm
環境準備:
1、安裝 sublimetext 3
下載安裝最新版本 sublimetext 3 http://www.sublimetext.com/3
2、安裝 Package Control,
在開啟 Sublime Text 3以後,按下快速鍵 Ctrl + `或者到功能表列的:View > Show Console執行以下命令
import urllib.request as 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())
//下面的是ubuntu的
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’
Mac下命令如下:
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, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())
參考:http://jinzhe.net/post/16.html
3、安裝 GoSublime
Command+Shift+P 開啟Package Control ,然後輸入 pcip (即“Package Control: Install Package”的縮寫)
在隨後出現的介面輸入GoSublime,點擊出現的項,就可以成功安裝GoSublime了。
4、go fmt啟用:
選中sublime text功能表列的Perferences>Package Settings>GoSublime>Settings User
找到env,並設定成:”env”: { “PATH”: “$HOME/go/bin:$PATH”},“use_gs_gopath”: true,
安裝 ctag
4.1.下載並解壓ctags包中的ctags.exe放到任何目錄下面,然後把這個目錄添加到系統的環境變數PATH裡面,最簡單就是放在 C:\Windows\System32 目錄下。
下載地址: http://ctags.sourceforge.net/
mac下安裝方法:
The default ctags executable in OSX does not support recursive directory search (i.e. ctags -R). To get a proper copy of ctags, use one of the following options:
-
Using Homebrew:
brew install ctags
-
Using MacPorts:
port install ctags
Ensure that the PATH is updated so the correct version is run:
- If which ctags doesn't point at ctags in /usr/local/bin, make sure you add /usr/local/bin to your PATH ahead of the folder which ctags reported.
- Alternatively, add the path to the new ctags executable to the settings, under command. If you have Xcode / Apple Developer Tools installed this path will likely be /usr/local/bin/ctags.
4.2 安裝 sublime text 的 Ctags 外掛程式。
官方說明文檔地址: https://github.com/SublimeText/CTags
官方Windows的安裝說明如下:
- Download the CTags binary from the Exuberant CTags site.
- Extract ctags.exe from the downloaded zip to C:\Program Files\Sublime Text 2 or any folder within your PATH so that Sublime Text can run it.
- Alternatively, extract to any folder and add the path to this folder to the command setting.
安裝結束之後,重啟Sublime Text之後,開啟$GOROOT/pkg檔案夾,
其中$GOROOT就是Go的安裝目錄,比如預設的是C:\go。開啟之後,點擊pkg節點,右鍵,選擇CTags: Rebuild Tags。
等待運行完成後,我們就可以做跳轉了,在函數上按ctrl+shift+滑鼠左鍵, 就可以看到跳轉。
CTags: Rebuild Tags 這一步其實是在 pkg 目錄下執行下面命令:
ctags -R -f .tags的命令
sublime text 匯入工程
project->add folder to project,選擇要匯入的檔案。
參考資料:
http://blog.csdn.net/laukaka/article/details/9737815
參考資料:
http://golanghome.com/post/126
Sublime Text 的Ctag 的預設命令快速鍵如下:
參看: https://github.com/SublimeText/CTags
官方提供的快速鍵如下:
不過我在 Windows 下實驗有效是下面2個,其他都沒有試用通過:
調轉到定義: ctrl + shift + left_click
跳回來: alt + - (當前開啟頁面的游標回來)
參考: http://golanghome.com/post/477
ubuntu 下搭建請參考: http://golanger.cn/sublime-text-2%E4%BD%BF%E7%94%A8ctags%E5%AE%9E%E7%8E%B0%E5%87%BD%E6%95%B0%E8%B7%B3%E8%BD%AC/