--
Regards,
anhnmncb
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!
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
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
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
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.
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