selection to upper case or lower case

4 views
Skip to first unread message

Jeri Raye

unread,
Oct 30, 2010, 6:16:44 AM10/30/10
to v...@vim.org
Hi,

With gUU you can change a line to all upper case words.
With guu you can change a line to all lower case.

How can you apply this to a selection?
Meaning:
When I have a piece of code selected to status line shows --SELECT--
When I then press gUU, it removes my selection and give me the text gUU.
That's not what I want.

What I want is to:
1) Select a piece of code.
2) Press <Shift-F3> and make it upper case.
3) Press <Shift-F3> again to change it to lower case. (So a toggle function)


Rgds,
Jeri

ZyX

unread,
Oct 30, 2010, 6:38:21 AM10/30/10
to vim...@googlegroups.com
Reply to message «selection to upper case or lower case»,
sent 14:16:44 30 October 2010, Saturday
by Jeri Raye:

> With gUU you can change a line to all upper case words.
> With guu you can change a line to all lower case.
>
> How can you apply this to a selection?
> Meaning:
> When I have a piece of code selected to status line shows --SELECT--
> When I then press gUU, it removes my selection and give me the text gUU.
> That's not what I want.

You should not be using select mode instead of visual mode. If you press `gU'
(not `gUU` since second `U' is a motion) in visual mode, it will do what you
want. Try doing `set selectmode=' and then repeat what you do. If you do not
want to use visual mode, use `<C-o>gU' instead of `gU'.

> What I want is to:
> 1) Select a piece of code.
> 2) Press <Shift-F3> and make it upper case.
> 3) Press <Shift-F3> again to change it to lower case. (So a toggle
> function)

If you want to toggle upper/lower (so that `Ul' becomes `uL'), use
vnoremap <special> <S-F3> ~
if you want to toggle upper/lower based on character under cursor, use
vnoremap <expr> <special> <S-F3> ((matchstr(getline('.'), '^.', col('.')-1)=~#'\u')?
('gu'):('gU'))

signature.asc

Javier Rojas

unread,
Oct 30, 2010, 9:49:57 AM10/30/10
to vim...@googlegroups.com
On Sat, Oct 30, 2010 at 02:38:21PM +0400, ZyX wrote:
> Reply to message «selection to upper case or lower case»,
> > What I want is to:
> > 1) Select a piece of code.
> > 2) Press <Shift-F3> and make it upper case.
> > 3) Press <Shift-F3> again to change it to lower case. (So a toggle
> > function)
> If you want to toggle upper/lower (so that `Ul' becomes `uL'), use
> vnoremap <special> <S-F3> ~
> if you want to toggle upper/lower based on character under cursor, use
> vnoremap <expr> <special> <S-F3> ((matchstr(getline('.'), '^.', col('.')-1)=~#'\u')?
> ('gu'):('gU'))

If I remember correctly, keybindings like Shift-Fn are recognized only
by gvim, not by terminal vim (because of limitations of the terminal
emulator, e.g., xterm or konsole)

Using ~ to toggle the case of text seems more simple to type for me.

--
Javier Rojas

GPG Key ID: 0x24E00D68

signature.asc

ZyX

unread,
Oct 30, 2010, 11:16:45 AM10/30/10
to vim...@googlegroups.com
Reply to message «Re: selection to upper case or lower case»,
sent 17:49:57 30 October 2010, Saturday
by Javier Rojas:

> If I remember correctly, keybindings like Shift-Fn are recognized only
> by gvim, not by terminal vim (because of limitations of the terminal
> emulator, e.g., xterm or konsole)

No, sometimes <S-FN> works fine. Sometimes it requires a bunch of
...
set <S-F3>=^[[13;2~
...
placed in the vimrc. But they can be recognized in a terminal. There can be some
problems when terminal takes <S-FN> key as its own shortcut... but this can
apply to any <C-, <A- and others as well.

signature.asc

Jeri Raye

unread,
Oct 30, 2010, 1:14:27 PM10/30/10
to vim...@googlegroups.com
>> With gUU you can change a line to all upper case words.
>> With guu you can change a line to all lower case.
>>
>> How can you apply this to a selection?
>> Meaning:
>> When I have a piece of code selected to status line shows --SELECT--

This seems to work for the text selected when your in select mode
vmap <S-F3> <esc>gv~

<esc> stops the select-mode
gv selects the last selection, but then in visual mode
~ does then the toggling

Rgds,
Jeri

Reply all
Reply to author
Forward
0 new messages