dum*_*dad 14 git macos visual-studio-code
我正在尝试配置我的Mac Book Pro(OSX El Capitan 10.11.1)以使用Visual Studio Code作为其默认编辑器.我创建了一个~/.bash_profile包含以下两行的文件
vscode () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
export VISUAL=open\ -n\ -b\ "com.microsoft.VSCode"
Run Code Online (Sandbox Code Playgroud)
这适用于某些事情:我可以vscode test.txt在bash终端输入并test.txt在Visual Studio Code中弹出,如果我运行env我VISUAL=open -n -b com.microsoft.VSCode在列表中看到的命令.我甚$VISUAL至可以只键入并在新的空文件上打开Visual Studio代码.
但如果我输入,git commit我会收到以下错误
错误:无法运行com.microsoft.vscode:没有此类文件或目录
错误:无法启动编辑器'com.microsoft.vscode'请
使用-m或-F选项提供消息.
所以我成功了,因为git试图打开Visual Studio Code来编辑我的提交消息但是它失败了.
我X应该export VISUAL=X在我的~/.bash_profile文件中使用什么来启用git来打开提交消息的Visual Studio代码?
(NB 如何使用Visual Studio代码作为Git的默认编辑器并不重复,因为Gary在Windows PC上.)
Gov*_*Rai 14
export EDITOR="code -w"到您的bash个人资料(您的Bash个人资料可通过访问open ~/.bash_profile)
这要求您code在路径中已经有二进制文件。如果没有,或者不知道是否这样做,只需进入vscode,输入CMD + SHIFT + P,键入code,然后单击Shell Command:在PATH中安装“ code”命令。然后执行第一步。
另外,下面pompalini的评论很有帮助,
记住要通过再次关闭并重新打开终端来“刷新”终端,或者通过运行来为bash配置文件提供资源
source ~/.bash_profile,只有这样,bash_profile中的新更改才会应用于终端。
小智 9
在终端
类型: open ~/.bash_profile
插入: export EDITOR="code -w"
在 Visual Studio 代码中
CMD + SHIFT + Pinstall code并从自动完成菜单中选择shell command: Install 'code' in command PATH它与VS Code的最新版本0.10.9一起使用
[core]
editor = '/Applications/Visual Studio Code.app/Contents/MacOS/Electron' -w
Run Code Online (Sandbox Code Playgroud)
使用以下命令对其进行测试:git config --global --edit。记住在更改配置文件后刷新终端。
1) 只需将此添加到您的~/.bash_profile 或 ~/.zshrc 中:
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
2)然后打开一个新终端或运行:source ~/.bash_profile或source ~/.zshrc
完成此步骤后,您将能够code .在任何路径上打开 VS Code
您还可以使用duti(一个命令行工具)来选择 macOS 上文档类型和 URL 方案的默认应用程序。
brew install duti
Run Code Online (Sandbox Code Playgroud)
# Make VS Code as default editor for all text files
duti -s com.microsoft.VSCode public.plain-text all
# Open files without extensions with VS Code as well
duti -s com.microsoft.VSCode public.data all
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10674 次 |
| 最近记录: |