Vim Tips Wiki
Register
No edit summary
 
(Change to TipImported template + severe manual clean)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=428
 
|id=428
  +
|previous=427
|title=Wordwise Ctrl-Y in insert mode
 
  +
|next=430
|created=February 18, 2003 0:19
+
|created=February 18, 2003
 
|complexity=basic
 
|complexity=basic
 
|author=Dubhead
 
|author=Dubhead
 
|version=5.7
 
|version=5.7
 
|rating=10/7
 
|rating=10/7
 
}}
|text=
 
Ctrl-Y in insert mode is one of Vim's handy extensions that inserts character which is above cursor (see :help i_CTRL-Y). However, sometimes this is not very useful when a user wants to insert many characters. In this case it's better to get a *word* above cursor.
+
Ctrl-Y in insert mode is one of Vim's handy extensions that inserts character which is above cursor (see :help i_CTRL-Y). However, sometimes this is not very useful when a user wants to insert many characters. In this case it's better to get a ''word'' above the cursor.
   
 
Put this in vimrc:
   
  +
<pre>
 
" Wordwise Ctrl-Y in insert mode
 
noremap! &lt;C-Y&gt; &lt;Esc&gt;klyWjpa
  +
</pre>
   
 
You might want to substitute 'W' with 'w', 'E', or 'e'. Try them and choose one that works best for you.
Put this in ~/.vimrc:
 
   
 
Unfortunately, this simple map doesn't work at the beginning or end of line. Improvements are welcome.
   
 
==Comments==
 
How about a small mod:
   
 
noremap! &lt;C-Y&gt; &lt;Esc&gt;klyWjPa
" Wordwise Ctrl-Y in insert mode
 
   
 
----
noremap! &lt;C-Y&gt; &lt;Esc&gt;klyWjpa
 
 
Other interesting variants, depending upon what one wants:
   
 
inoremap &lt;C-Y&gt; &lt;Esc&gt;klyiWjPa
 
inoremap &lt;C-Y&gt; &lt;Esc&gt;klyiwjPa
   
  +
The yiw yanks the "inner word", yiW yanks the "inner WORD". Both of these forms appear to work at both the beginning and end of sentences, with the exception that neither works for a single letter word at the beginning of a sentence.
   
You might want to substitute 'W' with 'w', 'E', or 'e'. Try them and choose one that works best for you.
 
 
 
 
Unfortunately, this simple map doesn't work at the beginning or end of line. Improvements are welcome.
 
 
 
}}
 
 
== Comments ==
 
How about a small mod:
 
 
noremap! &lt;C-Y&gt; &lt;Esc&gt;klyWjPa
 
 
 
cec--AT--NgrOyphSon.gPsfAc.nMasa.gov
 
, February 20, 2003 8:27
 
 
----
 
----
 
I think
Other interesting variants, depending upon what one wants:
 
 
:imap &lt;F1&gt; &lt;C-O&gt;:set virtualedit=all&lt;CR&gt;&lt;C-O&gt;k&lt;C-O&gt;yw&lt;C-O&gt;j&lt;C-O&gt;P&lt;C-O&gt;:set virtualedit=&lt;CR&gt;
   
 
is a little bit better, but not really satisfying (a bug in virtualedit/&lt;C-O&gt;?).
inoremap &lt;C-Y&gt; &lt;Esc&gt;klyiWjPa
 
inoremap &lt;C-Y&gt; &lt;Esc&gt;klyiwjPa
 
 
The yiw yanks the "inner word", yiW yanks the "inner WORD".
 
Both of these forms appear to work at both the beginning and
 
end of sentences, with the exception that neither works for a
 
single letter word at the beginning of a sentence.
 
 
cec--AT--NgrOyphSon.gPsfAc.nMasa.gov
 
, February 25, 2003 11:43
 
----
 
I think,
 
:imap &lt;F1&gt; &lt;C-O&gt;:set virtualedit=all&lt;CR&gt;&lt;C-O&gt;k&lt;C-O&gt;yw&lt;C-O&gt;j&lt;C-O&gt;P&lt;C-O&gt;:set virtualedit=&lt;CR&gt;
 
is a little bit better, but not really satisfying (a bug in virtualedit/&lt;C-O&gt; ?)
 
   
Tobi
 
, May 2, 2003 7:41
 
 
----
 
----
<!-- parsed by vimtips.py in 0.474946 seconds-->
 

Revision as of 06:17, 4 November 2007

Tip 428 Printable Monobook Previous Next

created February 18, 2003 · complexity basic · author Dubhead · version 5.7


Ctrl-Y in insert mode is one of Vim's handy extensions that inserts character which is above cursor (see :help i_CTRL-Y). However, sometimes this is not very useful when a user wants to insert many characters. In this case it's better to get a word above the cursor.

Put this in vimrc:

" Wordwise Ctrl-Y in insert mode
noremap! <C-Y> <Esc>klyWjpa

You might want to substitute 'W' with 'w', 'E', or 'e'. Try them and choose one that works best for you.

Unfortunately, this simple map doesn't work at the beginning or end of line. Improvements are welcome.

Comments

How about a small mod:

noremap! <C-Y> <Esc>klyWjPa

Other interesting variants, depending upon what one wants:

inoremap <C-Y> <Esc>klyiWjPa
inoremap <C-Y> <Esc>klyiwjPa

The yiw yanks the "inner word", yiW yanks the "inner WORD". Both of these forms appear to work at both the beginning and end of sentences, with the exception that neither works for a single letter word at the beginning of a sentence.


I think

:imap <F1> <C-O>:set virtualedit=all<CR><C-O>k<C-O>yw<C-O>j<C-O>P<C-O>:set virtualedit=<CR>

is a little bit better, but not really satisfying (a bug in virtualedit/<C-O>?).