Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In vim, if I'm working on a Python script, I will commonly type:

:! python this_script.py

to execute the script. Is there a shortcut for the name of the current file? If not, can I easily make one? I'm new at vim, and I'm not sure how to google for this.

share|improve this question

4 Answers 4

up vote 19 down vote accepted

You can just use % for current file. This command should serve your purpose:

:! python %
share|improve this answer
4  
Thus, don't forget you must quote the % character when using commands like :s ... :s/Foo\%X// ... if you don't, the name of the file will show up there. –  Mei Jun 4 '11 at 6:24

Some pointers

:h 'makeprg
:h :make
share|improve this answer

FYI, if you are also using the embedded Python interpreter in Vim, you can get the name with the vim.current.buffer.name attribute. You man also want to use the :update command to write the file automatically. I have a mapping like for Python buffers:

nmap ;ru :update<CR>:python pyterm(vim.current.buffer.name)

The pyterm is a function that also opens a new Python interpreter in a new terminal window and runs it in interactive mode.

share|improve this answer

One other way is to use the really nice package for vim: Efficient python folding : Fold python code nicely and toggle with one keystroke which folds the "defs, classes" but also binds "shift+e" to 'save + execute', so cool and useful!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.