Uninstalled MacVim, now can't use regular Vim? - vim

I got a new machine at work. The previous developer had macvim installed. When typing 'vim' in the terminal, the macvim program would open. I uninstalled macvim because I don't use it. Now when I type 'vim' in the terminal, it says, "Sorry, cannot find MacVim.app." I want to just run vim in the terminal. Is this an alias or something? How can I quickly fix!

you can enter this into the terminal:
which vim
alias
to see info about defined aliases and what happens when you try to run vim

The previous user installed the mvim script that comes with MacVim somewhere in the $PATH or elsewhere and probably symlinked it or created an alias.
To get rid of that behaviour, try the following:
look into your ~/.bashrc or whatever if there's an alias that point at mvim
look everywhere in your $PATH for a mvim script, maybe
$ which mvim
will do
make sure /usr/bin/vim is a real Vim executable and not a symlink with this command
$ file /usr/bin/vim
If it's symlinked then you have trouble, If it's only an alias simply remove it. If you don't want to mess around too much, you can add an alias to /usr/bin/vim in your ~/.profile or whatever.
Whatever you do, I'd recommend you to re-install MacVim as it is a lot better than the default Vim in almost every way.

Is there still a file here: /usr/bin/vim ?
If that got deleted, then you'll need to reinstall vim.
I suggest using Link as your package manager

Related

open vim file in new unix terminal

How to open existing vim file from unix shell (bash) in new terminal (not in same/new tab of existing terminal) on local machine ?
Also is there any way to split file on new terminal (not in same/new tab of existing terminal) from inside vim ?
How to open a new terminal is platform dependent; This doesn't really have a whole lot to do with vim itself.
For example, if you're using GNOME you could do this by running gnome-terminal -e "vim $filename" & disown. Look up the documentation for the terminal emulator you're using to find out how to launch a new terminal and execute commands in it.
Another (IMHO much better) solution is to simply use GVim for situations like these, unless you have a very good reason to run vim in the terminal (if you're running this over ssh this won't work anyway, in that case you're better off using a terminal multiplexer like screen or tmux).
PS: bash isn't a terminal (emulator); bash is a shell. If you just run a new instance of bash it'll run in the same terminal, which is not what you want here.
Try this:
vim [your file]
If this isn't working for you, make sure you have it installed with:
sudo apt-get install vim
If you're already IN vim do
:edit [your file]

How to make terminal recognize command "gvim" or "mvim"?

I am not sure I understand correctly from the readme file how to install vim onto my mac. After installation, I still cannot seem to open files while typing gvim HelloWorld.c into terminal. How can I permanently fix the gvim command for terminal to recognize all the time?
Mac OS X already ships with a slightly underpowered but perfectly working vim build so you only have to issue that command in your terminal:
$ vim filename
MacVim is a more featureful version that comes with a GUI and a CLI executable. Is that what you installed?
The archive you downloaded contains MacVim.app and a shell script called mvim.
If you don't plan to use Vim in or from your terminal, you don't need that mvim script at all.
If you do, the simplest solution is to put that script somewhere in your $PATH. To do so, check the value of $PATH with the following command:
$ echo $PATH
and copy the script into one of the listed directories:
$ cp /path/to/mvim /some/directory/mvim
After that's done, you can call the MacVim GUI from your terminal with:
$ mvim filename
or the MacVim CLI with:
$ mvim -v filename

vim in screen: vim does not highlight syntax when I'm in a screen session

I cannot see any syntax highlighting in any language (e.g. python, c++ and sh) when I use vim within a screen session. The line numbers are in color though.
I precise that my terminal (in screen too) is able to show 256 colors schemes (I tested with the 256colors perl script found here: http://frexx.de/xterm-256-notes/ ).
How can I fix that?
OK, here is the issue/solution:
I used to call vim by using $vi, indeed:
$ which vi
alias vi='vim'
/usr/bin/vim
But:
$ screen
$ which vi
/bin/vi
I just learnt that screen doesn't load this system level alias which is tricky.
I had this problem. In my case, I was running a version of screen from brew. brew doesn't use ~/.screenrc as its startup file. So there's two solutions to this.
1) Set your term in the screenrc that brew_screen is expecting. This might be /opt/etc/screenrc. I didn't try this method, so I'm not sure.
2) Make an alias for screen that sets the term to what you want it to be. In this case, screen-256color is sufficient. I added the following line to my bash_profile, which is symlinked to my bashrc (mac problems):
alias screen='screen -T screen-256color'

$PATH in vim is different from which in shell? (Mac OSX)

As you know that the ctags in OSX is a basic version, and I install a full version of ctags using homebrew, but when I wanna use it in Vim's command mode, it always ran the basic one. So I checked the $PATH var in Vim's command mode, like !echo $PATH, and it showed that /usr/local/bin followed the /usr/bin, which was different from the shell environment $PATH, so please kindly tell me how to fix this, many thanks!.
BTW, I changed the $PATH in vimrc file, but it only affected the $PATH if I type the command echo $PATH in Vim's command mode, not !echo $PATH.
Unfortunately, MacVim won't be affected by paths you set in .profile or .bashrc.
You can set paths affecting all programs on Mac OS X by using the /etc/paths and /etc/paths.d/ mechanisms. More detailed explanation here:
https://serverfault.com/questions/16355/how-to-set-global-path-on-os-x

How can I get vim to point to macvim? Where can I find macvim?

I would like vim to point to macvim :)
Probably through an alias.
vim is here: whereis vim
/usr/bin/vim
macvim I can't find, e.g.
whereis macvim returns nothing
The MacVim distro comes with a script called mvim that takes exactly the same arguments as vim. Put mvim somewhere in your path. Then, just set the alias: alias vim='mvim'
If you want to completely override the system vim, an easy way is to use Homebrew. Just install MacVim with $brew install macvim --override-system-vim. The --override-system-vim flag will create mvim symlinks to vi, vim, etc. You may find it a cleaner way to achieve the same goal. Plus, I prefer to use Homebrew as a package manager.
EDIT: Since you say you don't know where MacVim is, you may just want to download the latest tarball for your system and start from scratch. There are three files: the MacVim application, the mvim script, and a README.
Put MacVim in your Applications folder. Put mvim somewhere in your path.
Going forward, you should look for mvim using which rather than whereis. E.g. $which mvim #=> /usr/local/bin/mvim
which returns the pathnames of the files which would be executed in the current environment. whereis checks the standard binary directories, and may miss files included in your personal path.
Alternately, use Homebrew, as I suggest above and it will manage the location of both files.
My answer is kind of the opposite of michaelmichael's and I've made it quite a few times:
MacVim comes with a CLI executable that you can use in place of Mac OS X's default Vim if you add a single alias to your ~/.bashrc/~/.profile. No need to compile anything, no need to put MacVim in a special place, no need to overwrite default programs with symlinks
This way, you can stay in CLI-land and enjoy the power of a powerful/recent/fast Vim.
EDIT
MacVim is a native Mac OS X GUI version of Vim. It doesn't come preinstalled with your OS so you have to download it from the Internet or install it through homebrew (see michaelmichael's answer). Once it's installed, MacVim is where you have put it, plain and simple.
Because it's a full fledged GUI app, MacVim can't really be used as a drop-in replacement for the default Vim in the terminal.
`$ MacVim file.txt` will not work. `$ open -a macvim file.txt` will not work either.
You basically have two options: use the mvim CLI wrapper to open MacVim from the terminal or use an alias to MacVim's bundled CLI executable.
The mvim wrapper
I think michaelmichael's answer could be a expanded a bit but the most important is said.
EDIT: well scratch that.
The bundled CLI executable
Just add this line (customized to reflect your system) to your ~/.bashrc or ~/.profile or whatever file is run by your shell at startup:
alias vim='/path/to/MacVim.app/Contents/MacOS/Vim'
Open a new terminal window, $ vim file.txt should launch vim in your terminal window, just like the default /usr/bin/vim but with a lot more bells and whistles.
After installing mvim, you can find where it is located with typing into terminal:
which mvim
On my system this gave me:
/usr/local/bin/mvim
Then you create an alias in .bash_profile by typing the following in your terminal, and hit enter:
echo alias vim='/usr/local/bin/mvim' >> .bash_profile
Restart your terminal and try typing:
vim .
This should launch mvim and not vim

Resources