Mvim solution is not available in Mac Terminal

Source: Internet
Author: User

For everyone, there will be a special favorite editor. For many people who love Unix/linux, Vim/vi must be familiar with the "editing weapon".

Of course, for Mac users, there is certainly no shortage of vim enthusiasts. Fortunately, VIM provides a standalone application Macvim for Mac users.

As a Unix-derived system, MacOS naturally supports the user interacting with the OS through the shell, and therefore introduces the issue to be discussed: Under Mac Terminal, enter Macvim Start command Mvim but cannot start Macvim.

First, consider the differences between the Macvim standalone application and the vim that comes with the Mac Terminal:

    1.MacVim is a typical GUI Vim (Gvim) under Mac, which provides a better editing interface without having to be constrained to the configuration file of Mac terminal (including color matching, window size)

2.MacVim when used, is to open a new window independently, rather than like the terminal Vim, occupy the Terminal interface window (of course, through the MacOS Cmd+t shortcut can also create a new terminal tab, switching process just ctrl+tab switch tab, This also seems to make vim editing files appear more intuitive at the end of the terminal.

3.MacVim If you leave the terminal to use (each time you click on the Macvim app to start, and enter the path of the file to be edited), it will become lost its speed, although MacOS can let you drag any file to Macvim to achieve the Macvim to edit the file, But this seems to be to some extent contrary to the use of vim "Beginner's Mind" (Vim in my eyes, is to let people out of the mouse, only by the keyboard to edit everything)

As a result, we need to make the Macvim as fast and easy as vim at the end of the terminal, and let Macvim really start its own application. This is the best explanation for the Mvim command after installing Macvim.

However, under my terminal, after installing Macvim, the Mvim command does not work, as shown below:

1. Copy Mvim to/usr/local/bin/directory, restart Bash, still unable to use Mvim, error "Sorry, cannot find Vim executable."

2. Copy the Mvim to the/usr/bin/directory (related to Apple's rootless control mechanism introduced in MacOS Update, how to dismiss please consult other blogs), unable to use Mvim, report the same error

3. Execute the Mvim edit file by entering the full path (/applications/macvim.app/contents/bin/mvim) of the Mvim executable file, which is possible

Of course, consulted several how to solve 1, 2 of the error of the blog, but the feeling of controversy ... So, consider yourself writing an intermediate program like parse command to help execute the mvim command

Since it is already possible to execute through the Mvim full path, it is very painful to enter the full path each time, so consider using a program to help enter these strings.

So, you can write a C program to achieve (for the moment, this program is called Gvim):

So, through this code can be seen, in the input $ gvim file1.txt file2.txt ... After that, you can let the shell parse the command into the Gvim program, the Gvim program will "stitch" the files represented by these strings "Mvim" the full path, and then through the UNIX system function to invoke the execution of this complete command: $/applications/ Macvim.app/contents/bin/mvim file1.txt file2.txt ...

This is the realization principle of gvim, which is the idea of the whole design process.

But!!! This program is still problematic, such as I am in a directory containing 20+ Java source files, input command $gvim *.java to edit these Java files, then because the length of gvim.c cmd is limited, at this time the shell can only feedback information: " Abort trap:6 "(array out of bounds), which is naturally certain, the length of my full command exceeds the limit length of 180.

In this case, the classic C/C + + problem is returned, the memory allocation for arrays is fixed (just the way to declare an array to allocate memory, not the malloc, calloc functions), then how to assign the appropriate length to a string to ensure that it can include all the command characters I want to enter, And can not consume too much memory.

Naturally, I think of C + + 's string! (Don't mention Java ...) After all, the shell is involved, professional face)

Then there is the C + + version of Gvim:

  Here, std::string is used to construct the string, call its Append method to implement stitching, and call the Std::string.c_str () function to implement std::string conversion to a const char * type ( Because the system has strict requirements for its incoming parameters as a const char * type, the "full command of the input" is resolved because of the flexibility of the std::string (the length change is determined by the incoming string).

At this point, you can use $ gvim to replace the $ mvim. Although not fundamentally solve the problem, but ultimately by the knowledge learned to achieve the goal!

Test results are released below:

 

Okay, get it done!

I hope this article will be able to configure the Mvim path to the head of the big friends, a simple solution to the idea.

Remember today this is a special day, I feel the fragrance of the single dog is more rich ...

Edited on 2018.5.20

Mvim solution is not available in Mac Terminal

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.