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

quick question

Expand Messages
  • John Levon
    Is there some way to execute normal-mode stuff from an imap without having to map the key sequences Escape, , i (or a) ? i.e. is there some magic
    Message 1 of 17 , Feb 20, 2001
    • 0 Attachment
      Is there some way to execute normal-mode stuff from an "imap"
      without having to map the key sequences Escape, <whatever>, i (or a) ?
      i.e. is there some magic keypress that reads in stuff as normal-mode
      when in insert mode ?

      fwiw, I'm mapping ctrl-j to gq} :

      :imap <C-j> ^V^]gq}<CR>i

      or similar

      thanks
      john

      --
      "Taste is predicated on discrimination."
    • c928400@student.dtu.dk
      ... I would prefer to use instead of ^V^[ (as I suppose you mean). But I digress. Instead of using ...i, is your friend ... See :help
      Message 2 of 17 , Feb 20, 2001
      • 0 Attachment
        Thus wrote John Levon (moz@...) on [010220]:

        > Is there some way to execute normal-mode stuff from an "imap"
        > without having to map the key sequences Escape, <whatever>, i (or a) ?
        > i.e. is there some magic keypress that reads in stuff as normal-mode
        > when in insert mode ?

        > fwiw, I'm mapping ctrl-j to gq} :

        > :imap <C-j> ^V^]gq}<CR>i

        I would prefer to use <Esc> instead of ^V^[ (as I suppose you mean).
        But I digress.

        Instead of using <Esc>...i, <C-O> is your friend

        :imap <C-J> <C-O>gq}

        See ":help i_CTRL-O" and below for a minor issue regarding the use of
        it.

        Peppe
        --
        "Before you criticize someone, walk
        Preben "Peppe" Guldberg __/-\__ a mile in his shoes. That way, if
        c928400@... (o o) he gets angry, he'll be a mile away
        ----------------------oOOo (_) oOOo-- - and barefoot." --Sarah Jackson
      • Arjona, Ariel
        if you represent Alt+m as , how do you represent Alt+Shift+m or Alt+Ctrl+m, and the like? I am using gvim 5.7 on Win2K. thanx in advance Ariel ~ ~
        Message 3 of 17 , Jul 5, 2001
        • 0 Attachment
          if you represent Alt+m as <M-m>, how do you represent Alt+Shift+m or
          Alt+Ctrl+m, and the like?
          I am using gvim 5.7 on Win2K.

          thanx in advance
          Ariel
          ~
          ~
          :wq
        • adam.seyfarth@home.com
          ... Alt+Ctrl+m == Alt+Shift+m == HTH ~~ ``This is the most beautiful coin I have ever seen. It has amazing detail, and that 3D,
          Message 4 of 17 , Jul 5, 2001
          • 0 Attachment
            On Thu, 5 Jul 2001, Arjona, Ariel wrote:

            > if you represent Alt+m as <M-m>, how do you represent Alt+Shift+m or
            > Alt+Ctrl+m, and the like?
            > I am using gvim 5.7 on Win2K.

            Alt+Ctrl+m == <M-C-m>
            Alt+Shift+m == <M-S-m>

            HTH



            ~~
            ``This is the most beautiful coin I have ever seen. It has
            amazing detail, and that 3D, holographic image makes it look
            like it's from some futuristic, sci-fi movie.''
            -- An actual, American, TV commercial

            /|| Adam Seyfarth <http://www2.netdoor.com/~seyfarth/> ||\
            /«|| <mailto:cloud@...> <http://plib.sf.net> ||»\
            \«|| <http://tuxaqfh.sf.net> <http://tuxkart.sf.net> ||»/
            \|| <http://vim.sf.net> <http://www.python.org> ||/



            ~~
            singing person: ``There's nothing quite as wonderful as money,
            There's nothing quite as beautiful as cash...''
            choire: ``money money money money money money money...''
            -- Monty Python::music(unknown)

            /|| Adam Seyfarth <http://www2.netdoor.com/~seyfarth/> ||\
            /«|| <mailto:cloud@...> <http://plib.sf.net> ||»\
            \«|| <http://tuxaqfh.sf.net> <http://tuxkart.sf.net> ||»/
            \|| <http://vim.sf.net> <http://www.python.org> ||/
          • Ondrejko, David
            ... Mmm ... maybe, maybe not. On Win NT 4.0, Alt-Ctrl-m doesn t do a thing; there is no keypress for the program to even act on. I can t seem to get the
            Message 5 of 17 , Jul 5, 2001
            • 0 Attachment
              RE: quick question

              >> if you represent Alt+m as <M-m>, how do you
              >> represent Alt+Shift+m or Alt+Ctrl+m, and the
              >> like?  I am using gvim 5.7 on Win2K.
              >
              > Alt+Ctrl+m == <M-C-m>
              > Alt+Shift+m == <M-S-m>

              Mmm ... maybe, maybe not.  On Win NT 4.0, Alt-Ctrl-m doesn't do a thing; there is no keypress for the program to even act on.  I can't seem to get the Alt-Shift combination to work either, even though there is definitely a keypress associated with it.  Mapping <M-m> works, in that Alt-m performd the mapping, but mapping <M-M> or <M-S-m> doesn't get Alt-Shift-m to do anything (except beep).

              -- Davyd

            • Chris Hudson
              How would I replace every line in a file that starts with certain text, for example every line that begins with 22. Thanks, Chris
              Message 6 of 17 , Dec 1, 2005
              • 0 Attachment
                How would I replace every line in a file that starts with certain text, for
                example every line that begins with 22.

                Thanks,
                Chris
              • Peter Palm
                ... What do you mean by replace every line , replace with what? Given the following contents: 22 one 11 two 33 three 2222 four ... replaces, on every line
                Message 7 of 17 , Dec 1, 2005
                • 0 Attachment
                  Op donderdag 1 december 2005 17:01, schreef Chris Hudson:
                  > How would I replace every line in a file that starts with certain text, for
                  > example every line that begins with 22.

                  What do you mean by "replace every line", replace with what?

                  Given the following contents:
                  22 one
                  11 two
                  33 three
                  2222 four

                  :g/^22/s/o/a/g

                  replaces, on every line beginning with 22, all o's with a's


                  Peter
                • Pete Johns
                  ... See ... Hope this helps; --paj -- Pete Johns Tel/Fax numbers and IM information:
                  Message 8 of 17 , Dec 1, 2005
                  • 0 Attachment
                    On Thu, 2005-12-01 at 10:01:35 -0600, Chris Hudson sent:
                    >How would I replace every line in a file that starts with
                    >certain text, for example every line that begins with 22.
                    >
                    :s/^22.*$/Some Text/

                    See

                    :help :subst

                    Hope this helps;


                    --paj
                    --
                    Pete Johns <http://johnsy.com/>
                    Tel/Fax numbers and IM information: <http://johnsy.com/contact/>
                    Thank You For Th...<http://johnsy.com/blog/?entry=20051130191827>
                  • Tim Chase
                    ... Should be in the tutorial or in the FAQ, but the short answer would be ... If you want lines that begin with 22 , but not 222 , then you can use ... or
                    Message 9 of 17 , Dec 1, 2005
                    • 0 Attachment
                      > How would I replace every line in a file that starts with
                      > certain text, for example every line that begins with 22.

                      Should be in the tutorial or in the FAQ, but the short answer
                      would be

                      :%s/^22.*/certain text

                      If you want lines that begin with "22", but not "222", then you
                      can use

                      :%s/^22\>.*/certain text

                      or

                      :%s/^22[^2].*/certain text

                      If you want to replace arbitrary text only on lines beginning
                      with "22", you can use

                      :g/^22/s/text to change/certain text

                      more info can be found at

                      :help :s
                      :help ordinary-atom
                      :help :g

                      -tim
                    • Chris Allen
                      ... The substitute command. For example: %s/^22.*$/my replacement text/ That would replace anywhere in the whole file (%) a string which started (^) with 22
                      Message 10 of 17 , Dec 1, 2005
                      • 0 Attachment
                        On 01/12/05, Chris Hudson <chudson@...> wrote:
                        > How would I replace every line in a file that starts with certain text, for
                        > example every line that begins with 22.

                        The 'substitute' command. For example:

                        %s/^22.*$/my replacement text/

                        That would replace anywhere in the whole file (%) a string which
                        started (^) with 22 (22) and then continued on with anything (or even
                        nothing) (.*) to the end of the line ($). See also :help :s

                        You can also delete any line starting with a certain string using the
                        :global command, if you decide you'd rather do that. Something like:

                        :g/^22/ d

                        HTH,
                        Chris Allen
                      • Alan G Isaac
                        ... hth, Alan Isaac
                        Message 11 of 17 , Dec 1, 2005
                        • 0 Attachment
                          On Thu, 1 Dec 2005, Chris Hudson apparently wrote:
                          > How would I replace every line in a file that starts with certain text, for
                          > example every line that begins with 22.

                          :g/^22/s/.*/newtext

                          hth,
                          Alan Isaac
                        • Gareth Oakes
                          ... -G
                          Message 12 of 17 , Dec 1, 2005
                          • 0 Attachment
                            To do a regex search/replace:

                            :%s/^22.*/replacement

                            To do some command with each line:

                            :g/^22/some-ex-command


                            -G

                            Chris Hudson wrote:
                            > How would I replace every line in a file that starts with certain text, for
                            > example every line that begins with 22.
                            >
                            > Thanks,
                            > Chris
                            >
                          • Bob Hiestand
                            Message 13 of 17 , Dec 1, 2005
                            • 0 Attachment
                              On 12/1/05, Chris Hudson <chudson@...> wrote:
                              > How would I replace every line in a file that starts with certain text, for
                              > example every line that begins with 22.
                              >
                              > Thanks,
                              > Chris
                              >

                              :g/^22/s/.*/replacement
                            • A. S. Budden
                              ... To read this, find all the files that have a start of line (^) immediately followed by two 2 s and delete them (d) ... Al
                              Message 14 of 17 , Dec 1, 2005
                              • 0 Attachment
                                On 01/12/05, Chris Hudson <chudson@...> wrote:
                                > Sorry, I should have said 'delete' instead of replace. So I guess using your
                                > example I could just replace the line with nothing, like this :$s/^22.*//g

                                A better way of doing that is to use:

                                :g/^22/d

                                To read this, find all the files that have a start of line (^)
                                immediately followed by two '2's and delete them (d)

                                :help :g

                                Al
                              • Wolfgang Schmidt
                                ... if e.g your file lookss as follows ===== LINESTART this is the rest of the first line LINESTART this is the rest of another line etc. ... will: -replace
                                Message 15 of 17 , Dec 1, 2005
                                • 0 Attachment
                                  Chris Hudson schrieb:

                                  >How would I replace every line in a file that starts with certain text, for
                                  >example every line that begins with 22.
                                  >
                                  >Thanks,
                                  >Chris
                                  >
                                  >
                                  if e.g your file lookss as follows

                                  =====
                                  LINESTART this is the rest of the first line
                                  LINESTART this is the rest of another line
                                  etc.
                                  =====

                                  :%s/^LINESTART.*/replacement/gc

                                  will:

                                  -replace every line starting with "LINESTART" with the text
                                  "replacement" and prompt for

                                  In detail:

                                  :%

                                  means "work on all lines of the file"

                                  s/...//gc

                                  means "search and replace globally (g) with confirmation (c)"

                                  ^LINESTART

                                  means "match every occurence of string LINESTART at the beginning of a
                                  line (^)"

                                  .*

                                  means "followed by any character (.) 0 or any times (*)"

                                  Cheers,

                                  Wolfgang
                                • Charles E. Campbell, Jr.
                                  ... If you wanted to avoid lines that began with 221, though... ... Regards, Chip Campbell
                                  Message 16 of 17 , Dec 1, 2005
                                  • 0 Attachment
                                    Chris Hudson wrote:

                                    >How would I replace every line in a file that starts with certain text, for
                                    >example every line that begins with 22.
                                    >
                                    >
                                    >

                                    :g/^22/d

                                    If you wanted to avoid lines that began with 221, though...

                                    :g/^22[^0-9]/d

                                    Regards,
                                    Chip Campbell
                                  • Frans Grotepass
                                    ... Hi Chris and others, This is one of the first decent answers I ve seen on this list. I ve been using (g)Vim now for a number of years sporadically.
                                    Message 17 of 17 , Dec 1, 2005
                                    • 0 Attachment
                                      On Thursday 01 December 2005 17:30, Chris Allen wrote:
                                      > On 01/12/05, Chris Hudson <chudson@...> wrote:
                                      > > How would I replace every line in a file that starts with certain text,
                                      > > for example every line that begins with 22.
                                      >
                                      > The 'substitute' command. For example:
                                      >
                                      > %s/^22.*$/my replacement text/
                                      >
                                      > That would replace anywhere in the whole file (%) a string which
                                      > started (^) with 22 (22) and then continued on with anything (or even
                                      > nothing) (.*) to the end of the line ($). See also :help :s
                                      >
                                      > You can also delete any line starting with a certain string using the
                                      >
                                      > :global command, if you decide you'd rather do that. Something like:
                                      > :g/^22/ d
                                      >
                                      > HTH,
                                      > Chris Allen


                                      Hi Chris and others,

                                      This is one of the first decent answers I've seen on this list. I've been
                                      using (g)Vim now for a number of years sporadically. Recently I've changed
                                      jobs and I now have a development job in embedded linux, so I am using Vim
                                      more often now. The last few months I've made a concerted effort to improve
                                      my Vim skills. Using the Vim Regular expressions is obviously one of the
                                      powerful tools in the search/replace functions. They are explained in the
                                      help.

                                      This response is however a good example of how one can learn via example. Most
                                      of the answers on questions on this list is simply a post of the commandline
                                      and it is assumed that the person asking the question knows what the symbols
                                      mean in the search replace. Your response does however show exactly what each
                                      expression does and makes it easier for the reader helped by your response to
                                      achieve fluency in regular expressions faster.

                                      Best regards,

                                      Frans Grotepass
                                    Your message has been successfully submitted and would be delivered to recipients shortly.