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

Re: decapitlising on the fly

Expand Messages
  • 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 1 of 6 , Sep 3, 2001
    • 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 2 of 6 , Sep 3, 2001
      • 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 3 of 6 , Sep 3, 2001
        • 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 4 of 6 , Sep 7, 2001
          • 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.