'How can I turn off vim in terminal of Mac?

I was trying to setup Mongo DB Community on my Mac(m1). I installed Home-brew first and followed the install instruction of the Mongo DB. However I could not run the command brew and I found that it was the problem that I didn't set up the Path in the zshell. So I tried it with my terminal but It just got stuck in this here. I tried to escape it with the :wq, :q! commands and it works. but whenever I restart the terminal it goes right back to this screen not to main screen. How can I solve this problem? plz help :( (Im trying to learning so I'm not familiar with the terminal and codes stuffs)

enter image description here



Solution 1:[1]

You are in this situation because you typed the wrong command in the terminal and I suspect it is because you copy-pasted it instead of typing it out.

Your command is helpfully spelled out in the title bar of the window:

$ vi ~/.zshrcexport PATH=/opt/homebrew/bin:

Judging by the content of the buffer, it is almost certainly truncated and the actual command was probably:

$ vi ~/.zshrcexport PATH=/opt/homebrew/bin:$PATH

So what's wrong with that command? Everything, actually.

  • For starter, it should have been:

    $ vi ~/.zshrc
    

    with ~/.zshrc being your shell's main configuration file.

    Everything after that shouldn't be here.

  • Vim, which is the program providing the vi command, takes one or more filenames as arguments. With that command, you told Vim to open two files:

    ~/.zshrcexport
    PATH=/opt/homebrew/bin:$PATH
    
    • the former is the one shown in your screenshot,
    • the latter is not shown but it is likely to have a rather long name,
    • neither of those files are supposed to exist.

How to get out of that mess?

  • Assuming you are in the situation shown by that screenshot, do the following:

    1. Press the esc key to make sure you are in what is called "normal mode" in Vim.
    2. Press the : key to enter "command-line mode".
    3. Type qa!, then press the return or ?? key.
  • At that point you should be outside of Vim and in your shell. It is time to delete the non-wanted files you created with these two commands, each followed by a press on the return or ?? key:

    $ rm ~/.zshrcexport
    $ rm PATH=/opt/homebrew/bin:$PATH
    
  • Now you should finally be able to edit your shell's configuration file but I recommend you don't do it with the vi command. nano is a much simpler editor that doesn't require as much learning.

    1. Open the configuration file in nano with:

      $ nano ~/.zshrc
      
    2. Move around with your cursor keys until you find the right spot, just like in a regular text editor. The file is probably empty anyway.

    3. Type that "export" line:

      export PATH=/opt/homebrew/bin:$PATH
      
    4. Press control+X to quit, as instructed at the bottom of the screen.

    5. Press the appropriate key when asked if you want to write the file.

  • Avoid vi or vim in the future until you actually have or want to learn it.

As for why you end up in Vim when you open a new terminal window I have no clue. Maybe another one of your mistakes?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 romainl