Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 01-24-2006, 09:49 PM   #1
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
Referring to current file/path in vim's :!<cmd>

I've been looking around online for information on the right syntax for this but can't seem to find anything.

I'd like to set up a keymap in vim to do two things:
1. cd (within vim) to the directory where the file I'm currently editing is (e.g. if I opened a file with "vim foo/bar/baz", it would execute ":!cd foo/bar")
2. Do something to the current file (e.g. execute ":!java foo/bar/baz)

I can't figure out how to get the path to the current file and parse it to accomplish something like that. Any tips are appreciated.
Old 01-27-2006, 05:03 PM   #2
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Original Poster
Rep: Reputation: 30
After hunting around a little more it looks like I've found the answer, which I thought I'd post here if others are interested. ":h expand()" gives most of the answer--you can let a variable be the full path, the last element of the full path, the full path with the last element removed, etc., and then work from there.

Or, the easier, "cd %:h" (see :h cd).

Last edited by jrdioko; 01-27-2006 at 05:08 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get absolute path of current executing C/C++ prog? Thinking Programming 2 10-10-2005 11:27 AM
Is there any app to convert emacs's syntax highlight def. file to vim's def. file ? cyu021 Linux - Software 0 10-06-2004 12:02 AM
Placing current path in the prompt zepplin611 Linux - General 2 05-13-2004 01:07 PM
How to change the path of the current directory ? ndha Linux - General 7 12-03-2003 12:05 PM
CSH: "cmd >& file" or "cmd </dev/null >& file" stefanlasiewski Programming 1 09-08-2003 05:19 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:51 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration