How do I get autochdir to work on a Mac when running Vim from the terminal? - macos

In MacVim autochdir works without a problem. However, lately I've been running iTerm2 (full screen with split) for coding and the lack of autochdir is really bothering me. Any solutions? Thanks.

What do you mean by "the lack of autochdir"? It works fine both in CLI and in GUI.
If you have set autochdir in your ~/.vimrc this feature will work the same way whether you are in MacVim or iTerm2 or Terminal or whatever.
But I suspect you are changing dirs in an iTerm2 split and expecting Vim to somehow learn about that change and change its pwd accordingly. Am I right? "Unfortunately" Vim doesn't know about the second iTerm2 split and can't react to your cd there.

In the terminal:
> which vim
If it says /usr/bin/vim, you're using the mac base installation. This is an old version of vim and doesn't support autochdir. You'll need a newer version.
Check if you have another installation of vim by running:
> /usr/local/bin/vim
If so, add /usr/local/bin to your $PATH before /usr/bin
If not, install it:
> brew install vim

Related

Why shell always execute vim in /usr/bin rather than vim in /opt/homebrew/bin?

I don't want to use the vim bundled on the macOS, so I download new vim using homebrew.
My environment variable PATH is set as follows:
/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin. The vim downloaded using brew in in /opt/homebrew/bin, and vim bundled with macOS is in /usr/bin. However, when I input vim on the shell, it always execute /usr/bin/vim(i.e. the vim bundled with macOS).
Does anyone know how to solve this or what is the reason for this circumstance? Very appreciate any help.
Oh! I know why is that. After installing new vim using brew, we need to reboot the terminal. I know this because I I accidentally shut down the terminal, then I open the terminal and find the vim in /opt/homebrew/bin can be executed when I input vim in the shell.
For beginners, this is a difficult problem to find the reason. I solved this problem myself, hoping to help people who encounter the same problem

Update OSX Vim using MacVim

I'm trying to update Vim (for use in Terminal) on my Mac. It's currently running version 7.3, but YouCompleteMe requires Vim 7.3.584, and won't run even though it's installed.
I've tried using a Vim alias in my .bash_profile:
alias vim='/Users/Conor/Applications/MacVim.app/Contents/MacOS/Vim'
However none of my Vim plugins are launched when I run Vim like this, any my vimrc file isn't recognised either.
How can I get this alias to recognise my existing Vim settings? Or is there a better way of upgrading Vim for mac?
The *.tbz that you downloaded from the official page contains a mvim script.
Once you have moved that script somewhere in your $PATH you can start the MacVim GUI like this:
$ mvim filename
and the MacVim CLI like that:
$ mvim -v filename
From there the only thing you need is to change your alias to point to mvim:
alias vim='mvim -v'
The original built-in Vim and its runtime files stay untouched, MacVim uses its own runtime files located in the MacVim.app bundle and both honor your personal config (assuming they are located where they should be: ~/.vimrc and ~/.vim/).
Quick, clean and painless.
If you installed MacVim with HomeBrew you can use
brew install macvim --override-system-vim
If you just want pure vim with python support do:
brew install vim --override-system-vim --HEAD
I had the same issue as you, but this worked like a charm. You complete me works perfectly after this.

Homebrew version of vim won't open files

I installed vim via brew so I could have the latest version (7.4) and get syntax highlighting for Clojure. No big deal. Unfortunately, the brew version of vim seems to be broken on my system. I also aliased the vim command:
brew install vim # Install went successfully
alias vim=/usr/local/Cellar/7.4.052/bin/vim # Shouldn't be any problems here
When I open the brew version of vim, it fails to load any of my plugins (I use spf13) throwing a bunch of "Undefined variable" and "Invalid expression", etc errors for every plugin in my bundle directory; I just hit enter to continue. My .vimrc loads properly. When I open a file, it opens two tabs, both blank. One is a new file, the other is the file I tried to open, except there's nothing in it.
Potentially useful information: echo $VIM returns an empty line, while echo $ZSH returns /User/bsima/.dotfiles as expected.
Here are my dotfiles, but I don't think the problem lies in those configuration files.
Is this a known bug? Or is something wrong with my vim install?
I have no idea what's going on and I really miss my vim :( As good as Textmate is, I can't be without vim forever.
Edit: MacVim, installed via Homebrew, kinda works. It still opens 2 tabs on startup, but it does open files for editing and saves.
I found the problem: it was with my spf13 vim config. The following commands fixed the issue, in addition to double-checking that symlinks such as ~/.vim and ~/.vimrc were correct:
> which vim # This should output /usr/local/bin/vim since I'm using Homebrew
/usr/local/bin/vim
> cd ~/.spf13-vim-3
> ./bootstrap.sh # Basically re-installs spf13

Run gedit on OSX Mavericks?

The Version of Gedit on the gnome.org site does not seem to run on OSX Mavericks. Is there any way to fix this?
When I tried it, the problem was the version of libxml2 packaged with gedit.
Use the command "brew install libxml2"
then cp /usr/local/Cellar/libxml2/2.9.1/lib/libxml2.2.dylib /Applications/gedit.app/Contents/Resources/lib/.
In the current version of brew, the directory has changed to 2.9.2 so:
then cp /usr/local/Cellar/libxml2/2.9.2/lib/libxml2.2.dylib /Applications/gedit.app/Contents/Resources/lib/.
Having MacPorts installed and comments from above I was able to simply rm /Applications/gedit.app/Contents/Resources/lib/libxml2.2* and it used the system/macports library instead of the bundled one without error.
Just to Revise:
Having macports installed correctly. (If you just updated from e.g. OSX Lion you need to migrate macports to your new Maverics OSX System, https://trac.macports.org/wiki/Migration)
Downloading gedit-3.2.6-3
sudo port install libxml2
and rm /Applications/gedit.app/Contents/Resources/lib/libxml2.2*
Open gedit and start Coding!
For my 13-inch, Early 2011 Macbook pro it worked just fine.
--
If you want to use gedit from Terminal:
add
alias gedit="open -a gedit"
to
~/.bash_profile
Gedit 2.30.2 works.
But your own plugin won't work on Gedit 2.30.2.
I dont know what your goal is, but i found a easier way with another program. If installing all of this starts to get tiersome (that's what i figured out at least, since xcode needed downloading and tampering), i found sublime text 2 to work very nicely.
I found that the version of "libxml2.2.dylib", distributed with Gedit 3.2.6 is outdated.
Install "Xcode" from the App Store (if you have not already done so), then:
$ cp -p /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib/libxml2.2.dylib /Applications/gedit.app/Contents/Resources/lib/libxml2.2.dylib
One solution (I'm still interested in others) is the following:
The latest version of Gedit (3.2.6-3)for OSX on the Gnome.org website crashes.
The older Gedit 2.30.2 still runs.
try version 2.26.3 of Gedit – it’s working for me on MOJAVE !
http://ftp.gnome.org/pub/GNOME/binaries/mac/gedit/2.26/
Darek
If I am guessing correctly, your aim is a GUI Text editor for convenience.
open /path/to/file
performs the same action as of double clicking on the file from Finder
Also if you want to use it with a specific application like sublime text
open -a 'Sublime Text' /path/to/file

Compiled vim from source on Mac OSX and getting 'shell returned 127' error?

On my Mac OSX 10.6 machine, I started to use MacVIM for vim. Then I noticed my terminal version was different to the MacVIM version (MacVIM was 7.3 and my terminal version 7.2)... I thought they used the same vim?
I need 7.3 for some of the features. So I set about wanting to update the terminal version. I basically cloned it using Mercurial (the perferred way according to the official site) and then did the usual to compile it. This did work and I now have 7.3 in my terminal. But, on some commands when exiting, I can this error:
/bin/bash: q: command not found
shell returned 127
Press ENTER or type command to continue
...I've tried my hardest to try and fix this problem, but trying to reinstall MacVIM, deleting the vim in my /usr/local/bin and compiling again and I just can't get rid of this annoying error.
Can anyone possibly help me? Am I doing this all wrong? ...most of the time I will be using MacVIM, but it'd be nice for me to have it in the Terminal - exactly how I'd have it on my Ubuntu servers.
Any help would be fantastic!
:!q is not :q!. This is probably not a bug.
The error message you're seeing is is most likely the result of accidentally typing :!q instead of :q!, which would be user error, not a bug. :!q shells out to run q, and your shell (bash) is not finding such a command and bails with 127. (For comparison, you might try :!true, :!false, :!vim %, to get a feel of this.)
There isn't really a “fix” for this, and ! is really useful for other purposes; maybe with more practice you'll make the typo less often. You could also try using ZQ instead of :q!; this has other disadvantages (a typo ZZ will instead save the file if it's edited, and ZQ specifically is a vim extension), but at least you see this error again.
The upshot here is basically check to make sure you typed in your commands right, I guess.
I'm not sure on the exact path, but somewhere a few folders deep into the Applications/MacVim.app folder is the vim executable that will also run in a terminal (Use the -g option to launch it in GUI mode).
You should be able to throw this in your .bashrc:
alias vim=/Applications/MacVim.app/Contents/MacOS/vim
This is the homebrew formula for vim. Try these settings for "configure" or just install homebrew and install vim from there.
system "./configure", "--prefix=#{prefix}",
"--mandir=#{man}",
"--enable-gui=no",
"--without-x",
"--disable-nls",
"--enable-multibyte",
"--with-tlib=ncurses",
"--enable-pythoninterp",
"--enable-rubyinterp",
"--with-features=huge"
system "make"
system "make install"

Resources