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

Re: how can I add this feature to vim!!

Expand Messages
  • David Nečas (Yeti)
    ... http://marc.info/?l=vim&m=117912217106498&w=2 ... set fo+=t you may want other flags beside t (r, o, a, w...), see ... Add it to ~/.xinitrc before the line
    Message 1 of 7 , Jun 1, 2007
      On Fri, Jun 01, 2007 at 01:05:53PM +0800, jaywee wrote:
      > mostly when I press "{", I have to press one more "}" after, because
      > they are always appears at the same time! the same as "()" "[]", and
      > also the quote mark(""). so I wonder how can I add the feature that when
      > I insert "{" or the other punctuations above, it will automatically add
      > "}" !!!

      http://marc.info/?l=vim&m=117912217106498&w=2

      > besides, I wonder how can I make vim to break the line automatically??

      set fo+=t

      you may want other flags beside t (r, o, a, w...), see

      :h 'fo
      :h fo-table

      > and I find a great tip named #166 which tells me how to switch Capslock
      > to esc, the tip goes to like this:
      > add
      > *! Swap caps lock and escape, good for Vim
      > remove Lock = Caps_Lock
      > keysym Escape = Caps_Lock
      > keysym Caps_Lock = Escape
      > add Lock = Caps_Lock
      > *to a file named .speedswapper to the home directory, and run *xmodmap
      > ~/.speedswapper* in a terminal, I follow the guide and finally done! but
      > the bad thing is I have to run the command every time I reboot ubuntu!!

      Add it to ~/.xinitrc before the line executing the window
      manager. Hm, Ubuntu is a desktop distro, so this probably
      won't work... Therefore use the desktop thing that lets you
      set up programs to be run when the desktop is initialized
      and add the command there. Where to find this thing strongly
      depends on the desktop environment.

      > maybe too much questions!

      And so much punctuation...

      Yeti

      --
      http://gwyddion.net/
    • Marc Weber
      Hi jaywee, The simplest way is using a mapping inoremap { { } O which should do what you want. But I myself find this terrible annying because it always
      Message 2 of 7 , Jun 1, 2007
        Hi jaywee,

        The simplest way is using a mapping
        inoremap { {<cr>}<esc>O
        which should do what you want.

        But I myself find this terrible annying because it always inserts those
        closing braces.

        That's why I've written some kind of context sensitive completion
        http://www.mawercer.de/marcweber/vim/installer/vimlib_contextcompletion_installer_sourceme.vim
        After sourceing you can save to different folder and use set runtime+=differentfolder.

        Then you can use

        call vl#lib#completion#contextcompletion#InitContextCompletion(
        \ [ [ "Tab",'<tab>','b:tab_compl']
        \ , [ "MCR" ,"<m-cr>" ,'b:mcr_compl', "\<cr>" ]
        \ , [ "CR" ,"<cr>" ,'b:cr_compl', "\<cr>" ]
        \ , [ "BO" ,"{" ,'b:bo_compl', "{" ]
        \ ]
        \ )

        " this will generate severeal commands
        " You are interested in
        " (BO = brace open ;)

        AddBOCompletion bcm: {\<cr>}\<esc>O

        If you only want this behaviour after functions and whiles I'd suggest
        AddBOCompletion bcm:)$ {\<cr>}\<esc>O

        which means do this only if the regex )$ matches before the cursor

        Here are some further examples which map
        d
        id
        <
        "
        to
        #ifdef
        #include <|>
        #include "|"

        function! vl#dev#cpp#context_completions#AddCPPCompletions()
        AddTabCompletion ^d \<bs>#define ts:
        AddTabCompletion ^id \<bs>\<bs>#ifdef\<cr>#endif\<esc>-A ts:
        AddTabCompletion ^< \<bs>#include\<space><>\<left>
        AddTabCompletion ^\" \<bs>#include\<space>\"\"\<left>
        endfunction

        If more than one context matches you'll get a list or can resolve it by adding
        AddTabCompletion a a\<space>tab\<space>pressed
        AddTabCompletion a a\<space>tab\<space>pressed2 fitness:2

        which means use the second because its fitness is greater.

        I've mapped opening cloning brace to <m-cr> (AddMCRCompletion) to be able to
        decide wether I want this behaviour..

        My scipts are overkill for this task but they might become handy if you
        really many mappings because you can map more than one string/action to
        the same key.

        Marc
      • Michael F. Lamb
        ... If it s a default Ubuntu install, meaning you re a Gnome user, name the file .Xmodmap rather than .speedswapper. When you log in, it should detect it
        Message 3 of 7 , Jun 1, 2007
          jaywee wrote:
          > *! Swap caps lock and escape, good for Vim
          > remove Lock = Caps_Lock
          > keysym Escape = Caps_Lock
          > keysym Caps_Lock = Escape
          > add Lock = Caps_Lock
          > *to a file named .speedswapper to the home directory, and run *xmodmap
          > ~/.speedswapper* in a terminal, I follow the guide and finally done! but
          > the bad thing is I have to run the command every time I reboot ubuntu!!
          > so any helps??

          If it's a default Ubuntu install, meaning you're a Gnome user, name the
          file .Xmodmap rather than .speedswapper. When you log in, it should
          detect it automatically, and ask if you wish to use it.

          You might also find that configuration option available in the Gnome
          "Keyboard Properties" part of the system configuration menu, I'm not sure.
        • Robert Cussons
          ... Hi, I ve been using this tip for ages and find it very useful, but I have the same problem as jaywee and none of the solutions so far suggested have solved
          Message 4 of 7 , Jun 4, 2007
            Michael F. Lamb wrote:
            > jaywee wrote:
            >> *! Swap caps lock and escape, good for Vim
            >> remove Lock = Caps_Lock
            >> keysym Escape = Caps_Lock
            >> keysym Caps_Lock = Escape
            >> add Lock = Caps_Lock
            >> *to a file named .speedswapper to the home directory, and run *xmodmap
            >> ~/.speedswapper* in a terminal, I follow the guide and finally done!
            >> but the bad thing is I have to run the command every time I reboot
            >> ubuntu!!
            >> so any helps??
            >
            > If it's a default Ubuntu install, meaning you're a Gnome user, name the
            > file .Xmodmap rather than .speedswapper. When you log in, it should
            > detect it automatically, and ask if you wish to use it.
            >
            > You might also find that configuration option available in the Gnome
            > "Keyboard Properties" part of the system configuration menu, I'm not sure.
            >

            Hi, I've been using this tip for ages and find it very useful, but I
            have the same problem as jaywee and none of the solutions so far
            suggested have solved the problem. I am using Debian Etch with KDE
            3.5.5. In my home directory, I have tried creating a .xinitrc with the
            same contents as the .speedswapper file (there wasn't one already
            existing), I have tried creating a .Xmodmap file with the same contents
            and I have looked in the KDE control panel for anything that might be
            able to do this, but didn't find anything. It's not a big problem, but
            it just would be nice to have it done automatically :-)

            Thanks for any help,
            Rob.
          • vim@cca.me.uk
            ... Hi, to make commands to be run when your desktop first loads I found this page useful: http://gentoo-wiki.com/HOWTO_Autostart_Programs so, to ensure your
            Message 5 of 7 , Jun 4, 2007
              Robert Cussons wrote:
              > Michael F. Lamb wrote:
              >> jaywee wrote:
              >>> *! Swap caps lock and escape, good for Vim
              >>> remove Lock = Caps_Lock
              >>> keysym Escape = Caps_Lock
              >>> keysym Caps_Lock = Escape
              >>> add Lock = Caps_Lock
              >>> *to a file named .speedswapper to the home directory, and run
              >>> *xmodmap ~/.speedswapper* in a terminal, I follow the guide and
              >>> finally done! but the bad thing is I have to run the command every
              >>> time I reboot ubuntu!!
              >>> so any helps??
              >>
              >> If it's a default Ubuntu install, meaning you're a Gnome user, name
              >> the file .Xmodmap rather than .speedswapper. When you log in, it
              >> should detect it automatically, and ask if you wish to use it.
              >>
              >> You might also find that configuration option available in the Gnome
              >> "Keyboard Properties" part of the system configuration menu, I'm not
              >> sure.
              >>
              >
              > Hi, I've been using this tip for ages and find it very useful, but I
              > have the same problem as jaywee and none of the solutions so far
              > suggested have solved the problem. I am using Debian Etch with KDE
              > 3.5.5. In my home directory, I have tried creating a .xinitrc with the
              > same contents as the .speedswapper file (there wasn't one already
              > existing), I have tried creating a .Xmodmap file with the same
              > contents and I have looked in the KDE control panel for anything that
              > might be able to do this, but didn't find anything. It's not a big
              > problem, but it just would be nice to have it done automatically :-)
              >
              > Thanks for any help,
              > Rob.
              Hi, to make commands to be run when your desktop first loads I found
              this page useful:
              http://gentoo-wiki.com/HOWTO_Autostart_Programs

              so, to ensure your keys get swapped when KDE starts, put the commands
              into any accessible file (~/.speedswapper above). Then create a shell
              script in the appropriate directory for your distribution (on xfce4 here
              it is ~/.config/autostart, and in KDE it is ~/.kde/Autostart) that calls
              xmodmap:

              #!/bin/bash
              xmodmap ~/.speedswapper

              Make that executable (chmod +x ~/.kde/Autostart/swapscript)

              and you should have what you want (just in case any of you are lawyers,
              I, of course, do not mean to imply that this solution will give you
              everything that you want, just the required results of this question).

              cheers

              Chris
            • Robert Cussons
              ... Thanks so much Chris, I should have known to look in the Gentoo pages, they are always very helpful and generally well explained. ... Just have to wait
              Message 6 of 7 , Jun 4, 2007
                vim@... wrote:
                > Robert Cussons wrote:
                >> Michael F. Lamb wrote:
                >>> jaywee wrote:
                >>>> *! Swap caps lock and escape, good for Vim
                >>>> remove Lock = Caps_Lock
                >>>> keysym Escape = Caps_Lock
                >>>> keysym Caps_Lock = Escape
                >>>> add Lock = Caps_Lock
                >>>> *to a file named .speedswapper to the home directory, and run
                >>>> *xmodmap ~/.speedswapper* in a terminal, I follow the guide and
                >>>> finally done! but the bad thing is I have to run the command every
                >>>> time I reboot ubuntu!!
                >>>> so any helps??
                >>>
                >>> If it's a default Ubuntu install, meaning you're a Gnome user, name
                >>> the file .Xmodmap rather than .speedswapper. When you log in, it
                >>> should detect it automatically, and ask if you wish to use it.
                >>>
                >>> You might also find that configuration option available in the Gnome
                >>> "Keyboard Properties" part of the system configuration menu, I'm not
                >>> sure.
                >>>
                >>
                >> Hi, I've been using this tip for ages and find it very useful, but I
                >> have the same problem as jaywee and none of the solutions so far
                >> suggested have solved the problem. I am using Debian Etch with KDE
                >> 3.5.5. In my home directory, I have tried creating a .xinitrc with the
                >> same contents as the .speedswapper file (there wasn't one already
                >> existing), I have tried creating a .Xmodmap file with the same
                >> contents and I have looked in the KDE control panel for anything that
                >> might be able to do this, but didn't find anything. It's not a big
                >> problem, but it just would be nice to have it done automatically :-)
                >>
                >> Thanks for any help,
                >> Rob.
                > Hi, to make commands to be run when your desktop first loads I found
                > this page useful:
                > http://gentoo-wiki.com/HOWTO_Autostart_Programs
                >
                > so, to ensure your keys get swapped when KDE starts, put the commands
                > into any accessible file (~/.speedswapper above). Then create a shell
                > script in the appropriate directory for your distribution (on xfce4 here
                > it is ~/.config/autostart, and in KDE it is ~/.kde/Autostart) that calls
                > xmodmap:
                >
                > #!/bin/bash
                > xmodmap ~/.speedswapper
                >
                > Make that executable (chmod +x ~/.kde/Autostart/swapscript)

                Thanks so much Chris, I should have known to look in the Gentoo pages,
                they are always very helpful and generally well explained.

                >
                > and you should have what you want (just in case any of you are lawyers,
                > I, of course, do not mean to imply that this solution will give you
                > everything that you want, just the required results of this question).

                Just have to wait 'til next time I log out and and in again to see if I
                achieve nirvana... ;-)

                >
                > cheers
                >
                > Chris
                >
              Your message has been successfully submitted and would be delivered to recipients shortly.