cmd-start problem with actual directory

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

cmd-start problem with actual directory

Raphael Brunner-2
Dear Vim-Users

I have a problem, I make a map of the F5-Key to run the file with
python. Now, on Linux it works well. But in my Company on a Windows XP
System I have this problem: if I press F5, then the buffer of VIM is
executed with python.exe, but in the python program, I need to know, in
witch directory the python-prgram is running (eg.
C:\python\trys\program.py) If I start the programm with F5 in VIM, then
the path (:pwd) isn't right, where I opened the file. It shows me the
"HOME" in Windows. Is there a possibility to show the directory in with
my file live (not "bufname"), then I can cd to it before start the
python-file.
Or does anyone know, how to work around my problem?

Many thanks for your help

here is a window in my vimrc:

        " ********* Python Objekts **********
        :function PYTHONfiles()
                set expandtab
                set tabstop=4
                set shiftwidth=4
                set cindent
                set number
                syntax enable
                " zeigt Klammernpaar 0.6s an)
                set showmatch
                set matchtime=6
                " Fold-Settings:
                " set my key-shortcuts
                :map <silent> <F5> :call RunPythonScript() <CR><ESC>
        :endfunction

        function RunPythonScript()
                let s:pythonpath = '/usr/bin/python'
                let s:pythonpath = 'C:\Python24\python.exe'
                let s:pythonfile = bufname('%')
                :execute ':!' . s:pythonpath . " " . s:pythonfile
        endfunction
Reply | Threaded
Open this post in threaded view
|

Re: cmd-start problem with actual directory

Yakov Lerner
"Raphael Brunner" <[hidden email]> wrote:

> I have a problem, I make a map of the F5-Key to run the file with
> python. Now, on Linux it works well. But in my Company on a Windows XP
> System I have this problem: if I press F5, then the buffer of VIM is
> executed with python.exe, but in the python program, I need to know, in
> witch directory the python-prgram is running (eg.
> C:\python\trys\program.py) If I start the programm with F5 in VIM, then
> the path (:pwd) isn't right, where I opened the file. It shows me the
> "HOME" in Windows. Is there a possibility to show the directory in with
> my file live (not "bufname"), then I can cd to it before start the
> python-file.
> Or does anyone know, how to work around my problem?

Try to change your bufname('%') to expand('%:p') like this:

  let s:pythonfile = expand('%:p')

Yakov


> here is a window in my vimrc:
>
> " ********* Python Objekts **********
> :function PYTHONfiles()
> set expandtab
> set tabstop=4
> set shiftwidth=4
> set cindent
> set number
> syntax enable
> " zeigt Klammernpaar 0.6s an)
> set showmatch
> set matchtime=6
> " Fold-Settings:
> " set my key-shortcuts
> :map <silent> <F5> :call RunPythonScript() <CR><ESC>
> :endfunction
>
> function RunPythonScript()
> let s:pythonpath = '/usr/bin/python'
> let s:pythonpath = 'C:\Python24\python.exe'
> let s:pythonfile = bufname('%')
> :execute ':!' . s:pythonpath . " " . s:pythonfile
> endfunction
--
 
  [hidden email]

--
http://www.fastmail.fm - Access all of your messages and folders
                          wherever you are

Reply | Threaded
Open this post in threaded view
|

Re: cmd-start problem with actual directory

Marian Csontos
In reply to this post by Raphael Brunner-2
Hi Raphael,

>
> I have a problem, I make a map of the F5-Key to run the file with
> python. Now, on Linux it works well. But in my Company on a Windows XP
> System I have this problem: if I press F5, then the buffer of VIM is
> executed with python.exe, but in the python program, I need to know, in
> witch directory the python-prgram is running (eg.
> C:\python\trys\program.py) If I start the programm with F5 in VIM, then
> the path (:pwd) isn't right, where I opened the file. It shows me the
> "HOME" in Windows. Is there a possibility to show the directory in with
> my file live (not "bufname"), then I can cd to it before start the
> python-file.
> Or does anyone know, how to work around my problem?

You can simple change to file's directory using
        :cd %:p:h

Regards,

-- Marian


________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Server.
  part000.txt - is OK
http://www.nod32.com