dyng / ctrlsf.vim

A text searching plugin mimics Ctrl-Shift-F on Sublime Text 2
1.59k stars 86 forks source link

Sync CtrlSF compact window when navigating via quickfix #340

Closed PezCoder closed 1 year ago

PezCoder commented 1 year ago

A thank you note ❤️

First off, I want to thank you immensely for making this plugin! I think it works superbly out of the box, which is rarely the case with the plugins within VIM community.

I've had a terrible experience with other searches like rg, ack & their integration with VIM - as it required a lot of tweaks for basic features that modern IDEs provide.

Issue description

I'm using compact view with the setting to enable populating the quickfix list. Since I've primarily migrated from using vim-ack which pretty much uses quickfix list extensively & opens that after search completion which stays in sync with where the user is in the quickfix list.

With CtrlSF, with the settings mentioned, you may search for a keyword & it populates 10 results, even if you keep navigating the quickfix using :cnext to 7th word, it doesn't updates the position of the cursor within CTRLSF search results window.

The expectation is for it to behave like quickfix window (if possible), or if there is a way for me to rather trigger :copen at the end of search instead of CTRLSF's window, that would also be great. The only caveat is, I wouldn't be able to leverage edit mode if I use quick fix list.

Here is a video of how quickfix list work: https://asciinema.org/a/XWEijrJrtNhZGiSvmJUj7RKy5

Here is a video of how CtrlSF window works with the provided settings: https://asciinema.org/a/KE39Zrf06KBo2Dpa4UxoAzyyh

Things about your system and environment(请在此填写你的系统信息)

field value
os OS X Ventura 13.4 (22F66)
vim NVIM v0.7.0
backend ripgrep 13.0.0
locale ?
dyng commented 1 year ago

Sorry for this late reply, and thank you for your appreciation!

Compact mode is an interface that looks like quickfix but does not share same behaviors, if you prefer real quickfix window, a quick & dirty solution is using g:CtrlSFAfterMainWindowInit hook.

function! g:CtrlSFAfterMainWindowInit()
    close
    copen
endfunction

Compact mode is a design choice when I didn't fully understand quickfix window. As there are many plugins which enhance quickfix window recently, maybe I'll deprecate the compact mode later.

PezCoder commented 1 year ago

Thank you for the help! @dyng - This works great ❤️

I'm assuming there wouldn't be a way to get the best of both worlds is it? - I mean having a way to rename things (edit mode) + quick fix list together.

PezCoder commented 1 year ago

I think let me close this issue as I got the answer for the quickfix list, I had created a separate issue asking that here: https://github.com/dyng/ctrlsf.vim/issues/339

PezCoder commented 10 months ago

Just want to let you know that, the above suggested solution to provide CtrlSFAfterMainWindowInit has some edgecase, especially when doing repeat searches breaks with the following error:

" previous config
let g:ctrlsf_default_view_mode = 'compact' " Quickfix like view
let g:ctrlsf_populate_qflist = 1
let g:ctrlsf_auto_close = {
    \ "compact": 0
    \}
let g:ctrlsf_mapping = {
    \ "next": "j",
    \ "prev": "k",
    \ }
let g:ctrlsf_auto_focus = {
    \ "at": "start"
    \ }
nnoremap <Leader>/ :CtrlSF<Space>

" Opens quickfix window instead of compact window
" Because compact window doesn't stay in sync with quickfix
" https://github.com/dyng/ctrlsf.vim/issues/340
function! g:CtrlSFAfterMainWindowInit()
  close
  copen
endfunction
Error detected while processing function ctrlsf#Search[15]..<SNR>107_ExecS
earch[19]..<SNR>107_DoSearchAsync[4]..<SNR>107_Open[1]..ctrlsf#win#OpenMai
nWindow[67]..<SNR>108_InitMainWindow:
line    7:
E21: Cannot make changes, 'modifiable' is off: fileformat=unix
Press ENTER or type command to continue

Removing that function & using the following configuration worked for me 🎉

" New config
let g:ctrlsf_default_view_mode = 'compact' " Quickfix like view

" Use quick fix list to populate & open instead of ctrlsf window
" https://github.com/dyng/ctrlsf.vim/issues/340
let g:ctrlsf_populate_qflist = 1
let g:ctrlsf_auto_close = 1
let g:ctrlsf_auto_qf = 1

let g:ctrlsf_mapping = {
    \ "next": "j",
    \ "prev": "k",
    \ }
let g:ctrlsf_auto_focus = {
    \ "at": "start"
    \ }
nnoremap <Leader>/ :CtrlSF<Space>