Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

selfish question here: Does anybody know how to setup vim so that :! recognises aliases?

something like...

  set shellcmdflag=-O\ expand_aliases\ -c


Your aliases are generally sourced from your shell rc file (ie ~/.bashrc). Not sure how vim launches the shell to run ex shell commands but in the interest of portability it's probably just sh with no rc files loaded. This is probably configurable. Try :help shell or :help :! (I'm not at a terminal so not sure what you'll find)


By default, Bash, Zsh, and other shells don't source the shell config when started with -c (because it's considered a non-interactive session). For Bash & Zsh, you can force .bashrc/.zshrc to load by adding -i to 'shellcmdflag'.


I believe that vim sources env files rather than rc. For example, any aliases placed in my zshenv are available in vim but those in zshrc are not. I would imagine that applies to other shells as well.


Zsh always source zshenv, regardless of login/interactive options. AFAIK, Bash has no equivalent.


I always start vim from within xterm (bashrc has already run and aliases are already set up). It just works. I can use :!ll (or ctrl-z and 'll' in the sub-shell) and it just works.

Not sure why it wouldn't for you.


ctrl-z doesn't start a sub-shell, it backgrouns vim and returns you to the parent shell.

And maybe he's running gvim or from a login shell that hasn't sourced his bashrc.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: