Re: CTRL-X CTRL-N in command line?

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

Re: CTRL-X CTRL-N in command line?

Hari Krishna Dara

On Fri, 29 Jul 2005 at 4:33pm, M.K. wrote:

> Is it possible to somehow get CTRL-X CTRL-N functionality (word completion
> from insert mode) when editing the command line?  From time to time I run
> into the situation where I start with ":%s/", at which point in time I
> realize that the word I want to substitute for is quite long and somewhere
> in the current buffer, hence would prefer to just type its first few
> letters and have Vim complete the rest from the current buffer.  Usually in
> such cases the cursor is *not* on the word in question, else I would have
> used CTRL-R CTRL-W...

It might be possible to write a script to do that, but the best solution
is to switch to the command-line window and complete the word. Take a
look at the help on cmdline-window.

--
HTH,
Hari

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 
Reply | Threaded
Open this post in threaded view
|

Re: CTRL-X CTRL-N in command line?

Tim Chase-2
> It might be possible to write a script to do that, but the
> best solution is to switch to the command-line window and
> complete the word. Take a look at the help on cmdline-window.

I too have wished that ^N/^P (or ^X ^N/^P) worked in command-line
mode--particularly in the ":s/.../" portion of things.

In addition to Hari's good suggestion of using "q:" or "q/" to
edit the command-line history much like any other buffer, if your
cursor is on the word in question, you can also use ^R^W (that's
control+R followed by control+W) on the command line to insert
the word over which you're cursor is currently positioned.  There
are some funky edge cases in which this doesn't work quite as
expected (such as when coming through line-wise visual mode) but
for most of your usual cases, it works like a charm.

        :help c_CTRL-R_CTRL-W

for more on this too.

HTH,

-tim





Reply | Threaded
Open this post in threaded view
|

Re: CTRL-X CTRL-N in command line?

Maciej Kalisiak-3
In reply to this post by Hari Krishna Dara
--On Friday, July 29, 2005 18:18:17 -0400 Hari Krishna Dara
<[hidden email]> wrote:
> It might be possible to write a script to do that, but the best solution
> is to switch to the command-line window and complete the word. Take a
> look at the help on cmdline-window.

Hmm, good idea, never thought of that.  But now I have a second problem:
the 'cedit' key doesn't seem to work for me.  From what I understand, after
I type ":%s/", I should be able to just hit C-F, and the cmdline  window
should pop up.  For me, nothing happens.  To make sure, I did ":set
cedit=<C-F>", and still nothing.  I have no problems reaching that window
from normal mode though, using "q:".  What could be the problem??

Reply | Threaded
Open this post in threaded view
|

Re: CTRL-X CTRL-N in command line?

Hari Krishna Dara
In reply to this post by Hari Krishna Dara

On Fri, 29 Jul 2005 at 7:38pm, M.K. wrote:

> --On Friday, July 29, 2005 18:18:17 -0400 Hari Krishna Dara
> <[hidden email]> wrote:
> > It might be possible to write a script to do that, but the best solution
> > is to switch to the command-line window and complete the word. Take a
> > look at the help on cmdline-window.
>
> Hmm, good idea, never thought of that.  But now I have a second problem:
> the 'cedit' key doesn't seem to work for me.  From what I understand, after
> I type ":%s/", I should be able to just hit C-F, and the cmdline  window
> should pop up.  For me, nothing happens.  To make sure, I did ":set
> cedit=<C-F>", and still nothing.  I have no problems reaching that window
> from normal mode though, using "q:".  What could be the problem??
>

I think I had some problem with setting 'cedit' too, but <C-F> I think
is the default, so it should work with no configuration. I use <C-F> to
move forward, so I wanted to change it to <A-S-F>, and here is what I
have in my vimrc:

" To open the command window.
cnoremap <A-S-F> <C-F>
"set cedit=<A-S-F>

I think 'cedit' didn't work, which is why I had it commented and used an
alterntaive.

Another alternative I many times use is to use <C-R><C-W> in combination
with the default pattern. I first get the word that I am replacing into
the search history and position my cursor on the word that I am going to
replace with so that I can use <C-R><C-W> and use the below key
sequence:

:%s//<C-R><C-W>/<CR>

For Tim, I actually meant the 'cedit' key rather than using "q:", and I
am glad that the OP understood it though I didn't mention it clearly :)

--
HTH,
Hari

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com