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

Remap while completion popup is visible

Expand Messages
  • Matteo Landi
    Hi Everyone, I would like to remap the key so that vim will automatically pick the current selected item from the completion popup. I thought it would
    Message 1 of 6 , Jan 4, 2014
    • 0 Attachment

      Hi Everyone,

      I would like to remap the <Tab> key so that vim will automatically pick the current selected item from the completion popup.  I thought it would have been easy but was wrong;  here is what I added to my .vimrc file:

        inoremap <expr> <Tab> pumvisible() ? "\<C-Y>" : "\<Tab>"

      Vim still keeps adding tabs rather than closing the completion popup.  Is it something wrong with that?  Maybe other plugins interfering?  I even found at least two different resources where something like this is done, but none of them worked.


      Cheers,

      Matteo

      [1] http://vim.wikia.com/wiki/Make_Vim_completion_popup_menu_work_just_like_in_an_IDE
      [2] https://github.com/Shougo/neocomplete.vim

      --
      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
       
      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • ZyX
      ... Works for me. Can you show what exactly did you type, what you expected to see as a result and what you saw. Note that ` ` here actually produces
      Message 2 of 6 , Jan 5, 2014
      • 0 Attachment
        On Saturday, January 4, 2014 5:47:29 PM UTC+4, Matteo Landi wrote:
        > Hi Everyone,
        >
        > I would like to remap the <Tab> key so that vim will automatically pick the current selected item from the completion popup.  I thought it would have been easy but was wrong;  here is what I added to my .vimrc file:
        >
        >   inoremap <expr> <Tab> pumvisible() ? "\<C-Y>" : "\<Tab>"
        >
        > Vim still keeps adding tabs rather than closing the completion popup.  Is it something wrong with that?  Maybe other plugins interfering?  I even found at least two different resources where something like this is done, but none of them worked.

        Works for me. Can you show what exactly did you type, what you expected to see as a result and what you saw.

        Note that `"\<C-y>"` here actually produces string `"\"\\\<C-y>\""` instead of `"\"\\<C-y>\""`. I.e. <C-y> gets replaced with control character *before* string evaluation happens meaning that backslashes are useless here. Since backslash-escaped control character inside double quotes is just control character this does not do any harm *except* for misguiding reader about <C-y> handling in this case: it is handled when doing :map argument expansion and not expression evaluation.

        --
        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Matteo Landi
        Imagine I just typed `Hea and the completion popup pops in with the wollowing words: Head, Hearst, Heath, Heather and Heaviside. To autocomplete with
        Message 3 of 6 , Jan 5, 2014
        • 0 Attachment
          Imagine I just typed `Hea' and the completion popup pops in with the wollowing words: Head, Hearst, Heath, Heather and Heaviside.  To autocomplete with `Heater' I would move the selection to the right line using arrow keys or <C-N>/<C-P> and then would confirm the action with either Enter or <C-Y>.

          What happens with the mapping above?  When I press <Tab> to confirm the autocompletion, Vim closes the completion popup and insert a space at the end -- leaving me with `Hea ' instead of `Heather'.

          Is there a way to check for any interfering plugin?  Maybe vim-autocomplpop?


          Cheers


          On Sun, Jan 5, 2014 at 7:03 PM, ZyX <zyx.vim@...> wrote:
          On Saturday, January 4, 2014 5:47:29 PM UTC+4, Matteo Landi wrote:
          > Hi Everyone,
          >
          > I would like to remap the <Tab> key so that vim will automatically pick the current selected item from the completion popup.  I thought it would have been easy but was wrong;  here is what I added to my .vimrc file:
          >
          >   inoremap <expr> <Tab> pumvisible() ? "\<C-Y>" : "\<Tab>"
          >
          > Vim still keeps adding tabs rather than closing the completion popup.  Is it something wrong with that?  Maybe other plugins interfering?  I even found at least two different resources where something like this is done, but none of them worked.

          Works for me. Can you show what exactly did you type, what you expected to see as a result and what you saw.

          Note that `"\<C-y>"` here actually produces string `"\"\\\<C-y>\""` instead of `"\"\\<C-y>\""`. I.e. <C-y> gets replaced with control character *before* string evaluation happens meaning that backslashes are useless here. Since backslash-escaped control character inside double quotes is just control character this does not do any harm *except* for misguiding reader about <C-y> handling in this case: it is handled when doing :map argument expansion and not expression evaluation.

          --
          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.

          --
          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
           
          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Paul
          ... I have this, which works for me: inoremap pumvisible() ? : inoremap pumvisible() ? : --
          Message 4 of 6 , Jan 7, 2014
          • 0 Attachment
            On Saturday, 04 January, 2014 at 13:47:29 GMT, Matteo Landi wrote:
            > inoremap <expr> <Tab> pumvisible() ? "\<C-Y>" : "\<Tab>"

            I have this, which works for me:

            inoremap <expr><tab> pumvisible() ? "\<down>" : "\<tab>"
            inoremap <expr><s-tab> pumvisible() ? "\<up>" : "\<s-tab>"

            --
            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Ben Fritz
            ... By default, Vim will only pop up a completion menu if you explicitly tell it to, by pressing one of the completion key combinations: , ,
            Message 5 of 6 , Jan 7, 2014
            • 0 Attachment
              On Sunday, January 5, 2014 2:13:48 PM UTC-6, Matteo Landi wrote:
              > Imagine I just typed `Hea' and the completion popup pops in

              By default, Vim will only pop up a completion menu if you explicitly tell it to, by pressing one of the completion key combinations: <C-N>, <C-P>, <C-X><C-O>, etc. If your menu pops up automatically as you type, it must be a plugin doing that.

              > with the wollowing words: Head, Hearst, Heath, Heather and Heaviside.  To autocomplete with `Heater' I would move the selection to the right line using arrow keys or <C-N>/<C-P> and then would confirm the action with either Enter or <C-Y>.
              >
              >
              >
              > What happens with the mapping above?  When I press <Tab> to confirm the autocompletion, Vim closes the completion popup and insert a space at the end -- leaving me with `Hea ' instead of `Heather'.
              >
              >
              >
              > Is there a way to check for any interfering plugin?  Maybe vim-autocomplpop?
              >

              You can check to see what mapping is actually active for the <Tab> key, and what file defined that mapping:

              Insert and command-line mode:
              :verbose map! <Tab>

              Normal, operator pending, and visual mode:
              :verbose map <Tab>

              If these commands show your mapping, then there must be some problem with the mapping or Vim settings interfering. If these commands show some other mapping, check the file it says created the mapping.

              Note, if you have the 'paste' option set, your insert-mode mappings will not be used. I'd double-check that option value before doing anything else.

              --
              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php

              ---
              You received this message because you are subscribed to the Google Groups "vim_use" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • Matteo Landi
              Thank you Ben, your suggestion -- :verbose map , helped me figure out the problem. There was indeed another interfering mapping and once removed
              Message 6 of 6 , Jan 7, 2014
              • 0 Attachment
                Thank you Ben, your suggestion -- :verbose map <Tab>, helped me figure out the problem.  There was indeed another interfering mapping and once removed everything worked like a charm.


                Cheers.

                On Tue, Jan 7, 2014 at 5:09 PM, Ben Fritz <fritzophrenic@...> wrote:
                On Sunday, January 5, 2014 2:13:48 PM UTC-6, Matteo Landi wrote:
                > Imagine I just typed `Hea' and the completion popup pops in

                By default, Vim will only pop up a completion menu if you explicitly tell it to, by pressing one of the completion key combinations: <C-N>, <C-P>, <C-X><C-O>, etc. If your menu pops up automatically as you type, it must be a plugin doing that.

                > with the wollowing words: Head, Hearst, Heath, Heather and Heaviside.  To  autocomplete with `Heater' I would move the selection to  the right line using  arrow keys or <C-N>/<C-P> and then would confirm the action with either Enter or <C-Y>.
                >
                >
                >
                > What happens with the mapping above?  When I press <Tab> to confirm the autocompletion, Vim closes the completion popup and insert a space at the end -- leaving me with `Hea ' instead of `Heather'.
                >
                >
                >
                > Is there a way to check for any interfering plugin?  Maybe vim-autocomplpop?
                >

                You can check to see what mapping is actually active for the <Tab> key, and what file defined that mapping:

                Insert and command-line mode:
                  :verbose map! <Tab>

                Normal, operator pending, and visual mode:
                  :verbose map <Tab>

                If these commands show your mapping, then there must be some problem with the mapping or Vim settings interfering. If these commands show some other mapping, check the file it says created the mapping.

                Note, if you have the 'paste' option set, your insert-mode mappings will not be used. I'd double-check that option value before doing anything else.

                --
                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php

                ---
                You received this message because you are subscribed to the Google Groups "vim_use" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                For more options, visit https://groups.google.com/groups/opt_out.

                --
                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php
                 
                ---
                You received this message because you are subscribed to the Google Groups "vim_use" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                For more options, visit https://groups.google.com/groups/opt_out.
              Your message has been successfully submitted and would be delivered to recipients shortly.