macos 如何从终端运行 mvim (MacVim)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2056137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:40:37  来源:igfitidea点击:

How to run mvim (MacVim) from Terminal?

macosshellvimcommand-linemacvim

提问by Fred

I have MacVim installed and I am trying to set it up as the editor for Git (version control), but I can't run 'mvim' from the command line as it isn't recognised. How do I setup mvim so I can run it from Terminal?

我安装了 MacVim 并且我试图将它设置为 Git(版本控制)的编辑器,但是我无法从命令行运行“mvim”,因为它无法识别。如何设置 mvim 以便我可以从终端运行它?

采纳答案by Gordon Robertson

There should be a script named mvim in the root of the .bz2 file. Copy this somewhere into your $PATH ( /usr/local/bin would be good ) and you should be sorted.

.bz2 文件的根目录中应该有一个名为 mvim 的脚本。将其复制到您的 $PATH ( /usr/local/bin 会很好)中,您应该被排序。

回答by Swapneel Patil

I don't think I'd to add anything to the path, did

我不认为我会在路径中添加任何内容,是吗

brew install macvim

mvim -v

should then open macvim in the terminal, you can also go ahead and alias that

然后应该在终端中打开 macvim,你也可以继续并别名

alias vim='mvim -v'

回答by Sean Chou

If you go the brew route, the best way to install would be:

如果你走 brew 路线,最好的安装方法是:

brew install macvim --with-override-system-vim

That will provide mvim, vim, vi, view, etc. in /usr/local/bin (all symlinked to the copy in the Cellar). This also removes the need to create any aliases and also changes your vi, vim, etc. to all use the same Vim distribution as your MacVim.

这将在 /usr/local/bin 中提供 mvim、vim、vi、view 等(所有符号链接到 Cellar 中的副本)。这也消除了创建任何别名的需要,并且还将您的 vi、vim 等更改为与 MacVim 使用相同的 Vim 发行版。

回答by hakamadare

In addition, if you want to use MacVim (or GVim) as $VISUALor $EDITOR, you should be aware that by default MacVim will fork a new process from the parent, resulting in the MacVim return value not reaching the parent process. This may confuse other applications, but Git seems to check the status of a temporary commit message file, which bypasses this limitation. In general, it is a good practice to export VISUAL='mvim -f'to ensure MacVim will not forka new process when called, which should give you what you want when using it with your shell environment.

另外,如果你想使用 MacVim(或 GVim)作为$VISUALor $EDITOR,你应该知道默认情况下 MacVim 会从父进程 fork 一个新进程,导致 MacVim 返回值没有到达父进程。这可能会混淆其他应用程序,但 Git 似乎会检查临时提交消息文件的状态,从而绕过了此限制。通常,export VISUAL='mvim -f'确保 MacVim在调用时不会派生新进程是一个很好的做法,这应该会在您的 shell 环境中使用它时提供您想要的东西。

回答by gcb

If you already have macVim installed: /Applications/MacVim.app/Contents/MacOS/Vim -gwill give you macVim GUI.

如果你已经安装了 macVim:/Applications/MacVim.app/Contents/MacOS/Vim -g会给你 macVim GUI。

just add an alias.

只需添加一个别名。

i use gvimbecause that is what i use on linux for gnome-vim.

我使用gvim因为那是我在 linux 上用于 gnome-vim 的东西。

alias gvim='/Applications/MacVim.app/Contents/MacOS/Vim -g'

alias gvim='/Applications/MacVim.app/Contents/MacOS/Vim -g'

回答by ccerhan

Assume MacVim is installed in the Application folder.

假设 MacVim 安装在 Application 文件夹中。

Instead of adding MacVim path to your environment, create a link by typing this in terminal:

不要将 MacVim 路径添加到您的环境中,而是通过在终端中键入以下内容来创建链接:

sudo ln -s /Applications/MacVim.app/Contents/bin/mvim /usr/local/bin/mvim

sudo ln -s /Applications/MacVim.app/Contents/bin/mvim /usr/local/bin/mvim

Then, open a new terminal window/tab and type mvim.

然后,打开一个新的终端窗口/选项卡并输入mvim.

回答by Muhammad Reda

If you have homeBrewinstalled, this is all you have to do:

如果您安装了homeBrew,您只需执行以下操作:

brew install macvim
brew linkapps

Then type mvimin your terminal to run MacVim.

然后输入mvim你的终端来运行 MacVim。

回答by Douglas

Here's what I did:

这是我所做的:

After building Macvim I copied mvim to one of my $PATH destinations (In this case I chose /usr/local/bin)

构建 Macvim 后,我将 mvim 复制到我的 $PATH 目的地之一(在这种情况下,我选择了 /usr/local/bin)

cp -v [MacVim_source_folder]/src/MacVim/mvim /usr/local/bin

Then when you invoke mvim it is now recognised but there is an annoying thing. It opens the visual MacVim window, not the one in terminal. To do that, you have to invoke

然后当您调用 mvim 时,它现在可以识别,但是有一件烦人的事情。它打开可视化 MacVim 窗口,而不是终端中的窗口。为此,您必须调用

mvim -v

To make sure every time you call mvim you don't have to remember to add the '-v' you can create an alias:

为确保每次调用 mvim 时不必记得添加“-v”,您可以创建别名:

alias mvim='mvim -v'

别名 mvim='mvim -v'

However, this alias will only persist for this session of the Terminal. To have this alias executed every time you open a Terminal window, you have to include it in your .profile The .profile should be in your home directory. If it's not, create it.

但是,这个别名只会在终端的这个会话中持续存在。要在每次打开终端窗口时执行此别名,您必须将其包含在 .profile 中。.profile 应位于您的主目录中。如果不是,请创建它。

cd ~
mvim -v .profile

include the alias command in there and save it.

在那里包含别名命令并保存它。

That's it.

而已。

回答by OscarRyz

I'm adding Bard Park's comment here for that was the real answer for me:

我在这里添加巴德公园的评论,因为这对我来说是真正的答案:

Since mvim is simply a shell script, you can download it directly from the MacVim source at GitHub here: http://raw.github.com/b4winckler/macvim/master/src/MacVim/mvim

由于 mvim 只是一个 shell 脚本,您可以直接从 GitHub 上的 MacVim 源下载它:http://raw.github.com/b4winckler/macvim/master/src/MacVim/mvim

回答by ianmjones

I'd seriously recommend installing MacVim via MacPorts(sudo port install MacVim).

我强烈建议通过MacPorts( sudo port install MacVim)安装 MacVim 。

When installed, MacPorts automatically updates your profile to include /opt/local/bin in your path, and so when mvim is installed as /opt/local/bin/mvim during the install of MacVim you'll find it ready to use straight away.

安装后,MacPorts 会自动更新您的配置文件以在您的路径中包含 /opt/local/bin,因此当在 MacVim 安装过程中将 mvim 安装为 /opt/local/bin/mvim 时,您会发现它可以立即使用.

When you install the MacVim port the MacVim.app bundle is installed in /Applications/MacPorts for you too.

当您安装 MacVim 端口时,MacVim.app 包也会为您安装在 /Applications/MacPorts 中。

A good thing about going the MacPorts route is that you'll also be able to install git too (sudo port install git-core) and many many other ports. Highly recommended.

使用 MacPorts 路线的一个好处是,您还可以安装 git ( sudo port install git-core) 和许多其他端口。强烈推荐。