Would you provide a key mapping for insert mode which could make letters between start of current word to current cursor uppercase?
Example:
- For string
abcd efgh
, and now cursor is flickering at the end followingh
, then I could getabcd EFGH
. - For string
abcd efgh
, and now cursor is flickering ong
, then I could getabcd EFgh
.
Please note, I know
gU
and
map! <C-F> <Esc>gUiw`]a
But it cannot meet my second example.
Thanks in advance!
Updated on GMT 2016/3/30, 2:26:
According to comment from Carpetsmoker and as I tried, gUb
could meet my second example but not the first, while gUiw
could meet my first example but not the second.
So would anyone help to implement necessary function or logic? Thus could meet my requirement completely.
Or any other solution is also appreciated.
Updated on GMT 2016/3/30, 3:19:
Currently, there are two solutions, one is from muru and the other is from myself. Both works as I tried and are acceptable to me. I mark muru one as the answer.
Updated on GMT 2016/3/31, 23:19:
With comments from tommcdo and VanLaser, I updated my solution, and to me it's the current best one.
Updated on GMT 2016/10/20, 14:25:
Regarding the solution of
nnoremap <C-f> gUvb`]
I just found a bug. For example, in normal mode, we have asdf qwer
, and cursor is flicking on q
when we press Ctrl-f
, we will get ASDF Qwer
, rather than expected asdf Qwer
. So current best solution is
inoremap <C-f> <C-\><C-O>gUb<ESC>`]a
and
nnoremap <C-f> a<C-\><C-O>gUb<ESC>`]
gU
on the motioniw
, which is inner word, meaning all of the word the cursor is currently on. Your first and second case are actually subtly different, since the first is "capitalize all letters in the previous word", while the second case is "capitalize all letters before the cursor but NOT the letter the cursor is on"... Replacingiw
withb
will almost do what you want, but more logic is needed to do exactly what you want...gUb
instead ofgUiw
?h
, thengUb
will give youabcd EFGH
. Is the cursor onh
or afterh
?efgh
, the cursor will afterh
, while to usegUb
, I need switch to normal mode with <ESC>, then cursor will move onh
, right?