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

How to sort the vimgrep result in quickfix?

Expand Messages
  • anhnmncb
    Hi, list, I use vimgrep to search timeline like in my file, and let quckfix show me the result, the result sorted by line nubmer by default, I
    Message 1 of 9 , Dec 1, 2008
    • 0 Attachment
      Hi, list,
      I use vimgrep to search timeline like <\d\+-\d\+-\d\+> in my file, and let
      quckfix show me the result, the result sorted by line nubmer by default, I
      don't know how to let the result sorted by date?

      --
      Regards,
      anhnmncb


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Tony Mechelynck
      ... The quickfix list is always sorted in the order matches (or errors, for a make) were found. But you can use :w filename (or maybe :saveas filename
      Message 2 of 9 , Dec 1, 2008
      • 0 Attachment
        On 01/12/08 13:42, anhnmncb wrote:
        > Hi, list,
        > I use vimgrep to search timeline like<\d\+-\d\+-\d\+> in my file, and let
        > quckfix show me the result, the result sorted by line nubmer by default, I
        > don't know how to let the result sorted by date?
        >

        The quickfix list is always sorted in the order matches (or errors, for
        a make) were found. But you can use ":w filename" (or maybe ":saveas
        filename" which is subtly different) to save a copy and then use the
        ":sort" command. I'm not sure whether the quickfix buffer can be
        modified in situ.

        See
        :help :w_f
        :help :saveas
        :help :sort


        Best regards,
        Tony.
        --
        Sauron is alive in Argentina!

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • anhnmncb
        ... Yes, but I don t want this way, because sometimes I vimgrep a file which has crypted by vim and I don t want so many result written to a file and I forgot
        Message 3 of 9 , Dec 1, 2008
        • 0 Attachment
          On 2008-12-01, Tony Mechelynck wrote:
          >
          > On 01/12/08 13:42, anhnmncb wrote:
          >> Hi, list,
          >> I use vimgrep to search timeline like<\d\+-\d\+-\d\+> in my file, and let
          >> quckfix show me the result, the result sorted by line nubmer by default, I
          >> don't know how to let the result sorted by date?
          >>
          >
          > The quickfix list is always sorted in the order matches (or errors, for
          > a make) were found. But you can use ":w filename" (or maybe ":saveas
          > filename" which is subtly different) to save a copy and then use the
          > ":sort" command.

          Yes, but I don't want this way, because sometimes I vimgrep a file which has
          crypted by vim and I don't want so many result written to a file and I forgot
          to del it.

          I tried to save buffer to a temporary list variable which each atom is a line
          in buffer then sort them and vimgrey, but without lucky (I'm a vimscript
          newbie).


          --
          Regards,
          anhnmncb


          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • anhnmncb
          ... And I see some difference between :sort and sort(), with :sort, you can sort buffer by pattern, which sort() doesn t support. I tried to make quickfix
          Message 4 of 9 , Dec 1, 2008
          • 0 Attachment
            On 2008-12-01, Tony Mechelynck wrote:
            >
            > The quickfix list is always sorted in the order matches (or errors, for
            > a make) were found. But you can use ":w filename" (or maybe ":saveas
            > filename" which is subtly different) to save a copy and then use the
            > ":sort" command. I'm not sure whether the quickfix buffer can be
            > modified in situ.

            And I see some difference between :sort and sort(), with :sort, you can sort
            buffer by pattern, which sort() doesn't support.

            I tried to make quickfix modifiable then sort it then make it unmodifiable,
            but it makes quickfix jumping to relevent line mess up.


            --
            Regards,
            anhnmncb


            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • Tony Mechelynck
            ... Did you try internal :sort in the QF window? If it doesn t work, try moving the contents of the quickfix window to some [No Name] window by :%y in the
            Message 5 of 9 , Dec 1, 2008
            • 0 Attachment
              On 01/12/08 14:59, anhnmncb wrote:
              > On 2008-12-01, Tony Mechelynck wrote:
              >> On 01/12/08 13:42, anhnmncb wrote:
              >>> Hi, list,
              >>> I use vimgrep to search timeline like<\d\+-\d\+-\d\+> in my file, and let
              >>> quckfix show me the result, the result sorted by line nubmer by default, I
              >>> don't know how to let the result sorted by date?
              >>>
              >> The quickfix list is always sorted in the order matches (or errors, for
              >> a make) were found. But you can use ":w filename" (or maybe ":saveas
              >> filename" which is subtly different) to save a copy and then use the
              >> ":sort" command.
              >
              > Yes, but I don't want this way, because sometimes I vimgrep a file which has
              > crypted by vim and I don't want so many result written to a file and I forgot
              > to del it.
              >
              > I tried to save buffer to a temporary list variable which each atom is a line
              > in buffer then sort them and vimgrey, but without lucky (I'm a vimscript
              > newbie).
              >
              >

              Did you try internal ":sort" in the QF window? If it doesn't work, try
              moving the contents of the quickfix window to some [No Name] window by
              ":%y" in the one then ":put" in the other (without the quotes in both
              cases). Then try running an appropriate :sort.


              Vimgrep is not very useful to search a single file (use plain "slash"
              search then). It comes to hand when you have several (maybe many) files
              to search for a given string or regexp.


              IIUC, internal ":sort" (unlike external :!sort which is a filter)
              doesn't need anything to be written out to disk.


              Best regards,
              Tony.
              --
              GALAHAD: No. Look, I can tackle this lot single-handed!
              GIRLS: Yes, yes, let him Tackle us single-handed!
              "Monty Python and the Holy Grail" PYTHON (MONTY)
              PICTURES LTD

              --~--~---------~--~----~------------~-------~--~----~
              You received this message because you are subscribed to the Google Groups "vim_use" group.
              To post to this group, send email to vim_use@...
              To unsubscribe from this group, send email to vim_use+unsubscribe@...
              For more options, visit this group at http://groups.google.com/group/vim_use?hl=en
              -~----------~----~----~----~------~----~------~--~---
            • fritzophrenic
              On Dec 1, 8:56 am, Tony Mechelynck ... If you do this, you can get the line-jumping behavior (sort of) using the gF, ctrl-w F,
              Message 6 of 9 , Dec 2, 2008
              • 0 Attachment
                On Dec 1, 8:56 am, Tony Mechelynck <antoine.mechely...@...>
                wrote:
                > Did you try internal ":sort" in the QF window? If it doesn't work, try
                > moving the contents of the quickfix window to some [No Name] window by
                > ":%y" in the one then ":put" in the other (without the quotes in both
                > cases). Then try running an appropriate :sort.
                >

                If you do this, you can get the line-jumping behavior (sort of) using
                the gF, ctrl-w F, and ctrl-w gF commands.

                > Vimgrep is not very useful to search a single file (use plain "slash"
                > search then). It comes to hand when you have several (maybe many) files
                > to search for a given string or regexp.
                >

                Actually (though I don't do it very often) I can see much potential
                use in brining up the quickfix window with all matches in a single
                file.
                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • Michael Wookey
                ... In my .vimrc, I have the following that searches for all occurrences of the word under the cursor within the current file. The results appear in the
                Message 7 of 9 , Dec 2, 2008
                • 0 Attachment
                  >> Vimgrep is not very useful to search a single file (use plain "slash"
                  >> search then). It comes to hand when you have several (maybe many) files
                  >> to search for a given string or regexp.
                  >
                  > Actually (though I don't do it very often) I can see much potential
                  > use in bringing up the quickfix window with all matches in a single
                  > file.

                  In my .vimrc, I have the following that searches for all occurrences
                  of the word under the cursor within the current file. The results
                  appear in the quickfix window.

                  function! SearchCurrentFile()
                  let l:filename = expand("%")
                  let l:pat = expand("<cword>")
                  execute("vimgrep /".l:pat."/gj ".l:filename)
                  copen
                  endfunction

                  nmap <silent> <Leader>f :execute SearchCurrentFile()<CR>

                  I find this useful while programming to bring up a list that shows all
                  occurrences of a given variable. This makes it easy to see where the
                  variable has been used.

                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_use" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • John Beckett
                  ... Good stuff (BTW the execute in the last line can be just call ). I checked to see if this needed to be added to the wiki, and found that it is covered
                  Message 8 of 9 , Dec 2, 2008
                  • 0 Attachment
                    Michael Wookey wrote:
                    > In my .vimrc, I have the following that searches for all
                    > occurrences of the word under the cursor within the current
                    > file. The results appear in the quickfix window.
                    >
                    > function! SearchCurrentFile()
                    > let l:filename = expand("%")
                    > let l:pat = expand("<cword>")
                    > execute("vimgrep /".l:pat."/gj ".l:filename)
                    > copen
                    > endfunction
                    > nmap <silent> <Leader>f :execute SearchCurrentFile()<CR>

                    Good stuff (BTW the "execute" in the last line can be just "call").

                    I checked to see if this needed to be added to the wiki, and found that it is
                    covered in tip 1543 (with a command rather than a mapping):
                    http://vim.wikia.com/wiki/Find_in_files_within_Vim

                    command GREP :execute 'vimgrep /'.expand('<cword>').'/gj '.expand('%') | copen

                    Can anyone tell me if there is a reason to use "expand('%')" in the above? What
                    about:

                    command GREP2 :execute 'vimgrep /'.expand('<cword>').'/gj %' | copen

                    John


                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_use" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  • fritzophrenic
                    ... Possible bonus of expand: you can search again in the same file if using the command history, even if you are in a different buffer. This would be even
                    Message 9 of 9 , Dec 3, 2008
                    • 0 Attachment
                      On Dec 2, 7:26 pm, "John Beckett" <johnb.beck...@...> wrote:
                      > I checked to see if this needed to be added to the wiki, and found that it is
                      > covered in tip 1543 (with a command rather than a mapping):http://vim.wikia.com/wiki/Find_in_files_within_Vim
                      >
                      > command GREP :execute 'vimgrep /'.expand('<cword>').'/gj '.expand('%') | copen
                      >
                      > Can anyone tell me if there is a reason to use "expand('%')" in the above? What
                      > about:
                      >
                      > command GREP2 :execute 'vimgrep /'.expand('<cword>').'/gj %' | copen
                      >

                      Possible bonus of expand: you can search again in the same file if
                      using the command history, even if you are in a different buffer. This
                      would be even better if expand("%:p") were used instead, since options
                      like autochdir or commands that change the directory would interfere.

                      Just using '%' by itself would always search the current buffer, which
                      would also be useful. Because this is a "search current buffer only"
                      command, I think that not having the expand() would make more sense.

                      Note that for this method of searching a buffer to work, the buffer
                      must be as it appears on the disk.

                      Personally, I use the cabbrev from the same tip mentioned above, so
                      that I have a chance to tweak the command before running the search.
                      --~--~---------~--~----~------------~-------~--~----~
                      You received this message from the "vim_use" maillist.
                      For more information, visit http://www.vim.org/maillist.php
                      -~----------~----~----~----~------~----~------~--~---
                    Your message has been successfully submitted and would be delivered to recipients shortly.