Skip to content

Commit 54a2fed

Browse files
vim: better doc
1 parent 26b2f91 commit 54a2fed

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

.config/cvim/cheats/cheat40.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ Find commits for cur buf :BCommits N
6565
Find normal mode mapping :Maps N
6666
Find help tags :Helptags N
6767
}}}
68+
Search within files and replace{{{
69+
Search within files matching "my-file-pattern' containing "pattern" :grep my-pattern my-file-pattern
70+
View search's grep result :copen
71+
Keep only grep's result in files FOO/bar :cfilter FOO/bar
72+
Filter out all grep's result in files FOO/bar :cfilter! FOO/bar
73+
Filter out the result under the quickfix cursor from grep's result :x
74+
Replace FOO with BAR in grep results :cfdo %s/FOO/BAR/g
75+
}}}
6876
Keycodes {{{2
6977
All keycodes like <S-..>, :keycodes N
7078
}}}

.config/cvim/feature/grep.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,19 @@
44
" upcase search is case sensitive
55
" --uu : seach in all text files, including ignored ones
66
set grepprg=rg\ --vimgrep\ --smart-case\ -uu
7+
8+
" Load ability to filter quickfix search result with :Cfilter FOO/bar
9+
packadd! cfilter
10+
11+
" src: https://blog.beezwax.net/advanced-search-and-replace-with-vim/
12+
function! s:QfRemoveAtCursor() abort
13+
let currline = line('.')
14+
let items = getqflist()->filter({ index -> (index + 1) != currline })
15+
call setqflist(items, 'r')
16+
execute 'normal ' . currline . 'G'
17+
endfunction
18+
19+
augroup quickfix
20+
autocmd!
21+
autocmd FileType qf nnoremap &lt;buffer>&lt;silent> x :call &lt;SID>QfRemoveAtCursor()&lt;CR>
22+
augroup END

0 commit comments

Comments
 (0)