LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 01-24-2006, 08:49 PM   #1
jrdioko
Member
 
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, 04:03 PM   #2
jrdioko
Member
 
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.

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

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


Reply


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 10:27 AM
Is there any app to convert emacs's syntax highlight def. file to vim's def. file ? cyu021 Linux - Software 0 10-05-2004 11:02 PM
Placing current path in the prompt zepplin611 Linux - General 2 05-13-2004 12:07 PM
How to change the path of the current directory ? ndha Linux - General 7 12-03-2003 11:05 AM
CSH: "cmd >& file" or "cmd </dev/null >& file" stefanlasiewski Programming 1 09-08-2003 04:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:45 AM.

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