How to customize CTRL-W CTRL-F?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to customize CTRL-W CTRL-F?

Peng Yu
Hi,

I want to customize the behavior of CTRL-W CTRL-F. For example, it is
of the pattern #include <header.h>, I will search for C and C++ header
file directories. If it is of the pattern import os, I'll search for
python library directories for file os.py.

More generally, it a line match for some pattern, I will call an
external program (the program could be written as a vim function) to
resolve the file to be opened.

:help CTRL-W_f doesn't tell me how to customize it. Could anybody let
me know how to do so? Thanks!

Regards,
Peng

--
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
Reply | Threaded
Open this post in threaded view
|

Re: How to customize CTRL-W CTRL-F?

Tony Mechelynck
On 27/11/11 18:28, Peng Yu wrote:

> Hi,
>
> I want to customize the behavior of CTRL-W CTRL-F. For example, it is
> of the pattern #include<header.h>, I will search for C and C++ header
> file directories. If it is of the pattern import os, I'll search for
> python library directories for file os.py.
>
> More generally, it a line match for some pattern, I will call an
> external program (the program could be written as a vim function) to
> resolve the file to be opened.
>
> :help CTRL-W_f doesn't tell me how to customize it. Could anybody let
> me know how to do so? Thanks!
>
> Regards,
> Peng
>

About customizing key bindings (or bindings for key sequences), see
:help map.txt

About defining a custom function in Vim, see the help section starting
at :help user-functions

About regular expressions in Vim, see the help section starting at :help
pattern-overview (or :help rn-ov if you are, like me, a lazy typist) for
a summary and the rest of the same helpfile for the encyclopaedic
treatment of the matter.

About calling an external program in order to use its stdout output, see
:help system()

It's been too long since I've been Linux-only, I don't remember if
system() is or isn't one of the cases where, on Windows, calling an
external program requires opening a cmd.exe window which you'll have to
close by hitting any key after it finishes. I also can't tell if you are
on Windows or not: if you aren't, this paragraph does not apply to you.


Best regards,
Tony.
--
Love is the triumph of imagination over intelligence.
                -- H. L. Mencken

--
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
Reply | Threaded
Open this post in threaded view
|

Re: How to customize CTRL-W CTRL-F?

Benjamin R. Haskell-8
In reply to this post by Peng Yu
On Sun, 27 Nov 2011, Peng  Yu wrote:

> Hi,
>
> I want to customize the behavior of CTRL-W CTRL-F. For example, it is
> of the pattern #include <header.h>, I will search for C and C++ header
> file directories. If it is of the pattern import os, I'll search for
> python library directories for file os.py.
>
> More generally, it a line match for some pattern, I will call an
> external program (the program could be written as a vim function) to
> resolve the file to be opened.
>
> :help CTRL-W_f doesn't tell me how to customize it. Could anybody let
> me know how to do so? Thanks!

See:

:help 'include'      -- 'inc' = how to determine a line might be an 'include'
:help 'includeexpr'  -- 'inex' = how to transform that line into a filename

Generally, filetypes set up some minimal setup, usually enough to handle
files in the same directory or a subdir.

E.g. ft=python sets up:

include=s*\(from\|import\)
(which doesn't work... but that's a topic for a different thread)

and:
includeexpr=substitute(v:fname,'\.','/','g')

Obviously there are lots of cases where it could be improved, and it
often depends on the way a project is set up.  Just wanted to point out
the simple setup already present.  Most third-party ftplugins do this,
too.  So, again, you might not have to do the work yourself.

If you do end up trying this on your own, this command is helpful:

:che!                 -- show all files detected as includes
:help :checkpath

--
Best,
Ben

--
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