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

Effective programming with console vim

Expand Messages
  • Morten Brix Pedersen
    Hi all, I have been programming with console vim on Linux for quite a while now, although now I m curious on how others work with vim. I personally have 2
    Message 1 of 18 , Sep 27, 2001
    • 0 Attachment
      Hi all,

      I have been programming with console vim on Linux for quite a while now,
      although now I'm curious on how others work with vim.

      I personally have 2 Eterms open, with 2 vim sessions, so I can have a
      good overview of at least 2 open files. The biggest problem in this, is
      that I "forget" what buffers I have in each vim session, so I find
      myself opening files in my second vim session, which is already opened
      in my first vim session (getting a message that it's already open).

      Generally, I would just like to hear what people think is the most
      optimal way to work with vim in console. Especially how to keep a good
      overview over (many) open files.

      Thanks.

      - Morten.

      --
      Morten Brix Pedersen <morten@...> - http://www.wtf.dk/hp/
      Copenhagen, Denmark. -- Programmer, Scout, Geek.
    • Hans Fugal
      Something I ve just set up I think will work quite nicely. Using the --remote feature, I ve set an alias for vim so every time I go to edit a file it comes up
      Message 2 of 18 , Sep 27, 2001
      • 0 Attachment
        Something I've just set up I think will work quite nicely. Using the
        --remote feature, I've set an alias for vim so every time I go to edit a
        file it comes up in the same gvim window. So,
        alias vim="`which vim` --remote"
        That way I have only one master gvim floating around (omnipresent on my
        windowmaker desktop) where I edit everything. Thanks to splitting of
        all varieties and my recently-acquired ability to maneuver buffers
        (special thanks to the buffer explorer script, too) it's not hard to be
        comfortable with just one window, and the colors are nicer too. :)

        When you try to open a file that's already open, gvim bring the
        already-open buffer to front. It's slick.

        This brings me to ask another more-or-less related question. I use a
        program at work that uses vim as its editor by writing a temporary file
        and calling vim on that file. I change things, and save it in vim and
        commit the changes in the other program. Then when I'm done, I 'check
        it in' and the other program deletes the temporary file. Vim complains
        about the file no longer existing, and if I'm in a tidy mood I do :bd on
        that buffer. But sometimes I just leave it and go on to another file,
        and have all these buffers referring to files that have disappeared. Is
        there a way to catch that "file no longer available" event in a script,
        so I can close those buffers automatically?

        Thanks,
        Hans :)

        * Morten Brix Pedersen (mbp@...) thus spake:
        > Hi all,
        >
        > I have been programming with console vim on Linux for quite a while now,
        > although now I'm curious on how others work with vim.
        >
        > I personally have 2 Eterms open, with 2 vim sessions, so I can have a
        > good overview of at least 2 open files. The biggest problem in this, is
        > that I "forget" what buffers I have in each vim session, so I find
        > myself opening files in my second vim session, which is already opened
        > in my first vim session (getting a message that it's already open).
        >
        > Generally, I would just like to hear what people think is the most
        > optimal way to work with vim in console. Especially how to keep a good
        > overview over (many) open files.
        >
        > Thanks.
        >
        > - Morten.
        >
        > --
        > Morten Brix Pedersen <morten@...> - http://www.wtf.dk/hp/
        > Copenhagen, Denmark. -- Programmer, Scout, Geek.

        --
        Who is more foolish, the fool or the fool who follows him?
      • Michael Naumann
        My Tip is this: Use gvim if possible. It has more features than termvim. Start only one vim and never stop this (well, of course in appropriate cases do so).
        Message 3 of 18 , Sep 27, 2001
        • 0 Attachment
          My Tip is this:
          Use gvim if possible. It has more features than termvim.
          Start only one vim and never stop this (well, of course in appropriate cases
          do so).
          Use :sp and :sb instead of :e or :n
          Use the smallest possible font suitable for your eyes.
          Use gvim in full-screen-mode in it's dedicated virtual screen.
          And of course have a shortcut to start/switch to gvim.

          Just my two Eurocents,

          Michael

          ----- Original Message -----
          From: "Morten Brix Pedersen" <mbp@...>
          To: <vim@...>
          Sent: Friday, September 28, 2001 12:39 AM
          Subject: Effective programming with console vim


          > Hi all,
          >
          > I have been programming with console vim on Linux for quite a while now,
          > although now I'm curious on how others work with vim.
          >
          > I personally have 2 Eterms open, with 2 vim sessions, so I can have a
          > good overview of at least 2 open files. The biggest problem in this, is
          > that I "forget" what buffers I have in each vim session, so I find
          > myself opening files in my second vim session, which is already opened
          > in my first vim session (getting a message that it's already open).
          >
          > Generally, I would just like to hear what people think is the most
          > optimal way to work with vim in console. Especially how to keep a good
          > overview over (many) open files.
          >
          > Thanks.
          >
          > - Morten.
          >
          > --
          > Morten Brix Pedersen <morten@...> - http://www.wtf.dk/hp/
          > Copenhagen, Denmark. -- Programmer, Scout, Geek.
        • Michael Naumann
          Good trick, your alias, I ll try the idea. But why not simply alias vim= vim --remote which works for me. What is the idea behind this `which vim` ? To your
          Message 4 of 18 , Sep 27, 2001
          • 0 Attachment
            Good trick, your alias, I'll try the idea.
            But why not simply
            alias vim="vim --remote"
            which works for me. What is the idea behind this `which vim` ?

            To your question:
            There are two autocommands (FileChangedShell and FileChangedRO)
            which you may consider using.
            (Type :he au and read all about it)

            HTH, Michael

            ----- Original Message -----
            From: "Hans Fugal" <hans@...>
            To: <vim@...>
            Sent: Friday, September 28, 2001 1:18 AM
            Subject: Re: Effective programming with console vim


            > Something I've just set up I think will work quite nicely. Using the
            > --remote feature, I've set an alias for vim so every time I go to edit a
            > file it comes up in the same gvim window. So,
            > alias vim="`which vim` --remote"
            > That way I have only one master gvim floating around (omnipresent on my
            > windowmaker desktop) where I edit everything. Thanks to splitting of
            > all varieties and my recently-acquired ability to maneuver buffers
            > (special thanks to the buffer explorer script, too) it's not hard to be
            > comfortable with just one window, and the colors are nicer too. :)
            >
            > When you try to open a file that's already open, gvim bring the
            > already-open buffer to front. It's slick.
            >
            > This brings me to ask another more-or-less related question. I use a
            > program at work that uses vim as its editor by writing a temporary file
            > and calling vim on that file. I change things, and save it in vim and
            > commit the changes in the other program. Then when I'm done, I 'check
            > it in' and the other program deletes the temporary file. Vim complains
            > about the file no longer existing, and if I'm in a tidy mood I do :bd on
            > that buffer. But sometimes I just leave it and go on to another file,
            > and have all these buffers referring to files that have disappeared. Is
            > there a way to catch that "file no longer available" event in a script,
            > so I can close those buffers automatically?
            >
            > Thanks,
            > Hans :)
            >
            > * Morten Brix Pedersen (mbp@...) thus spake:
            > > Hi all,
            > >
            > > I have been programming with console vim on Linux for quite a while now,
            > > although now I'm curious on how others work with vim.
            > >
            > > I personally have 2 Eterms open, with 2 vim sessions, so I can have a
            > > good overview of at least 2 open files. The biggest problem in this, is
            > > that I "forget" what buffers I have in each vim session, so I find
            > > myself opening files in my second vim session, which is already opened
            > > in my first vim session (getting a message that it's already open).
            > >
            > > Generally, I would just like to hear what people think is the most
            > > optimal way to work with vim in console. Especially how to keep a good
            > > overview over (many) open files.
            > >
            > > Thanks.
            > >
            > > - Morten.
            > >
            > > --
            > > Morten Brix Pedersen <morten@...> - http://www.wtf.dk/hp/
            > > Copenhagen, Denmark. -- Programmer, Scout, Geek.
            >
            > --
            > Who is more foolish, the fool or the fool who follows him?
          • Hans Fugal
            ... `which vim` just returns the full path to vim. I guess technically there s no reason to do that, I just did a mental search and replace since in my real
            Message 5 of 18 , Sep 27, 2001
            • 0 Attachment
              * Michael Naumann (mnaumann@...) thus spake:
              > Good trick, your alias, I'll try the idea.
              > But why not simply
              > alias vim="vim --remote"
              > which works for me. What is the idea behind this `which vim` ?

              `which vim` just returns the full path to vim. I guess technically
              there's no reason to do that, I just did a mental search and replace
              since in my real alias it's actually pointing to the vim I compiled in
              my user space.

              >
              > To your question:
              > There are two autocommands (FileChangedShell and FileChangedRO)
              > which you may consider using.
              > (Type :he au and read all about it)

              Great, thanks!

              >
              > HTH, Michael
              >
              > ----- Original Message -----
              > From: "Hans Fugal" <hans@...>
              > To: <vim@...>
              > Sent: Friday, September 28, 2001 1:18 AM
              > Subject: Re: Effective programming with console vim
              >
              >
              > > Something I've just set up I think will work quite nicely. Using the
              > > --remote feature, I've set an alias for vim so every time I go to edit a
              > > file it comes up in the same gvim window. So,
              > > alias vim="`which vim` --remote"
              > > That way I have only one master gvim floating around (omnipresent on my
              > > windowmaker desktop) where I edit everything. Thanks to splitting of
              > > all varieties and my recently-acquired ability to maneuver buffers
              > > (special thanks to the buffer explorer script, too) it's not hard to be
              > > comfortable with just one window, and the colors are nicer too. :)
              > >
              > > When you try to open a file that's already open, gvim bring the
              > > already-open buffer to front. It's slick.
              > >
              > > This brings me to ask another more-or-less related question. I use a
              > > program at work that uses vim as its editor by writing a temporary file
              > > and calling vim on that file. I change things, and save it in vim and
              > > commit the changes in the other program. Then when I'm done, I 'check
              > > it in' and the other program deletes the temporary file. Vim complains
              > > about the file no longer existing, and if I'm in a tidy mood I do :bd on
              > > that buffer. But sometimes I just leave it and go on to another file,
              > > and have all these buffers referring to files that have disappeared. Is
              > > there a way to catch that "file no longer available" event in a script,
              > > so I can close those buffers automatically?
              > >
              > > Thanks,
              > > Hans :)
              > >
              > > * Morten Brix Pedersen (mbp@...) thus spake:
              > > > Hi all,
              > > >
              > > > I have been programming with console vim on Linux for quite a while now,
              > > > although now I'm curious on how others work with vim.
              > > >
              > > > I personally have 2 Eterms open, with 2 vim sessions, so I can have a
              > > > good overview of at least 2 open files. The biggest problem in this, is
              > > > that I "forget" what buffers I have in each vim session, so I find
              > > > myself opening files in my second vim session, which is already opened
              > > > in my first vim session (getting a message that it's already open).
              > > >
              > > > Generally, I would just like to hear what people think is the most
              > > > optimal way to work with vim in console. Especially how to keep a good
              > > > overview over (many) open files.
              > > >
              > > > Thanks.
              > > >
              > > > - Morten.
              > > >
              > > > --
              > > > Morten Brix Pedersen <morten@...> - http://www.wtf.dk/hp/
              > > > Copenhagen, Denmark. -- Programmer, Scout, Geek.
              > >
              > > --
              > > Who is more foolish, the fool or the fool who follows him?

              --
              Who is more foolish, the fool or the fool who follows him?
            • Brett Calcott
              Hi, Will this work for you: Get the latest version (6.0), resize the eterm to twice the width and do Ctrl-W V. You now can see 2 files (as before), just as
              Message 6 of 18 , Sep 27, 2001
              • 0 Attachment
                Hi,

                Will this work for you:
                Get the latest version (6.0), resize the eterm to twice the width and do
                Ctrl-W V. You now can see 2 files (as before), just as before, but you have
                only vim - so you can cut and paste, etc.

                Brett
              • Helmut 'Kolbi' Kolb
                Hi Michael! ... What features do you mean? lg -- A list is only as strong as its weakest link. - Don Knuth you ask why? here it s now Friday, September 28,
                Message 7 of 18 , Sep 27, 2001
                • 0 Attachment
                  Hi Michael!

                  On Fri, 28 Sep 2001, Michael Naumann wrote:
                  > [...]
                  > Use gvim if possible. It has more features than termvim.
                  > [..]
                  What features do you mean?

                  lg
                  --
                  A list is only as strong as its weakest link. - Don Knuth
                  you ask why? here it's now Friday, September 28, 2001 05:56!
                  ------------------------------------------------------------------------
                  Helmut 'Kolbi' Kolb - = < > = - http://www.0x13.org
                • Morten Brix Pedersen
                  ... Like what? The only extra features I have seen, is that some scripts manipulate the menu.. - Morten. -- Morten Brix Pedersen -
                  Message 8 of 18 , Sep 27, 2001
                  • 0 Attachment
                    On Fri, Sep 28, 2001 at 01:18:16AM +0200, Michael Naumann wrote:
                    > My Tip is this:
                    > Use gvim if possible. It has more features than termvim.

                    Like what? The only "extra" features I have seen, is that some scripts
                    manipulate the menu..

                    - Morten.

                    --
                    Morten Brix Pedersen <morten@...> - http://www.wtf.dk/hp/
                    Copenhagen, Denmark. -- Programmer, Scout, Geek.
                  • Morten Brix Pedersen
                    Hi Brett, ... Just tried it, it works great comparing to my old solution! Although it feels weird to edit 2 files in vim with vertical split :) but I guess
                    Message 9 of 18 , Sep 27, 2001
                    • 0 Attachment
                      Hi Brett,

                      On Fri, Sep 28, 2001 at 11:37:11AM +1200, Brett Calcott wrote:
                      > Get the latest version (6.0), resize the eterm to twice the width and do
                      > Ctrl-W V. You now can see 2 files (as before), just as before, but you have
                      > only vim - so you can cut and paste, etc.

                      Just tried it, it works great comparing to my old solution! Although it
                      feels weird to edit 2 files in vim with vertical split :) but I guess
                      I'll just have to get used to that.

                      Thanks.

                      - Morten.

                      --
                      Morten Brix Pedersen <morten@...> - http://www.wtf.dk/hp/
                      Copenhagen, Denmark. -- Programmer, Scout, Geek.
                    • Denis Perelyubskiy
                      ... in the very least, the hilighting is much nicer :) .. if you care about that of course ... denis -- // mailto: Denis Perelyubskiy //
                      Message 10 of 18 , Sep 27, 2001
                      • 0 Attachment
                        * Morten Brix Pedersen <mbp@...> [27-Sep-01 22:36 -0700]:
                        >
                        >On Fri, Sep 28, 2001 at 01:18:16AM +0200, Michael Naumann wrote:
                        >> My Tip is this:
                        >> Use gvim if possible. It has more features than termvim.
                        >
                        >Like what? The only "extra" features I have seen, is that some scripts
                        >manipulate the menu..

                        in the very least, the hilighting is much nicer :) .. if you
                        care about that of course ...

                        denis


                        --
                        // mailto: Denis Perelyubskiy <denisp@...>
                        // icq : 12359698
                        // PGP : http://www.cs.ucla.edu/~denisp/files/pgp.asc
                      • Jeff Turner
                        ... Multiple files is the only thing that frustrates me with Vim. I can only really deal with two at once (:e to open the second, then C-6 to switch). Has
                        Message 11 of 18 , Sep 27, 2001
                        • 0 Attachment
                          On Fri, Sep 28, 2001 at 12:39:41AM +0200, Morten Brix Pedersen wrote:
                          > Hi all,
                          >
                          > I have been programming with console vim on Linux for quite a while now,
                          > although now I'm curious on how others work with vim.
                          >
                          > I personally have 2 Eterms open, with 2 vim sessions, so I can have a
                          > good overview of at least 2 open files. The biggest problem in this, is
                          > that I "forget" what buffers I have in each vim session, so I find
                          > myself opening files in my second vim session, which is already opened
                          > in my first vim session (getting a message that it's already open).
                          >
                          > Generally, I would just like to hear what people think is the most
                          > optimal way to work with vim in console. Especially how to keep a good
                          > overview over (many) open files.

                          Multiple files is the only thing that frustrates me with Vim. I can only
                          really deal with two at once (:e to open the second, then C-6 to
                          switch). Has anyone written a script to provide Windows-like toggling
                          between multiple files on alt-tab or C-tab?

                          --Jeff

                          > Thanks.
                          >
                          > - Morten.
                          >
                          > --
                          > Morten Brix Pedersen <morten@...> - http://www.wtf.dk/hp/
                          > Copenhagen, Denmark. -- Programmer, Scout, Geek.
                        • Brett Calcott
                          ... I use this: set hidden map :bn map :bp I recommend the BufExplorer plugin from Johannes Zellner s site as well.
                          Message 12 of 18 , Sep 28, 2001
                          • 0 Attachment
                            >
                            > Multiple files is the only thing that frustrates me with Vim. I can only
                            > really deal with two at once (:e to open the second, then C-6 to
                            > switch). Has anyone written a script to provide Windows-like toggling
                            > between multiple files on alt-tab or C-tab?
                            >

                            I use this:

                            set hidden
                            map <C-Tab> :bn<CR>
                            map <S-C-Tab> :bp<CR>

                            I recommend the BufExplorer plugin from Johannes Zellner's site as well.
                          • Michael Naumann
                            ... From: Denis Perelyubskiy To: Morten Brix Pedersen Cc: Michael Naumann ; vim
                            Message 13 of 18 , Sep 28, 2001
                            • 0 Attachment
                              ----- Original Message -----
                              From: "Denis Perelyubskiy" <denisp@...>
                              To: "Morten Brix Pedersen" <mbp@...>
                              Cc: "Michael Naumann" <mnaumann@...>; "vim" <vim@...>
                              Sent: Friday, September 28, 2001 8:55 AM
                              Subject: Re: Effective programming with console vim


                              > * Morten Brix Pedersen <mbp@...> [27-Sep-01 22:36 -0700]:
                              > >
                              > >On Fri, Sep 28, 2001 at 01:18:16AM +0200, Michael Naumann wrote:
                              > >> My Tip is this:
                              > >> Use gvim if possible. It has more features than termvim.
                              > >
                              > >Like what? The only "extra" features I have seen, is that some scripts
                              > >manipulate the menu..
                              >
                              > in the very least, the hilighting is much nicer :) .. if you
                              > care about that of course ...
                              >

                              And besides this there are thinks like

                              :promptf
                              :promprepl
                              :alt-input
                              :debug-signs
                              :debug-highlight
                              :gui-footer
                              :balloon-eval
                              :browse

                              as well as

                              foreground()
                              remote_foreground()

                              to name only some of them

                              and you can map more key-combinations like e.G <M-S-F5>
                              which does not work for xterm (at least for me) although
                              I did not find a note for this in the docs.

                              HTH, Michael
                            • Jeff Fletcher
                              ... I have: noremap :bn inoremap :bn cnoremap :bn in my .vimrc to do this.
                              Message 14 of 18 , Sep 28, 2001
                              • 0 Attachment
                                > Multiple files is the only thing that frustrates me with Vim. I can only
                                > really deal with two at once (:e to open the second, then C-6 to
                                > switch). Has anyone written a script to provide Windows-like toggling
                                > between multiple files on alt-tab or C-tab?

                                I have:

                                noremap <C-Tab> :bn<CR>
                                inoremap <C-Tab> :bn<CR>
                                cnoremap <C-Tab> :bn<CR>

                                in my .vimrc to do this.
                              • Ed Grimm
                                ... ... ... I personally find it quite helpful to have map ^[^[ :buffers^M map ^[OP :buffer 1^M map ^[OQ :buffer 2^M map ^[OR :buffer 3^M map
                                Message 15 of 18 , Sep 28, 2001
                                • 0 Attachment
                                  On Fri, 28 Sep 2001, Jeff Turner wrote:
                                  > On Fri, Sep 28, 2001 at 12:39:41AM +0200, Morten Brix Pedersen wrote:
                                  >> Hi all,
                                  >>
                                  <snip>
                                  >>
                                  >> I personally have 2 Eterms open, with 2 vim sessions, so I can have a
                                  >> good overview of at least 2 open files. The biggest problem in this, is
                                  >> that I "forget" what buffers I have in each vim session, so I find
                                  >> myself opening files in my second vim session, which is already opened
                                  >> in my first vim session (getting a message that it's already open).
                                  >>
                                  <snip>
                                  >
                                  > Multiple files is the only thing that frustrates me with Vim. I can only
                                  > really deal with two at once (:e to open the second, then C-6 to
                                  > switch). Has anyone written a script to provide Windows-like toggling
                                  > between multiple files on alt-tab or C-tab?

                                  I personally find it quite helpful to have

                                  map ^[^[ :buffers^M
                                  map ^[OP :buffer 1^M
                                  map ^[OQ :buffer 2^M
                                  map ^[OR :buffer 3^M
                                  map ^[OS :buffer 4^M
                                  map ^[[11~ :buffer 1^M
                                  map ^[[12~ :buffer 2^M
                                  map ^[[13~ :buffer 3^M
                                  map ^[[14~ :buffer 4^M
                                  map <F5> :buffer 5^M
                                  map <F6> :buffer 6^M
                                  map <F7> :buffer 7^M
                                  map <F8> :buffer 8^M
                                  map <F9> :buffer 9^M
                                  map <F10> :buffer 10^M
                                  map ^[1 :buffer 11^M
                                  map ^[2 :buffer 12^M
                                  map ^[3 :buffer 13^M
                                  map ^[4 :buffer 14^M
                                  map ^[5 :buffer 15^M
                                  map ^[6 :buffer 16^M
                                  map ^[7 :buffer 17^M
                                  map ^[8 :buffer 18^M
                                  map ^[9 :buffer 19^M
                                  map ^[0 :buffer 20^M

                                  Note that I've changed control characters to ^ representation so my
                                  sendmail doesn't eat them.

                                  The double bindings for buffers 1-4 are due to using screen and multiple
                                  OSes. Yes, I realize this removes :help from F1, but I normally want to
                                  look up something specific, and it's quicker to type it in rather than
                                  navigating through the help tree.

                                  I realize this only works for up to 20 buffers, but extensions should be
                                  obvious.

                                  Ed
                                • C. Porter Bassett
                                  ... have ... I am trying this with gvim on windows. I like it, except for one thing. I will switch over the the right sub-window, and mess it up because I
                                  Message 16 of 18 , Sep 28, 2001
                                  • 0 Attachment
                                    > Get the latest version (6.0), resize the eterm to twice the width and do
                                    > Ctrl-W V. You now can see 2 files (as before), just as before, but you
                                    have
                                    > only vim - so you can cut and paste, etc.

                                    I am trying this with gvim on windows. I like it, except for one thing. I
                                    will switch over the the right sub-window, and mess it up because I wasn't
                                    expecting it to be in insert mode, since it wasn't in insert mode when I was
                                    last in that sub-window.

                                    Is there a way to make the mode switch to command mode when you switch
                                    windows or when you move the prompt with the mouse?
                                  • Benji Fisher
                                    ... It should be possible with a few autocommands. (I am a little worried that someone else will point out that there is already an option for this. Fools
                                    Message 17 of 18 , Sep 28, 2001
                                    • 0 Attachment
                                      "C. Porter Bassett" wrote:
                                      >
                                      > > Get the latest version (6.0), resize the eterm to twice the width and do
                                      > > Ctrl-W V. You now can see 2 files (as before), just as before, but you
                                      > have
                                      > > only vim - so you can cut and paste, etc.
                                      >
                                      > I am trying this with gvim on windows. I like it, except for one thing. I
                                      > will switch over the the right sub-window, and mess it up because I wasn't
                                      > expecting it to be in insert mode, since it wasn't in insert mode when I was
                                      > last in that sub-window.
                                      >
                                      > Is there a way to make the mode switch to command mode when you switch
                                      > windows or when you move the prompt with the mouse?

                                      It should be possible with a few autocommands. (I am a little
                                      worried that someone else will point out that there is already an option
                                      for this. Fools rush in...)

                                      If you switch windows from the keyboard (:help window-move-cursor)
                                      then this is not a problem, so I assume you switch windows with the
                                      mouse. If so, try these mappings. The :vnoremap variant is left as an exercise.

                                      inoremap <LeftMouse> <Esc>:let b:lastmode="Insert"<CR><LeftMouse>
                                      \ :if exists("b:lastmode")&&b:lastmode=="Insert"<Bar>
                                      \ startinsert<Bar>endif<CR>
                                      nnoremap <LeftMouse> :let b:lastmode="Normal"<CR><LeftMouse>
                                      \ :if exists("b:lastmode")&&b:lastmode=="Insert"<Bar>
                                      \ startinsert<Bar>endif<CR>

                                      Note that I use [ni]noremap so that <LeftMouse> is not mapped
                                      recursively. The b:lastmode variable is defined in the old window and
                                      checked in the new window.

                                      HTH --Benji Fisher
                                    • Benji Fisher
                                      ... [snip] ... Oops. I see that I did not read your question carefully, and I forgot to erase my first thought (autocommands). Of course, it is much easier
                                      Message 18 of 18 , Sep 28, 2001
                                      • 0 Attachment
                                        Benji Fisher wrote:
                                        >
                                        > "C. Porter Bassett" wrote:
                                        > >
                                        [snip]
                                        > > Is there a way to make the mode switch to command mode when you switch
                                        > > windows or when you move the prompt with the mouse?
                                        >
                                        > It should be possible with a few autocommands. (I am a little
                                        > worried that someone else will point out that there is already an option
                                        > for this. Fools rush in...)
                                        >
                                        > If you switch windows from the keyboard (:help window-move-cursor)
                                        > then this is not a problem, so I assume you switch windows with the
                                        > mouse. If so, try these mappings. The :vnoremap variant is left as an exercise.
                                        >
                                        > inoremap <LeftMouse> <Esc>:let b:lastmode="Insert"<CR><LeftMouse>
                                        > \ :if exists("b:lastmode")&&b:lastmode=="Insert"<Bar>
                                        > \ startinsert<Bar>endif<CR>
                                        > nnoremap <LeftMouse> :let b:lastmode="Normal"<CR><LeftMouse>
                                        > \ :if exists("b:lastmode")&&b:lastmode=="Insert"<Bar>
                                        > \ startinsert<Bar>endif<CR>
                                        >
                                        > Note that I use [ni]noremap so that <LeftMouse> is not mapped
                                        > recursively. The b:lastmode variable is defined in the old window and
                                        > checked in the new window.
                                        >
                                        > HTH --Benji Fisher

                                        Oops. I see that I did not read your question carefully, and I
                                        forgot to erase my first thought (autocommands). Of course, it is much
                                        easier to do what you asked, and always switch to Normal mode when
                                        switching windows with the mouse. I am not sure what you mean by
                                        "moving the prompt," though.

                                        :imap <LeftMouse> <LeftMouse><Esc>

                                        Note that :inoremap is not needed here (but would work just as well.)

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