History Report a problem
Article Edit this page Discussion

Wordwise Ctrl-Y in insert mode

From Vim Tips Wiki

(Redirected from VimTip428)
Jump to: navigation, search

Tip 428 Previous TipNext Tip

Created: February 18, 2003 Complexity: basic Author: Dubhead Minimum version: 5.7 Karma: 10/7 Imported from: Tip#428


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.

[edit] 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>?).


Hmm.. I can't get Ctrl-Y to work at all :( I tried :behave xterm but it doesn't seem to do anything for me :(

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Pushing Daisies
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Godzilla
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Wordwise Ctrl-Y in insert mode"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation


.