tags:

views:

262

answers:

3

I have often PATHs for files which do not exist in my codes.

I run as my cursor is at a PATH which does not exist

CTRL-W f

I get

E447: Can't find file "~/bin/editors/emacs/python_mode" in path

The long way of creating new file is

Ctrl-W v
:args [copy_paste_the_path_with_mouse]

Do you know any short way of creating a new file in Vim when you have PATHs for files in a file which do not exists yet?

I would like to create a new file simply by

CTRL-W f
+1  A: 

:e path_to_file
:w!

I don't think there's a built in key combination for reading in the clipboard for the new file.
You should be able to use key maps for this or a custom script.

See this question and vim.org for more info.

Hope that helps

Steve Lazaridis
Problem: What is the code for coping the text between two spaces? If we know that, then the main problem is nearly solved.
Masi
`yiW` = "yank inner WORD", see `:h text-objects` for more info.
ephemient
Also, <Ctrl+R>0 pastes the contents of register 0 while in insert mode, so `:e <Ctrl+R>0` will be what you want to do after the above.
ephemient
@ephemient: Thank you for your answers!
Masi
+3  A: 

If you do :h E447 to look up the error message you received, you will see this:

...
If you do want to edit a new file, use:
    :e <cfile>
To make gf always work like that:
    :map gf :e <cfile><CR>

So try this:

:nmap <C-w>f :e <cfile><CR>
Brian Carper
What does <cfile> mean? -- My docs says that it is about reading error files.
Masi
I tested it on Linux, Vim version 7.2. You can see this doc here online (grep it for E447): http://www.vim.org/htmldoc/editing.html
Brian Carper
Certain literals are expanded magically on the Vim commandline. <cfile> is expanded to a string containing the pathname under the cursor in the currently active buffer. See :h <cfile> and :h cmdline-special .
Brian Carper
I found the same docs as you have in my OS/X. I made apparently a typo which gave me bad results. --- Thank you for your answers!
Masi
To get everything works fine, I recommend to use CTRL-W c, instead of CTRL-W f in creating new files.
Masi
A: 

To avoid having to copy-paste with the mouse you can do :edit ^R^P to copy the path/filename at the cursor position into the command line. For more info do :help ^R^P

intuited