Mac Questions

classic Classic list List threaded Threaded
31 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Mac Questions

Brett Calcott-2
Hi all,

I have just got a Macbook (switching from windows) and have downloaded
and compiled the latest version of Vim on it. It all works fine, but I
have a few questions.

1. How do I distinguish between the command line and gui versions.
Both appear to respond 'True' to has("gui"). Is there another feature
that I should be looking for.

2. Where does the gui version get its initial environment from? I want
to add some extra stuff to PATH. I know I can do this using $PATH in
the .vimrc, but I would rather do it at some global level.

Thanks for any aid,
Brett
Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

A.J.Mechelynck
Brett Calcott wrote:
> Hi all,
>
> I have just got a Macbook (switching from windows) and have downloaded
> and compiled the latest version of Vim on it. It all works fine, but I
> have a few questions.
>
> 1. How do I distinguish between the command line and gui versions.
> Both appear to respond 'True' to has("gui"). Is there another feature
> that I should be looking for.

Many non-Windows versions of GUI-enabled Vim can also run in console mode. The
"classical" way for a script to determine whether it is being sourced by gvim
or by Console Vim is to check has("gui_running").

>
> 2. Where does the gui version get its initial environment from? I want
> to add some extra stuff to PATH. I know I can do this using $PATH in
> the .vimrc, but I would rather do it at some global level.
>
> Thanks for any aid,
> Brett
>

I don't know the answer to this one, except that it gets its environment the
same way as any other program. If Mac is sufficiently similar to Linux (both
are Unix-like OSes after all) non-login shells may get it from shell-specific
files like ~/.bashrc, ~/.cshrc, etc. (For details,see the manpage for your
shell.) (Note: Files whose names start with a dot are normally not listed in
directory listings. Use "ls -a" (possibly with other options) to make them
appear.)


Best regards,
Tony.
Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

Brett Calcott-2
> >
> > 1. How do I distinguish between the command line and gui versions.
> > Both appear to respond 'True' to has("gui"). Is there another feature
> > that I should be looking for.
>
> Many non-Windows versions of GUI-enabled Vim can also run in console mode.
> "classical" way for a script to determine whether it is being sourced by gvim
> or by Console Vim is to check has("gui_running").

Yay! Thanks for that Tony.



> > 2. Where does the gui version get its initial environment from? I want
> > to add some extra stuff to PATH. I know I can do this using $PATH in
> > the .vimrc, but I would rather do it at some global level.
> >
> I don't know the answer to this one, except that it gets its environment the
> same way as any other program. If Mac is sufficiently similar to Linux (both
> are Unix-like OSes after all) non-login shells may get it from shell-specific
> files like ~/.bashrc, ~/.cshrc, etc. (For details,see the manpage for your
> shell.) (Note: Files whose names start with a dot are normally not listed in
> directory listings. Use "ls -a" (possibly with other options) to make them
> appear.)
>

I thought the same thing. But it does not appear to source my
.bash_profile or .bashrc.

Anyone out there got some clues...?

Thanks
Brett
Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

A.J.Mechelynck
Brett Calcott wrote:

>> >
>> > 1. How do I distinguish between the command line and gui versions.
>> > Both appear to respond 'True' to has("gui"). Is there another feature
>> > that I should be looking for.
>>
>> Many non-Windows versions of GUI-enabled Vim can also run in console
>> mode.
>> "classical" way for a script to determine whether it is being sourced
>> by gvim
>> or by Console Vim is to check has("gui_running").
>
> Yay! Thanks for that Tony.
>
>
>
>> > 2. Where does the gui version get its initial environment from? I want
>> > to add some extra stuff to PATH. I know I can do this using $PATH in
>> > the .vimrc, but I would rather do it at some global level.
>> >
>> I don't know the answer to this one, except that it gets its
>> environment the
>> same way as any other program. If Mac is sufficiently similar to Linux
>> (both
>> are Unix-like OSes after all) non-login shells may get it from
>> shell-specific
>> files like ~/.bashrc, ~/.cshrc, etc. (For details,see the manpage for
>> your
>> shell.) (Note: Files whose names start with a dot are normally not
>> listed in
>> directory listings. Use "ls -a" (possibly with other options) to make
>> them
>> appear.)
>>
>
> I thought the same thing. But it does not appear to source my
> .bash_profile or .bashrc.
>
> Anyone out there got some clues...?
>
> Thanks
> Brett
>

If you type "echo $SHELL" (without the quotes) at the Terminal app
command-line, what is the answer?


Best regards,
Tony.
Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

Brett Calcott-2
> >
>
> If you type "echo $SHELL" (without the quotes) at the Terminal app
> command-line, what is the answer?
>
>

/bin/bash for both gui and command line versions.


Brett
Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

A.J.Mechelynck
Brett Calcott wrote:

>> >
>>
>> If you type "echo $SHELL" (without the quotes) at the Terminal app
>> command-line, what is the answer?
>>
>>
>
> /bin/bash for both gui and command line versions.
>
>
> Brett
>

Hm, then let's wait and see what the Mac guys have to say.


Best regards,
Tony.
Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

Kev-13
In reply to this post by Brett Calcott-2
I believe both versions of Vim get its initial info from ~/.bashrc.
In my ~/.vimrc I have the following entry:

" make sure Vim uses the bash shell
set shell=bash

Which verion(s) are you using?  I have OS X 10.4.8 and the command  
line version of Vim is 6.3.82.
The GUI version is 7.0.  Other than some goofy font issues, the GUI  
version is more useful and has some rather nice features (tabs for  
one) that aren't available in the earlier command line version.

Kevin


On Jan 8, 2007, at 1:42 AM, Brett Calcott wrote:

> Hi all,
>
> I have just got a Macbook (switching from windows) and have downloaded
> and compiled the latest version of Vim on it. It all works fine, but I
> have a few questions.
>
> 1. How do I distinguish between the command line and gui versions.
> Both appear to respond 'True' to has("gui"). Is there another feature
> that I should be looking for.
>
> 2. Where does the gui version get its initial environment from? I want
> to add some extra stuff to PATH. I know I can do this using $PATH in
> the .vimrc, but I would rather do it at some global level.
>
> Thanks for any aid,
> Brett
>

Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

Alan G Isaac
In reply to this post by Brett Calcott-2
On Mon, 8 Jan 2007, Brett Calcott apparently wrote:
> I have just got a Macbook (switching from windows) and
> have downloaded and compiled the latest version of Vim on
> it. It all works fine, but I have a few questions.

Would you mind outlining the steps you took for someone who
is making the same transition but is not used to compiling
their own apps? (I have XCode installed.)

Thank you,
Alan Isaac




Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

Axel Kielhorn
In reply to this post by Kev-13

Am 08.01.2007 um 13:26 schrieb striker:

> I believe both versions of Vim get its initial info from ~/.bashrc.

Well, actually they get the environment from the shell that starts Vim.

When you start Vim from the bash, it will inherit the environment.
When you start Vim from the Finder (or the Dock) it will only have a
minimal environment.

> Which verion(s) are you using?  I have OS X 10.4.8 and the command
> line version of Vim is 6.3.82.

This seems to be the Vim provided with Mac OS. It was 6.3 in MacOS 10.3

> The GUI version is 7.0.  Other than some goofy font issues, the GUI
> version is more useful and has some rather nice features (tabs for
> one) that aren't available in the earlier command line version.

You can this version in the command line as well, I have
alias vim="~/src/Vim/vim70/src/darwin7.9/Vim.app/Contents/MacOS/Vim"
alias gvim="~/src/Vim/vim70/src/darwin7.9/Vim.app/Contents/MacOS/Vim -g
&"
in my .bashrc.

>> 2. Where does the gui version get its initial environment from? I want
>> to add some extra stuff to PATH. I know I can do this using $PATH in
>> the .vimrc, but I would rather do it at some global level.

I don't know how to extend the environment of the Finder, but maybe you
can write an automator script to call Vim from a bash.

Axel

PS: I cc'ed this to the Mac list as well.

Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

Mikołaj Machowski
In reply to this post by Brett Calcott-2
On pon sty 8 2007, [hidden email] wrote:
> I thought the same thing. But it does not appear to source my
> .bash_profile or .bashrc.
>
> Anyone out there got some clues...?

/etc/profile
/etc/bashrc

?

This will be global for all users (if working :)).

m.

Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

Brett Calcott-2
In reply to this post by Axel Kielhorn
This does seem to be the case. No amount of fiddling with .profile
.bashrc .bash_profile /etc/bashrc or whatever makes any difference to
the environment that ends up in the GUI version that is started from
the dock.

For the moment I just do something like this:
if has("gui_running")
  let $PATH=$PATH.':/some/more/paths:/and/more/still'
endif

Which does the trick for now.

>
> PS: I cc'ed this to the Mac list as well.
>
>

Thanks for that. I probably should have started there...

Thanks for the replies.
Brett
Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

Dave Land
Hello,

On Jan 8, 2007, at 2:31 PM, Brett Calcott wrote:

> This does seem to be the case. No amount of fiddling with .profile
> .bashrc .bash_profile /etc/bashrc or whatever makes any difference to
> the environment that ends up in the GUI version that is started from
> the dock.

I don't know if the Mac folks have filled you in, but apps launched  
from the Finder get their environment from the file ~/.MacOSX/
environment.plist. Mac OS X "Property List" files are XML, and they  
look like this (this is a bit of my own environment.plist):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://
www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>myvimhelp</key>
        <string>~/.vim/doc/dml.txt</string>
    </dict>
</plist>

Th file contains any number of <key>/<string> pairs, which give the  
name and value of environment variables for Finder-launched apps.

The values in environment.plist are loaded at login time, so you have  
to log out and back in for new variables to be available.

Some folks keep all their environment variables in environment.plist  
and  parse it from .bashrc (or equivalent for other shells) to load  
those vars into their shell. Happily, Apple provided a utility that  
handles it for you:

    defaults read "${HOME}/.MacOSX/environment"

Also, with the Apple developer tools comes a program "Property List  
Editor" that makes it very easy to muck about with its contents. Of  
course, this being a vim list, most of you probably would prefer to  
use something like pico or emacs for this purpose :-).

Dave

Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

Dave Land
On Jan 8, 2007, at 3:03 PM, Dave Land wrote:

> Happily, Apple provided a utility that handles it for you:
>
>    defaults read "${HOME}/.MacOSX/environment"

Actually, making this work in bash (or other shell) requires a little  
more than just reading the file... Here's the relevant chunk from  
my .bashrc:

# Get environment variables from ~/.MacOSX/environment.plist
# (This avoids the sin of duplicating data here and in that file)
if [[ `uname` == 'Darwin' ]] ; then
    defaults read ~/.MacOSX/environment | grep -v '[{}]' | tr '"' "'" |  
awk '{ print "declare -x",$1"="$3 }' | while read -r OneLine; do eval  
$OneLine; done;
fi

To give credit where it's due, this came from a comment on  
macosxhints.com.

The conditional (if [[ `uname` == "Darwin' ]]) is because I use this  
same .bashrc across several hosts, including Solaris, Linux, and Mac  
OS X.

Dave

Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

Bram Moolenaar

Dave Land wrote:

> On Jan 8, 2007, at 3:03 PM, Dave Land wrote:
>
> > Happily, Apple provided a utility that handles it for you:
> >
> >    defaults read "${HOME}/.MacOSX/environment"
>
> Actually, making this work in bash (or other shell) requires a little  
> more than just reading the file... Here's the relevant chunk from  
> my .bashrc:
>
> # Get environment variables from ~/.MacOSX/environment.plist
> # (This avoids the sin of duplicating data here and in that file)
> if [[ `uname` == 'Darwin' ]] ; then
>     defaults read ~/.MacOSX/environment | grep -v '[{}]' | tr '"' "'" |  
> awk '{ print "declare -x",$1"="$3 }' | while read -r OneLine; do eval  
> $OneLine; done;
> fi
>
> To give credit where it's due, this came from a comment on  
> macosxhints.com.
>
> The conditional (if [[ `uname` == "Darwin' ]]) is because I use this  
> same .bashrc across several hosts, including Solaris, Linux, and Mac  
> OS X.

This issue comes up often enough that it deserves a section in the help.
Could you perhaps write some text?  If you can send me a patch that
would be great.

--
hundred-and-one symptoms of being an internet addict:
4. Your eyeglasses have a web site burned in on them.

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

Muskoka Auto Parts Limited
In reply to this post by Brett Calcott-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 8-Jan-07, at 5:31 PM, Brett Calcott wrote:

> This does seem to be the case. No amount of fiddling with .profile
> .bashrc .bash_profile /etc/bashrc or whatever makes any difference to
> the environment that ends up in the GUI version that is started from
> the dock.
>
> For the moment I just do something like this:
> if has("gui_running")
>  let $PATH=$PATH.':/some/more/paths:/and/more/still'
> endif
>
> Which does the trick for now.
>

FWIW - found this in my .vimrc
" Get a good value for $PATH.  For example, if teTeX is installed, this
" should add the path to tex, pdflatex, etc.
" This should only make a difference when vim is started from the  
Finder or
" with open.
let $PATH = system("printenv PATH")
let $PATH = substitute($PATH, "\<C-J>$", "", "")

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (Darwin)
Comment: Verify this email or encrypt your email for free - see gnupg.org

iD8DBQFFo56iGnOmb9xIQHQRArvVAKC9jHkQ2cg/nSN1eoui9TwlUkKwGwCg06LF
EUmrItXId5XsNVgg2Cc6VLU=
=DhLZ
-----END PGP SIGNATURE-----
Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

Muskoka Auto Parts Limited
In reply to this post by Dave Land
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 8-Jan-07, at 6:14 PM, Dave Land wrote:

> On Jan 8, 2007, at 3:03 PM, Dave Land wrote:
>
>> Happily, Apple provided a utility that handles it for you:
>>
>>    defaults read "${HOME}/.MacOSX/environment"
>
> Actually, making this work in bash (or other shell) requires a  
> little more than just reading the file... Here's the relevant chunk  
> from my .bashrc:
>
> # Get environment variables from ~/.MacOSX/environment.plist
> # (This avoids the sin of duplicating data here and in that file)
> if [[ `uname` == 'Darwin' ]] ; then
>    defaults read ~/.MacOSX/environment | grep -v '[{}]' | tr '"'  
> "'" | awk '{ print "declare -x",$1"="$3 }' | while read -r OneLine;  
> do eval $OneLine; done;
> fi
>
> To give credit where it's due, this came from a comment on  
> macosxhints.com.
>
> The conditional (if [[ `uname` == "Darwin' ]]) is because I use  
> this same .bashrc across several hosts, including Solaris, Linux,  
> and Mac OS X.

Just a quick note to anyone using that plist option - I once wasted  
about 20 hours of my time because a 'bad? corrupt? I never determined  
exactly'
enviroment.plist file caused my home folder to become read-only to  
the Finder!  IIRC Terminal.app could still manipulate files.
It caused all sorts of nifty issues (mainly because ~/Library is used  
so much).  Since it's a single user machine, it looked like some  
bizarre disk issue.
What really got me going was when I couldn't find the problem, I  
reinstalled from scratch, everything was fine, then it came back when  
I restored my home folder.
Much hair tearing occurred on that one!

Hopefully I can save a few follicles for somebody else.

Brian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (Darwin)
Comment: Verify this email or encrypt your email for free - see gnupg.org

iD8DBQFFo+f8GnOmb9xIQHQRAsbaAJ9GcS7DyjSU78O1v3YWxdgtoBReUgCgy8Aq
HHLv34cFN6eyzje31pYIysk=
=c/F5
-----END PGP SIGNATURE-----
Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

Brett Calcott-2
In reply to this post by Dave Land
Hi Dave,

Thanks for that. I have spent about 15 years on Windows and know it well.
Now I have the fun of discovering all the hidden bits on Mac.

Thanks a lot!
Brett

On 1/9/07, Dave Land <[hidden email]> wrote:

>
> On Jan 8, 2007, at 3:03 PM, Dave Land wrote:
>
> > Happily, Apple provided a utility that handles it for you:
> >
> >    defaults read "${HOME}/.MacOSX/environment"
>
> Actually, making this work in bash (or other shell) requires a little
> more than just reading the file... Here's the relevant chunk from
> my .bashrc:
>
> # Get environment variables from ~/.MacOSX/environment.plist
> # (This avoids the sin of duplicating data here and in that file)
> if [[ `uname` == 'Darwin' ]] ; then
>     defaults read ~/.MacOSX/environment | grep -v '[{}]' | tr '"' "'" |
> awk '{ print "declare -x",$1"="$3 }' | while read -r OneLine; do eval
> $OneLine; done;
> fi
>
> To give credit where it's due, this came from a comment on
> macosxhints.com.
>
> The conditional (if [[ `uname` == "Darwin' ]]) is because I use this
> same .bashrc across several hosts, including Solaris, Linux, and Mac
> OS X.
>
> Dave
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

Krzysztof Maj
In reply to this post by Muskoka Auto Parts Limited

On 2007-01-09, at 14:54, Brian McKee wrote:

> " Get a good value for $PATH.  For example, if teTeX is installed,  
> this
> " should add the path to tex, pdflatex, etc.
> " This should only make a difference when vim is started from the  
> Finder or
> " with open.
> let $PATH = system("printenv PATH")
> let $PATH = substitute($PATH, "\<C-J>$", "", "")

Hi,
I have a question. If I open my GVIM from the Dock and after that I  
open some file from the gui it sets PWD to my home directory not to  
the place from the file really is. If I open the same file clicking  
on it in Finder VIM sets PWD to the right place (to directory from  
this file is). I have written above lines to my .gvimrc but without  
any effects. Could somebody explain me what's going on? It's really  
frustrating because if I don't change the path manually forgetting  
about it, GVIM write my file in the home directory not in the place  
where it really is, making two diffrent copies of it.

How to correct it?

Cheers,
--
Pozdrawiam - Krzysztof Maj
 I'm a Mac now, are you PC?
Oh, dear... ;-)



Reply | Threaded
Open this post in threaded view
|

Re: Mac Questions

A.J.Mechelynck
Krzysztof MaJ wrote:
[...]

> Hi,
> I have a question. If I open my GVIM from the Dock and after that I open
> some file from the gui it sets PWD to my home directory not to the place
> from the file really is. If I open the same file clicking on it in
> Finder VIM sets PWD to the right place (to directory from this file is).
> I have written above lines to my .gvimrc but without any effects. Could
> somebody explain me what's going on? It's really frustrating because if
> I don't change the path manually forgetting about it, GVIM write my file
> in the home directory not in the place where it really is, making two
> diffrent copies of it.
>
> How to correct it?
>
> Cheers,
> --Pozdrawiam - Krzysztof Maj
>  I'm a Mac now, are you PC?
> Oh, dear... ;-)
>
>
>
>
>

By default, Vim doesn't change directories when you open a file. If you open
Vim from the Dock, without a filename, the current dir is your home directory.
If you later edit one or more files, the current directory is unchanged. If
you want to edit a file which is not in the current dir, you should specify
the path as part of the argument to the ":edit" command. (You can use
command-line completion repeatedly to complete one subdirectory or file name
at a time.) If you type just ":e filename", then if "filename" doesn't exist
in the current directory, Vim will assume that you want to create a new file
there.

If, instead, you click a file in Finder, the OS sets the current directory to
that file's directory, then invokes Vim.

If Vim is compiled with +netbeans_intg or with +sun_workshop, you can set
'autochdir'. This will change the current directory whenever you edit a new
file, switch buffers, etc., so the current directory will follow the current
file. Vim will still not "guess" a directory name (how could it?): ":e
filename" with no path, still means that you want to edit (or create) a file
in the current directory, whatever it is.

Alternately, you can use

        :autocmd BufWinEnter * lcd %:p:h

which will set a "local directory" for each buffer. This alternative only
requires +autocmd, which is included in "Normal", "Big" and "Huge" builds of Vim.

Personally, I've tried it, and I've found that I don't like directory changes
happening, so to speak, "behind my back". I prefer that directories only be
changed when I use ":cd" or ":lcd" explicitly. (YMMV)

In any case, each window's status line (when present) displays the path to the
file in that window, relative to the current directory if possible, or
otherwise as an absolute path.

See
        :help 'autochdir'
        :help :autocmd
        :help BufWinEnter
        :help :cd
        :help :lcd
        :help 'laststatus'


Best regards,
Tony.
Reply | Threaded
Open this post in threaded view
|

Current working directory (was Re: Mac Questions

Timothy Knox
Somewhere on Shadow Earth, at Fri, Jan 12, 2007 at 03:45:26AM +0100, A.J.Mechelynck wrote:
<snip>

> Alternately, you can use
>
> :autocmd BufWinEnter * lcd %:p:h
>
> which will set a "local directory" for each buffer. This alternative only
> requires +autocmd, which is included in "Normal", "Big" and "Huge" builds
> of Vim.
>
> Personally, I've tried it, and I've found that I don't like directory
> changes happening, so to speak, "behind my back". I prefer that directories
> only be changed when I use ":cd" or ":lcd" explicitly. (YMMV)

Whereas I added that to my .vimrc some time ago, and absolutely love it. On the
other hand, I work on a large software development project with many deep
directory hierarchies (the Real Networks media server, most of the code for
which is open source, so you can see what I mean), and I find it *very* handy to
do something like this:

$ cd server/protocol/transport/rdt/unittest
$ vim ut_rdttcptran.cpp
<from within vim>
:e ../../../tools/unittest/netio/ut_socket.cpp
<later>
:e ut_bufsock.cpp (which is in the same dir as ut_socket.cpp)
<still later, after flipping back to ut_rdttcptran.cpp>
:e ut_rdtudptran.cpp (which is in the same dir as ut_rdttcptran.cpp)

I find that far more convenient than having to constantly remember to preface my
:e with a bunch of "../"'s, but, as noted, YMMV.

--
I have always wished that my computer would be as easy to use as my telephone.
My wish has come true. I no longer know how to use my telephone.
    -- Bjarne Stroustrup, creator of the C++ programming language
12