GoからVimを起動する

VimからGoを」ではありません。

CLIツールに設定ファイルをエディタで開く機能(git config --editのような)をつくろうとしたところ、上手く行きません。exec.Command("vim").Run()vimを起動しようとしても、exit status 1で失敗してしまうのです。

困った時のStackOverflow

VimEmacs etc. のようなターミナルアプリを呼び出すときも、Stdin/Stdoutを渡してやれば上手く動いてくれるようです。

http://stackoverflow.com/questions/21513321/how-to-start-vim-from-go Pass on stdin and stdout from the calling program which, provided it was run from a terminal (likely for a command line program) will start vim for you and return control when the user has finished editing the file.

package main

import (
    "fmt"
    "os"
    "os/exec"
)

func main() {
    cmd := exec.Command("vim", "test.txt")
    cmd.Stdin = os.Stdin
    cmd.Stdout = os.Stdout
    err := cmd.Run()
    fmt.Println(err)
}