189 8069 5689

vi编辑器go语言 vi编辑器编写c语言,并用gcc编译

golang ide 什么好用

第一种:LiteIDE

成都创新互联公司专业成都网站设计、成都网站建设,集网站策划、网站设计、网站制作于一体,网站seo、网站优化、网站营销、软文推广等专业人才根据搜索规律编程设计,让网站在运行后,在搜索中有好的表现,专业设计制作为您带来效益的网站!让网站建设为您创造效益。

LiteIDE是一个简单的开源IDE,值得注意的是,它是GO语言2012年正式版发布的首个IDE,由Qt开发,它看起来类似于Visual Studio等其他编译器。

由于它是为golang设计的,LiteIDE为开发人员提供了许多有用的功能,包括可配置的构建命令,高级代码编辑器和广泛的golang支持。其他功能包括代码管理、gdb、Delve调试器、自动完成和使用WordApi的主题,基于MIME类型的系统等。

第二种:VS Code

它是微软开发的广受欢迎的开源IDE,有一个开箱即用的go扩展可供VS Code使用。VS Code插件为开发人员提供了很多功能,包括与许多go工具集成。

VS Code通过IntelliSense,内置git集成,直接从编译器调试代码等功能提供智能完成功能;VS Code具有高度可扩展性,并通过其许多扩展提供了许多自定义选项,还提供了几十种语言的支持,成为受开发者欢迎的工具。

第三种:Atom

开发人员可以利用这个Atom IDE改进的语言集成与更智能的编辑器。开源的go-plus软件包使开发人员更容易在GO中进行编程。

Atom和go-plus软件包为golang提供工具,构建流程,linters、vet和coverage工具的支持;其他功能包括自动完成、格式化、测试和文档。

第四种:Vim

Vim有许多插件可以帮助开发人员更轻松地编辑他们的GO代码;Vim-go插件自动安装所有必要的东西,为Vim中的GO开发人员提供更平滑的集成。

Vim-go具有许多有用的功能,包括编译器,改进的语法高亮和折叠,完成支持以及一系列具有集成支持的调试程序。还有一些使用的高级源分析工具,包括GoImplements、GoCallees和GoReferrers。

如何配置go语言集成开发环境 vim

1、编译vimgdb

下载vimgdb73和vim73

mkdir -p ./tmp

cd tmp

tar zxvf ../vim-7.3.tar.gz

unzip ../vimgdb-for-vim7.3-master.zip

mv vimgdb-for-vim7.3-master vimgdb-for-vim7.3

patch -p0 vimgdb-for-vim7.3/vim73.patch

cd vim73

安装依赖

sudo apt-get install build-essential

sudo apt-get build-dep vim-gtk

sudo apt-get install libncurses5-dev

安装

// 这里直接执行make的操作

make

sudo make install

安装vimgdb runtime

cd ../vimgdb-for-vim7.3

cp vimgdb_runtime ~/.vim/bundle

打开vim

:helptags ~/.vim/bundle/vimgdb_runtime/doc " 生成doc文件

添加配置.vimrc

" vimgdb插件

run macros/gdb_mappings.vim

在vim中执行gdb时,报 “Unable to read from GDB pseudo tty” 的错误,因为没有安装 gdb ,所以安装gdb

sudo apt-get install gdb

2、安装vundle

set up vundle

$ git clone ~/.vim/bundle/vundle

Configure Plugins

在.vimrc文件的开头添加下面的内容,有些不是必须的,可以注掉

set nocompatible " be iMproved, required

filetype off " required

" set the runtime path to include Vundle and initialize

set rtp+=~/.vim/bundle/vundle/

call vundle#rc()

" alternatively, pass a path where Vundle should install plugins

"let path = '~/some/path/here'

"call vundle#rc(path)

" let Vundle manage Vundle, required

Plugin 'gmarik/vundle'

" The following are examples of different formats supported.

" Keep Plugin commands between here and filetype plugin indent on.

" scripts on GitHub repos

Plugin 'tpope/vim-fugitive'

Plugin 'Lokaltog/vim-easymotion'

Plugin 'tpope/vim-rails.git'

" The sparkup vim script is in a subdirectory of this repo called vim.

" Pass the path to set the runtimepath properly.

Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}

" scripts from

Plugin 'L9'

Plugin 'FuzzyFinder'

" scripts not on GitHub

Plugin 'git://git.wincent点抗 /command-t.git'

" git repos on your local machine (i.e. when working on your own plugin)

Plugin ''

" ...

filetype plugin indent on " required

" To ignore plugin indent changes, instead use:

"filetype plugin on

"

" Brief help

" : PluginList - list configured plugins

" : PluginInstall(!) - install (update) plugins

" : PluginSearch(!) foo - search (or refresh cache first) for foo

" : PluginClean(!) - confirm (or auto-approve) removal of unused plugins

"

" see :h vundle for more details or wiki for FAQ

" NOTE: comments after Plugin commands are not allowed.

" Put your stuff after this line

Install Plugins

Launch vim and run

: PluginInstall

vim +PluginInstall +qall

3、官方vim-lang插件

Config vim file .vimrc,Add content bellow in bottom of the file

" 官方的插件

" Some Linux distributions set filetype in /etc/vimrc.

" Clear filetype flags before changing runtimepath to force Vim to

" reload them.

filetype off

filetype plugin indent off

set runtimepath+=$GOROOT/misc/vim

filetype plugin indent on

syntax on

autocmd FileType go autocmd BufWritePre Fmt

4、代码补全的插件gocode

配置go的环境变量,比如我的配置,GOPATH变量是必须要配置的,PATH中必须把GOPATH的bin也添加进去,否则没有自动提示,会提示找不到模式

export GOROOT=/usr/local/go

export GOPATH=/data/app/gopath

export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

Set up gocode

Then you need to get the appropriate version of the gocode, for 6g/8g/5g compiler you can do this:

go get -u github点抗 /nsf/gocode (-u flag for "update")

Configure vim in .vimrc file

Plugin 'nsf/gocode', {'rtp': 'vim/'}

Install Plugins

Launch vim and run

: PluginInstall

vim +PluginInstall +qall

写一个helloword程序,输入fmt后按C-xC-o如果能看到函数的声明展示出来,说明安装是正确的。

4、代码跳转提示godef

Set up godef

go get -v code.google点抗 /p/rog-go/exp/cmd/godef

go install -v code.google点抗 /p/rog-go/exp/cmd/godef

git clone ~/.vim/bundle/vim-godef

Configure vim in .vimrc file

Bundle 'dgryski/vim-godef'

Install Plugins

Launch vim and run

: PluginInstall

vim +PluginInstall +qall

5、代码结构提示gotags

Set up gotags

go get -u github点抗 /jstemmer/gotags

Put the following configuration in your vimrc:

Bundle 'majutsushi/tagbar'

nmap :TagbarToggle

let g:tagbar_type_go = {

\ 'ctagstype' : 'go',

\ 'kinds' : [

\ 'p:package',

\ 'i:imports:1',

\ 'c:constants',

\ 'v:variables',

\ 't:types',

\ 'n:interfaces',

\ 'w:fields',

\ 'e:embedded',

\ 'm:methods',

\ 'r:constructor',

\ 'f:functions'

\ ],

\ 'sro' : '.',

\ 'kind2scope' : {

\ 't' : 'ctype',

\ 'n' : 'ntype'

\ },

\ 'scope2kind' : {

\ 'ctype' : 't',

\ 'ntype' : 'n'

\ },

\ 'ctagsbin' : 'gotags',

\ 'ctagsargs' : '-sort -silent'

\ }

命令模式下按在右边就会显示当前文件下的函数名,结构体名等等,光标放到相应的tag上,按回车可以快速跳到程序中的相应位置。

再次按会关闭tag窗口。

PS:本地的.vimrc的配置

" 插件管理器 vundle

set nocompatible " be iMproved, required

filetype off " required

" set the runtime path to include Vundle and initialize

set rtp+=~/.vim/bundle/vundle/

call vundle#rc()

" alternatively, pass a path where Vundle should install plugins

"let path = '~/some/path/here'

"call vundle#rc(path)

" let Vundle manage Vundle, required

Plugin 'gmarik/vundle'

" The following are examples of different formats supported.

" Keep Plugin commands between here and filetype plugin indent on.

" scripts on GitHub repos

" Plugin 'tpope/vim-fugitive'

" Plugin 'Lokaltog/vim-easymotion'

" Plugin 'tpope/vim-rails.git'

" The sparkup vim script is in a subdirectory of this repo called vim.

" Pass the path to set the runtimepath properly.

" Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}

" scripts from

" Plugin 'L9'

" Plugin 'FuzzyFinder'

" scripts not on GitHub

" Plugin 'git://git.wincent点抗 /command-t.git'

" git repos on your local machine (i.e. when working on your own plugin)

" Plugin ''

" ...

"

filetype plugin indent on " required

" To ignore plugin indent changes, instead use:

" filetype plugin on

"

" Brief help

" : PluginList - list configured plugins

" : PluginInstall(!) - install (update) plugins

" : PluginSearch(!) foo - search (or refresh cache first) for foo

" : PluginClean(!) - confirm (or auto-approve) removal of unused plugins

"

" see :h vundle for more details or wiki for FAQ

" NOTE: comments after Plugin commands are not allowed.

" Put your stuff after this line

syntax on

" ********************************************************************

" 这里省略了其它不相关的插件

" vimgdb插件

run macros/gdb_mappings.vim

" 官方的插件

" Some Linux distributions set filetype in /etc/vimrc.

" Clear filetype flags before changing runtimepath to force Vim to

" reload them.

filetype off

filetype plugin indent off

set runtimepath+=$GOROOT/misc/vim

filetype plugin indent on

syntax on

autocmd FileType go autocmd BufWritePre buffer Fmt

" 代码补全的插件

Bundle 'Blackrush/vim-gocode'

" 代码跳转提示

Bundle 'dgryski/vim-godef'

" 代码结构提示

Bundle 'majutsushi/tagbar'

nmap F8 :TagbarToggleCR

let g:tagbar_type_go = {

\ 'ctagstype' : 'go',

\ 'kinds' : [

\ 'p:package',

\ 'i:imports:1',

\ 'c:constants',

\ 'v:variables',

\ 't:types',

\ 'n:interfaces',

\ 'w:fields',

\ 'e:embedded',

\ 'm:methods',

\ 'r:constructor',

\ 'f:functions'

\ ],

\ 'sro' : '.',

\ 'kind2scope' : {

\ 't' : 'ctype',

\ 'n' : 'ntype'

\ },

\ 'scope2kind' : {

\ 'ctype' : 't',

\ 'ntype' : 'n'

\ },

\ 'ctagsbin' : 'gotags',

\ 'ctagsargs' : '-sort -silent'

\ }

如何使用vim编写go

对于这个问题,我想说“直接写不就可以了?”

但是,可以更好。vim这个编辑器向来不缺各种插件或配置来挖掘和提升它的能力,百度一下“vim go 开发环境”“vim go ide”“vim go 插件”等等就能找到大量的教程来把vim搞成一个相当好用的go开发环境。

推荐vim插件vim-go

如何使用Go语言实现远程执行命令

一般命令

所谓一般命令,就是在一定时间内会执行完的命令。比如 grep, cat 等等。 执行命令的步骤是:连接,执行,获取结果

连接

连接包含了认证,可以使用 password 或者 sshkey 2种方式来认证。下面的示例为了简单,使用了密码认证的方式来完成连接。

import (

"fmt"

"time"

"golang.org/x/crypto/ssh"

)

func connect(user, password, host string, port int) (*ssh.Session, error) {

var (

auth []ssh.AuthMethod

addr string

clientConfig *ssh.ClientConfig

client *ssh.Client

session *ssh.Session

err error

)

// get auth method

auth = make([]ssh.AuthMethod, 0)

auth = append(auth, ssh.Password(password))

clientConfig = ssh.ClientConfig{

User: user,

Auth: auth,

Timeout: 30 * time.Second,

}

// connet to ssh

addr = fmt.Sprintf("%s:%d", host, port)

if client, err = ssh.Dial("tcp", addr, clientConfig); err != nil {

return nil, err

}

// create session

if session, err = client.NewSession(); err != nil {

return nil, err

}

return session, nil

}

连接的方法很简单,只要提供登录主机的 用户*, *密码*, *主机名或者IP*, *SSH端口

执行,命令获取结果

连接成功后,执行命令很简单

import (

"fmt"

"log"

"os"

"time"

"golang.org/x/crypto/ssh"

)

func main() {

session, err := connect("root", "xxxxx", "127.0.0.1", 22)

if err != nil {

log.Fatal(err)

}

defer session.Close()

session.Run("ls /; ls /abc")

}

上面代码运行之后,虽然命令正常执行了,但是没有正常输出的结果,也没有异常输出的结果。 要想显示结果,需要将 session 的 Stdout 和 Stderr 重定向 修改 func main 为如下:

func main() {

session, err := connect("root", "xxxxx", "127.0.0.1", 22)

if err != nil {

log.Fatal(err)

}

defer session.Close()

session.Stdout = os.Stdout

session.Stderr = os.Stderr

session.Run("ls /; ls /abc")

}

这样就能在屏幕上显示正常,异常的信息了。

交互式命令

上面的方式无法远程执行交互式命令,比如 top , 远程编辑一个文件,比如 vi /etc/nginx/nginx.conf 如果要支持交互式的命令,需要当前的terminal来接管远程的 PTY。

func main() {

session, err := connect("root", "olordjesus", "dockers.iotalabs.io", 2210)

if err != nil {

log.Fatal(err)

}

defer session.Close()

fd := int(os.Stdin.Fd())

oldState, err := terminal.MakeRaw(fd)

if err != nil {

panic(err)

}

defer terminal.Restore(fd, oldState)

// excute command

session.Stdout = os.Stdout

session.Stderr = os.Stderr

session.Stdin = os.Stdin

termWidth, termHeight, err := terminal.GetSize(fd)

if err != nil {

panic(err)

}

// Set up terminal modes

modes := ssh.TerminalModes{

ssh.ECHO: 1, // enable echoing

ssh.TTY_OP_ISPEED: 14400, // input speed = 14.4kbaud

ssh.TTY_OP_OSPEED: 14400, // output speed = 14.4kbaud

}

// Request pseudo terminal

if err := session.RequestPty("xterm-256color", termHeight, termWidth, modes); err != nil {

log.Fatal(err)

}

session.Run("top")

}

总结

好了,这样就可以执行交互式命令了,比如上面的 top 也可以通过 vi /etc/nginx/nignx.conf 之类的命令来远程编辑文件。


本文标题:vi编辑器go语言 vi编辑器编写c语言,并用gcc编译
文章网址:http://cdxtjz.cn/article/ddsdeps.html

其他资讯