why does it add water
C-r C-w
inserts the word positioned under your cursor; however, if 'incsearch'
is set, and there is a match in the buffer for the current contents of the command-line, Vim doesn't use the cursor position anymore, but the end of the match. From :h c^r^w
:
When 'incsearch' is set the cursor position at the end of the
currently displayed match is used.
When your command-line contains the
, the end of the match is here:
I saw the water in a thermal bath.
^
There is no word at that position, so Vim inserts the next word which is water
.
I guess Vim uses a similar algorithm as with the *
command:
* Search forward for the [count]'th occurrence of the
word nearest to the cursor. The word used for the
search is the first of:
1. the keyword under the cursor |'iskeyword'|
2. the first keyword after the cursor, in the
current line
3. the non-blank word under the cursor
4. the first non-blank word after the cursor,
in the current line
Only whole keywords are searched for, like with the
command "/\<keyword\>". |exclusive|
'ignorecase' is used, 'smartcase' is not.
without a space?
I guess that's because C-r C-w
is meant to insert a word, and a space character is not considered as being part of a word.
why does it add only the first I letter of the next word in?
It's not the first letter of the next word; it's the word under your cursor.
I saw the water in a thermal bath.
^
When your search command-line contains thewater
, Vim can't use the end of the match as the position of the word because there is no match for thewater
in your buffer; so it falls back to your cursor position.
And under your cursor, the word is I
, not in
.
why is that letter capitalized?
Again, it's not just a capitalized letter; it's the word under your cursor.
why does it get stuck there and does not proceed further?
Because no matter how many I
you insert, there is still no match in the buffer; so Vim keeps using the cursor position to decide which word to insert.
To insert multiple words from the current line, you could also:
- press
C-r C-l
to insert the whole contents of the line (see :h c^r^l
)
- use traditional editing commands to remove the words you're not interested in (see
:h ex-edit-index
)
Note that c^r^l
requires the patch 8.0.1787
. Without, you could try some custom mapping (e.g. cno <c-r><c-l> <c-r><c-r>=getline('.')<cr>
).