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

automatic uppercase in insert mode

Expand Messages
  • Neil Zanella
    Hello, I would like to know whether vim has a command such as ... which would behave as follows: in command mode everything works the same, but once insert
    Message 1 of 6 , Nov 2, 2003
    • 0 Attachment
      Hello,

      I would like to know whether vim has a command such as

      :set uppercase

      which would behave as follows: in command mode everything
      works the same, but once insert mode is entered (e.g. by
      issuing one of the i, I, a, A, o, O, etc...) commands
      then all [[:isalpha:]] (i.e. alphabetic) characters
      types are uppercase, and lowercase only when the
      shift key is typed.

      This would be useful when writing in programming languages
      such as some assembly where almost everything is uppercase,
      but at the same time you don't want to have the caps lock
      key pressed because that would give you problems in
      command mode.

      Thanks,

      Neil
    • Gumnos (Tim Chase)
      ... I m not sure if this has made it up too far on the todo list. There s an entry in ... listing to disable caps-lock when leaving insert mode. However, it
      Message 2 of 6 , Nov 2, 2003
      • 0 Attachment
        > I would like to know whether vim has a command such as
        >
        > :set uppercase

        I'm not sure if this has made it up too far on the todo list. There's an
        entry in

        :he todo.txt

        listing to disable caps-lock when leaving insert mode. However, it doesn't
        seem to be available in my 6.1

        One workaround, if you really must have it, would be to do a slew (26, to be
        exact) of insert mappings that would prevent you from entering lowercase
        letters. If you really wanted them, you could either have 26 more mappings
        (for the uppercase letters to lc letters), or you could possibly write one
        generic function that would query some global (or buffer-global) "caps lock"
        flag, which you could toggle via another character (say, tilde, or some such
        character).

        :inoremap a A
        :inoremap b B
        :
        :
        :inoremap z Z

        It's an ugly & dirty solution, but it could do the job.

        Alternatively, you could make use of the gU command and post-process it
        after entering it--that way, you'd be able to enter all your commands in
        whatever case you like, but then let the gU<motion> convert it to uppercase
        after the fact. The help on gU even offers a macro for making the last word
        typed uppercase.

        HTH,

        -tim
      • Antoine J. Mechelynck
        ... I don t know if this exists, but if it doesn t, it looks to me like the ideal thing to be solved by a keymap, as follows: loadkeymap a A b B c C
        Message 3 of 6 , Nov 2, 2003
        • 0 Attachment
          Neil Zanella <nzanella@...> wrote:
          > Hello,
          >
          > I would like to know whether vim has a command such as
          >
          > > set uppercase
          >
          > which would behave as follows: in command mode everything
          > works the same, but once insert mode is entered (e.g. by
          > issuing one of the i, I, a, A, o, O, etc...) commands
          > then all [[:isalpha:]] (i.e. alphabetic) characters
          > types are uppercase, and lowercase only when the
          > shift key is typed.
          >
          > This would be useful when writing in programming languages
          > such as some assembly where almost everything is uppercase,
          > but at the same time you don't want to have the caps lock
          > key pressed because that would give you problems in
          > command mode.
          >
          > Thanks,
          >
          > Neil

          I don't know if this exists, but if it doesn't, it looks to me like the
          ideal thing to be solved by a keymap, as follows:

          loadkeymap
          a A
          b B
          c C
          ...
          y Y
          z Z
          A a
          B b
          ...
          Y y
          Z z

          The ... are not to be entered literally, they mean "and so on".

          See
          :help language-mapping
          :help mbyte-keymap
          :help keymap-file-format
          etc.

          HTH,
          Tony.
        • Keith Roberts
          ... Yuck! [IMHO] I have a similar situation, but prefer to use a few mappings to Upcase as I m typing (or shortly thereafter). In the language I use, ; is
          Message 4 of 6 , Nov 3, 2003
          • 0 Attachment
            >-----Original Message-----
            >From: Antoine J. Mechelynck [mailto:antoine.mechelynck@...]
            >Sent: Sunday, November 02, 2003 3:16 PM
            >To: Neil Zanella; Vim Mailing List
            >Subject: Re: automatic uppercase in insert mode
            >
            >Neil Zanella <nzanella@...> wrote:
            >> Hello,
            >>
            >> I would like to know whether vim has a command such as
            >>
            >> > set uppercase
            >>[...]
            >> This would be useful when writing in programming languages
            >> such as some assembly where almost everything is uppercase,
            >>[...]
            >
            >I don't know if this exists, but if it doesn't, it looks to me like the
            >ideal thing to be solved by a keymap, as follows:
            >
            > loadkeymap
            > a A
            > b B
            > c C
            >...
            > y Y
            > z Z
            > A a
            > B b
            >...
            > Y y
            > Z z

            Yuck! [IMHO]

            I have a similar situation, but prefer to use a few mappings to Upcase as
            I'm typing (or shortly thereafter). In the language I use, ';' is a command
            separator, and '*' is the comment leader. In normal mode, it advances by
            one line each time, allowing consecutive lines to be easily upcased w/o
            having to do a visual selection first:

            " Upcase current word
            map <F1> gUaww
            imap <F1> <ESC>m`gUaw``a

            " Upcase current line, up to but not including comment
            map ,U :call setline('.', substitute(getline('.'),
            '^.*\ze\(;\s*\*.*\)\\|.*', '\U&', ''))<cr>
            map <m-u> ,Uj
            imap <m-u> <c-o>,U
          • Antoine J. Mechelynck
            ... [...] ... [...] ... [...] You don t have to use it if it s not to your liking; but it s the kind of thing that you would write once, and later it s just
            Message 5 of 6 , Nov 3, 2003
            • 0 Attachment
              Keith Roberts <kroberts@...> wrote:
              > > -----Original Message-----
              > > From: Antoine J. Mechelynck [mailto:antoine.mechelynck@...]
              [...]
              > > I don't know if this exists, but if it doesn't, it looks to me like
              > > the ideal thing to be solved by a keymap, as follows:
              [...]
              > Yuck! [IMHO]
              [...]

              You don't have to use it if it's not to your liking; but it's the kind of
              thing that you would write once, and later it's just one keypress (Ctrl-^ by
              default) to turn it on or off. An additional line at the top of the keymap
              can even let you change the cursor color to remind you if uppercase mode is
              on or off. Of course my solution is not applicable if you want to write
              program code with implicit uppercase and then add comments in, let's say,
              Russian (using a different keymap). One will have to resort to uppercasing
              program text by means of Caps Lock then, or to doing it a posteriori as you
              do.

              Regards,
              Tony.
            • Benji Fisher
              ... There are advantages and disadvantages to using a keymap. Advantages: you get a reminder in the status line, it works with my script word_complete.vim ,
              Message 6 of 6 , Nov 4, 2003
              • 0 Attachment
                On Mon, Nov 03, 2003 at 12:15:36AM +0100, Antoine J. Mechelynck wrote:
                >
                > I don't know if this exists, but if it doesn't, it looks to me like the
                > ideal thing to be solved by a keymap, as follows:
                >
                > loadkeymap
                > a A
                > b B
                > c C
                > ...
                > y Y
                > z Z
                > A a
                > B b
                > ...
                > Y y
                > Z z
                >
                > The ... are not to be entered literally, they mean "and so on".
                >
                > See
                > :help language-mapping
                > :help mbyte-keymap
                > :help keymap-file-format
                > etc.
                >
                > HTH,
                > Tony.

                There are advantages and disadvantages to using a keymap.
                Advantages: you get a reminder in the status line, it works with my
                script word_complete.vim , others?
                Disadvantages: it also applies in search commands, etc., which I would
                find confusing. (YMMV) It will not work with any other keymaps you may
                have (as someone else already pointed out, I think).

                The attached script defines :inoremap's to accomplish much the same
                thing. You can turn caps lock on or off, or toggle it or just ask for
                the status with

                :CapsLock [on|off|!|?]

                (The usual abbreviation rules apply, so you can probably use "Caps", or
                maybe just "C", instead of "CapsLock".)

                In the comments at the top, I have left the "Maintainer" line
                empty. If anyone likes this and wants to adopt the script and post it,
                be my guest.

                HTH --Benji Fisher
              Your message has been successfully submitted and would be delivered to recipients shortly.