Friday, April 29, 2011

Re: vim %


thanks for the help.

On Fri, Apr 29, 2011 at 3:48 AM, Tony Mechelynck <antoine.mechelynck@gmail.com> wrote:
On 28/04/11 15:04, cyboman wrote:
i'm trying to learn a bit of vim scripting, specifically i'm trying to
understand how to do something similar to scanf().

say we have a command

map ,cd :cd %:p:h<CR>

what do those %:p:h mean? can anyone recommend a help file i need do
read in order to understand the meanings of %:p:h?

any help is appreciated


You already got the answer of where to find the requested help, and by all means go read it: I've always liked the Vim help better than any novel.

Now: about this particular question:
       %       the current file
       :p      expanded to a full path
       :h      the "head" of the path (removing the last element)

IOW: %:p:h means "the directory of the current file". If the current "file" is actually a directory (i.e., you're in a netrw window), then %:p:h means the _parent_ of the directory being browsed.

There are other filename-modifiers than :p and :h -- the help will tell you what they are, with examples. And there are other "filename" symbols than % too:
       :help filename-modifiers
       :help cmdline-special
You could also have found the former by looking up ::p or ::h, or even %:p or %:h ; or the latter by looking up c_% -- they are actually after each other in a single chapter of one helpfile.

Note that if you're editing in split-windows mode, you may prefer to use :lcd rather than :cd in order to change only the "local" directory for the current window, without clobbering any working-directory which has been set for other windows.


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
77. The phone company asks you to test drive their new PBX system

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: