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

RE: decapitlising on the fly

Expand Messages
  • Ash Searle
    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
    Message 1 of 6 , Sep 3 1:32 PM
    • 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
    • Eric Smith
      ... ... whoopee - no performance degradation from what I can see after a quick whirl. Anyone writing prose in vim should know about this. Well done! --
      Message 2 of 6 , Sep 3 1:43 PM
      • 0 Attachment
        According to Ash Searle on Mon, Sep 03, 2001 at 09:32:25PM +0100:
        |
        <snip>
        | 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

        whoopee - no performance degradation from what I can see after a
        quick whirl.
        Anyone writing prose in vim should know about this.

        Well done!

        --
        Eric Smith
      • Mark Zealey
        ... This is nice, maybe use s rather than s to avoid the need for lots of s... -- Mark Zealey (aka JALH on irc.openprojects.net: #zealos and many more)
        Message 3 of 6 , Sep 3 1:44 PM
        • 0 Attachment
          > 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>

          This is nice, maybe use ''s rather than "'s to avoid the need for lots of \'s...

          --

          Mark Zealey (aka JALH on irc.openprojects.net: #zealos and many more)
          mark@...

          UL++++>$ G!>(GCM/GCS/GS/GM) dpu? s:-@ a16! C++++>$ P++++>+++++$ L+++>+++++$
          !E---? W+++>$ N- !o? !w--- O? !M? !V? !PS !PE--@ PGP+? r++ !t---?@ !X---?
          !R- b+ !tv b+ DI+ D+? G+++ e>+++++ !h++* r!-- y--

          (www.geekcode.com)
        • Sven Br├╝ggemann
          ... That is certainly possible. AFAIK there is no event FinishedWord in VIM, but for normal text (you wouldn t want to use this auto correction when coding, do
          Message 4 of 6 , Sep 3 2:15 PM
          • 0 Attachment
            > I know I am not the only one with the problem of typing THis instead of
            > This (usually at the start of a sentence).

            > 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).

            > 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?


            That is certainly possible. AFAIK there is no event FinishedWord in VIM, but for normal text (you wouldn't want to use this auto correction when coding, do you?) an imap for <space> should to the job.

            I never really used marks so I struggle with the cursor positioning - I use a German keyboard layout where backticks are dead keys so I don't know whether I did something wrong or my keyboard fooled me. Certainly Benji can help here.

            I mapped <space> to a substitute command that replaces two uppercase characters at the beginning of a word by an uppercase and a lowercase character:

            imap <space> <esc>{mark cursor position here}:. s/\<\(\u\)\(\u\)\(\w*\)/\1\l\2\e\3/eg{return to cursor position here}

            Since it works on the whole line, it is a little bit more annoying than MS Word (regarding this special feature) but let's see how Benji and the others can improve this.

            Kind regards

            SAM
          • Ash Searle
            Thought I should share this slightly improved version. I don t know how often anyone types i.e. , or if there are any other latin things like that, but, I
            Message 5 of 6 , Sep 7 9:12 AM
            • 0 Attachment
              Thought I should share this slightly improved version. I don't
              know how often anyone types "i.e.", or if there are any other
              latin things like that, but, I don't believe it should be
              capitalized.

              Oh, mapping to <Space> doesn't help when you make a typo in the
              last word of a line (before pressing return.) So, you need to
              map <CR> too.

              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 (but not in i.e.'s)
              let l:line = substitute(l:line, '\<i\>\(\.e\.\)\@!\|\<i$', 'I', 'g')
              call setline(".", l:line)
              endfunction

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

              > -----Original Message-----
              > From: Mark Zealey [mailto:mark@...]
              > Sent: 3 September 2001 21:45
              > To: vim@...
              > Subject: Re: decapitlising on the fly
              >
              >
              > > 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>
              >
              > This is nice, maybe use ''s rather than "'s to avoid the need for
              > lots of \'s...
              >
              > --
              >
              > Mark Zealey (aka JALH on irc.openprojects.net: #zealos and many more)
              > mark@...
              >
              > UL++++>$ G!>(GCM/GCS/GS/GM) dpu? s:-@ a16! C++++>$ P++++>+++++$
              > L+++>+++++$
              > !E---? W+++>$ N- !o? !w--- O? !M? !V? !PS !PE--@ PGP+? r++ !t---?@ !X---?
              > !R- b+ !tv b+ DI+ D+? G+++ e>+++++ !h++* r!-- y--
              >
              > (www.geekcode.com)
            Your message has been successfully submitted and would be delivered to recipients shortly.