caps lock invert in insert mode? (Fortran 77 editing)

21 views
Skip to first unread message

Rob

unread,
Nov 22, 2010, 7:01:51 AM11/22/10
to v...@vim.org
I find it quite awkward to edit a language such as Fortran 77 where all keywords are in capitals. I am constantly turning caps lock on and off, sometimes forgetting which means I then enter the wrong commands.

Is there any vim feature to make this easier? I'm thinking something like ':set capsinvert' would help. It would only affect insert mode, and invert the functionality of the caps lock key. ie. normally type in capitals, but can be disabled (turn the caps lock light on) for typing string literals in normal case.

Any thoughts?

thanks,
Rob



Karthick Gururaj

unread,
Nov 22, 2010, 7:11:10 AM11/22/10
to vim...@googlegroups.com, v...@vim.org
On Mon, Nov 22, 2010 at 5:31 PM, Rob <r0...@yahoo.co.uk> wrote:
> I find it quite awkward to edit a language such as Fortran 77 where all keywords are in capitals.  I am constantly turning caps lock on and off, sometimes forgetting which means I then enter the wrong commands.
>
> Is there any vim feature to make this easier?  I'm thinking something like ':set capsinvert' would help.  It would only affect insert mode, and invert the functionality of the caps lock key. ie. normally type in capitals, but can be disabled (turn the caps lock light on) for typing string literals in normal case.

Check :help inoremap

For e.g,
:inoremap a A
:inoremap A a

Rob

unread,
Nov 22, 2010, 7:32:14 AM11/22/10
to vim...@googlegroups.com
> Check :help inoremap
>
> For e.g,
> :inoremap a A
> :inoremap A a

Thanks, but I can't get this to work. Am I correct in thinking that having done this, typing 'a' in insert mode should insert 'A' and vice versa?

I would need to setup 52 inoremaps and possibly functions to turn them all on or off?


Joan Miquel Torres Rigo

unread,
Nov 22, 2010, 8:01:17 AM11/22/10
to vim...@googlegroups.com
2010/11/22 Rob <r0...@yahoo.co.uk>:


Maybe it would be more easy if you write also the code in lowercase
and some hotkey to a function which selects the code (excluding string
literals) with regular expression and then make it all upercase with
'U' command.

This way you only need to press that hotkey just after (writting and)
executing the code.


...More elaborated idea could be to define BufWrite autocommand for
fortran files.


--
Joan Miquel Torres__________________________________
Linux Registered User #164872
http://www.mallorcaweb.net/joanmiquel
BULMA: http://bulma.net http://breu.bulma.net/?l2301

Karthick Gururaj

unread,
Nov 22, 2010, 8:02:23 AM11/22/10
to vim...@googlegroups.com
That is correct..

Ofcourse, you can put a loop instead of 52 explicit maps. Something like:
function EnableCapsMap()
let iLower=97 " Ascii value of 'a'
let iUpper=65 " Ascii value of 'A'
while iLower < 123
exe 'inoremap ' . printf("%c", iLower) . ' ' . printf("%c", iUpper)
exe 'inoremap ' . printf("%c", iUpper) . ' ' . printf("%c", iLower)
let iLower=iLower+1
let iUpper=iUpper+1
endwhile
endfunction

function DisableCapsMap()
let iLower=97 " Ascii value of 'a'
let iUpper=65 " Ascii value of 'A'
while iLower < 123
exe 'iunmap ' . printf("%c", iLower)
exe 'iunmap ' . printf("%c", iUpper)
let iLower=iLower+1
let iUpper=iUpper+1
endwhile

endfunction

Toggle the mode with
:call EnableCapsMap()
:call DisableCapsMap()

Rob

unread,
Nov 22, 2010, 10:22:01 AM11/22/10
to vim...@googlegroups.com
> >> For e.g,
> >> :inoremap a A
> >> :inoremap A a
> >
> > Thanks, but I can't get this to work. Am I correct
> in thinking that having done this, typing 'a' in insert mode
> should insert 'A' and vice versa?
> >
> > I would need to setup 52 inoremaps and possibly
> functions to turn them all on or off?
> That is correct..
>
> Ofcourse, you can put a loop instead of 52 explicit maps.
> Something like:

Thanks, that would be exactly what I need, except that the inoremap examples above have no effect for me. I presume it works for you. I am using vim 7.3 in a console.



Karthick Gururaj

unread,
Nov 22, 2010, 10:41:09 AM11/22/10
to vim...@googlegroups.com

Hmmm.. can't imagine why.. I checked the functions, they work for me
(in console environment as well). What is the value returned when you
do:
:echo &enc
and
:echo &tenc
and
:set

Can you check with just a single character?
Do,
:inoremap a A
and check if typing 'a' gives you 'A'

Rob

unread,
Nov 22, 2010, 11:25:58 AM11/22/10
to vim...@googlegroups.com
> Hmmm.. can't imagine why.. I checked the functions, they
> work for me
> (in console environment as well). What is the value
> returned when you
> do:
> :echo &enc

utf-8

> and
> :echo &tenc

nothing or white space, I can't tell which

> and
> :set
>

balloondelay=100 clipboard= expandtab helplang=en makeprg= number pastetoggle=<F6> ruler shell=/bin/tcsh shortmess=atoO tags= ttyfast wildmenu
ballooneval directory=. foldminlines=4 hlsearch modified paste path= scroll=53 shiftwidth=2 smartcase title ttymouse=xterm
fileencodings=ucs-bom,utf-8,default,latin1
wildmode=longest:full

*ahh, it is the paste mode!*

> Can you check with just a single character?
> Do,
> :inoremap a A
> and check if typing 'a' gives you 'A'

ok, with paste mode turned off (otherwise not)

thanks for your help.



AK

unread,
Nov 22, 2010, 12:17:36 PM11/22/10
to vim...@googlegroups.com

I have a sort of similar case: often, completion gives me a word with
first letter capitalized, while I need all lower-case (e.g. for a
variable). I have an insert-mode mapping that lowercases first letter of
that word and returns to insert mode:

inoremap <m-0> <esc>b~ea

You can use for example gUe command to uppercase to the end of a word.
That way you only need a single keystroke per word, which I think is
better and easier than switch to upper, type, then switch back. You also
won't have a problem with forgetting that you're in uppercase and typing
something that should be lowercase. -ak

Karthick Gururaj

unread,
Nov 22, 2010, 12:27:46 PM11/22/10
to vim...@googlegroups.com
On Mon, Nov 22, 2010 at 9:55 PM, Rob <r0...@yahoo.co.uk> wrote:
>> :set
>>
>
>  balloondelay=100    clipboard=          expandtab           helplang=en         makeprg=            number              pastetoggle=<F6>    ruler               shell=/bin/tcsh     shortmess=atoO      tags=               ttyfast             wildmenu
>  ballooneval         directory=.         foldminlines=4      hlsearch            modified            paste               path=               scroll=53           shiftwidth=2        smartcase           title               ttymouse=xterm
>  fileencodings=ucs-bom,utf-8,default,latin1
>  wildmode=longest:full
>
> *ahh, it is the paste mode!*
>
>> Can you check with just a single character?
>> Do,
>> :inoremap a A
>> and check if typing 'a' gives you 'A'
>
> ok, with paste mode turned off (otherwise not)
Apart from other suggestions on using a motion command followed by 'U'
to make upper case, you might want to define abbreviations only for
fortran keywords.

like (I don't know what are the keywords in fortran):
:iabbr function FUNCTION

That way, you do not have to bother about case at all, vim will
correct it for you. Having a look at the fortran syntax file might
help in getting a good list of keywords.

Ben Fritz

unread,
Nov 22, 2010, 4:26:04 PM11/22/10
to vim_use

Rob

unread,
Nov 22, 2010, 5:00:51 PM11/22/10
to vim...@googlegroups.com
Great, thanks everyone. Just need to work out which approach works best
for me.
Reply all
Reply to author
Forward
0 new messages