Loading ...
Sorry, an error occurred while loading the content.

20653RE: decapitlising on the fly

Expand Messages
  • Ash Searle
    Sep 3, 2001
    • 0 Attachment
      This might do the trick. I'm sure one of the vim gurus can make
      something more elegant, but give this a shot anyway.
      Pop this in your .vimrc - it will recapitalize words on the current
      line when you press space. You may want to add a few more mappings
      for "," "." "!" "?", "-" and carriage returns.

      function! Decap()
      let l:line = getline(".")
      " decapitalize words (e.g. THat -> That)
      let l:line = substitute(l:line, "\\<\\(\\u\\)\\(\\u\\)\\([^A-Z
      \\t.]\\)", "\\1\\L\\2\\e\\3", "g")
      " turn i's into I's
      let l:line = substitute(l:line, "\\<i\\>", "I", "g")
      call setline(".", l:line)
      endfunction

      inoremap <Space> <C-O>:call Decap()<CR><Space>

      Hope it helps,

      Ash


      > -----Original Message-----
      > From: Eric Smith [mailto:Eric.Smith@...]
      > Sent: 3 September 2001 19:38
      > To: vim users
      > Subject: decapitlising on the fly
      >
      >
      > I know I am not the only one with the problem of typing THis instead of
      > This (usually at the start of a sentence). Now that I have the
      > following (perl) solution, I tend to make this mistake even more
      > often.
      >
      > /usr/home/eric/bin/decap
      > #!/usr/bin/perl
      > while (<>)
      > {
      > s/(?<=\b)([A-Z]{2})(?![A-Z\s.\d])/ucfirst (lc ($1))/eg; #decap
      > s/\bi\b/I/g; #up-size the personal pronoun while u're at it
      > print;
      > }
      > so
      > :%!decap
      > does it.
      >
      > Some time ago I asked on this list whether there is a way to
      > dynamically correct this error (without having to explicitly define an
      > abbreviation for each possible instance which is ridiculous). The only
      > answer I received was that this could not be done. Hence the above
      > solution. Anyhow, I have had the misfortune of producing a document
      > in ms word over the last few days and they correct this error on the
      > fly once you have completed the offending word.
      >
      > Anything they can do we can do better? Or can we?
      > --
      > Eric Smith
    • Show all 6 messages in this topic