dyng / ctrlsf.vim

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

preview window positioning #304

Closed ri-aje closed 3 years ago

ri-aje commented 3 years ago

Before submitting your issue(请在提交 issue 前一定要检查以下项目!)

  1. Update to the latest version of CtrlSF.
  2. Update your backend(ag/ack/pt/rg) to their latest version.
  3. Enable debug mode to try to find what is going wrong yourself. You can enable debug mode by let g:ctrlsf_debug_mode = 1.

If you can't find out why things do not work or can be sure it's a bug of CtrlSF, please fulfill below issue template. Thanks in advance!

Issue template

Issue description

You can describe your issue here.(请将你的 issue 内容填写于此) is there anyway to control the preview window position? I cannot find such a flag in the doc. I searched issue history here, and found some relevant discussions, e.g., https://github.com/dyng/ctrlsf.vim/issues/31 and https://github.com/dyng/ctrlsf.vim/issues/161. but the discussions are messy and conclusions unclear, so I started this one.

I use auto preview and default ctrlsf window position (on the left). when I go through the matches in ctrlsf window, the preview window is shown right next to the ctrlsf window, and pushing my original window (from which the ctrlsf command was launched) further out to the right. my vim window then becomes three major pillars, left most one being ctrlsf window, middle one being ctrlsf preview window, right most one (and this one is only partially shown, and some times just a tiny portion) being my original window (which by the way may contain other splits). the overall presentation is then pretty confusing, and ctrlsf key to open in original window is pretty much useless because the original window is on the far right and only a tiny portion is visible.

can you provide a way to specify where ctrlsf preview is placed? for me personally, I would like it in the same pillar as ctrlsf such as a horizontal split placed on the lower half. I checked out issue history and noticed other people may have different preference, and I bet there will never be a consensus on what's the best layout, so making it configurable seems the best option.

and related, is there anyway to turn off the ctrlsf preview window when I press enter and jump to the original window? I am thinking the ctrlsf preview is useful when I work in ctrlsf window. once I jumped to the original window, it means I will focus on this one file for now, and the preview becomes useless since I have the whole buffer under my cursor anyway, so the preview better goes away to surrender its visual space for better use. makes sense?

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

field value
os ubuntu 18.04
vim VIM - Vi IMproved 8.2 Included patches: 1-1897
backend ripgrep 0.10.0 (rev 8a7db1a918)
locale en_US.UTF-8

let mapleader = ' '

call plug#begin('~/.vim/bundle') Plug 'dyng/ctrlsf.vim' call plug#end()

nnoremap a :CtrlSF -R ""

let g:ctrlsf_ackprg = '/usr/bin/rg' let g:ctrlsf_auto_close = { \ "normal" : 0, \ "compact": 0 \ } let g:ctrlsf_auto_focus = { \ "at": "done", \ "duration_less_than": 1000 \ } let g:ctrlsf_auto_preview = 1 let g:ctrlsf_default_root = 'project' let g:ctrlsf_search_mode = 'async'



- file:
an empty vim buffer will demonstrate the issue.
dyng commented 3 years ago

I have implemented a new option ctrlsf_preview_position, please checkout the feature branch and have a try. Any feedback is welcome.

ri-aje commented 3 years ago

I have implemented a new option ctrlsf_preview_position, please checkout the feature branch and have a try. Any feedback is welcome.

thanks for the quick turnaround. new positioning worked great for me. two notes:

  1. any chance to implement auto close preview upon opening a match in the original window? since the original window has the whole buffer, there seems to be no need for the preview window for the moment, and its screen can be relieved for other use.
  2. ctrlsf seems broken with https://github.com/dyng/ctrlsf.vim/commit/b8b0a669c6157050d64b9e5be4785035581ede7f. I have to revert that commit to test your change. with that commit, I ran CtrlSF -R "search", and I got
    Error detected while processing function ctrlsf#Search[15]..<SNR>179_ExecSearch[18]..<SNR>179_DoSearchAsync[1]..ctrlsf#backend#RunAsync[4]..<SNR>189_BuildCommand[113]..ctrlsf#opt#GetPath[30]..ctrlsf#fs#FindProject
    Root:
    line   11:
    E121: Undefined variable: marker
    E116: Invalid arguments for function empty(marker)

    worked right before that commit, so pretty clear that's a regression point.

in case it matters, below is my ctrlsf settings

 nnoremap <leader>a :CtrlSF -R "<c-r>=expand('<cword>')<cr>"<Left>
 vnoremap <leader>a :<c-u>CtrlSF -R "<c-r>=<sid>zm_get_visual_selection_escaped()<cr>"<Left>
 nnoremap <leader>A <Plug>CtrlSFVwordExec<cr>
 if s:zm_linux
  let g:ctrlsf_ackprg = '/usr/bin/rg'
 elseif s:zm_osx
  let g:ctrlsf_ackprg = '/usr/local/bin/rg'
 endif
 let g:ctrlsf_default_root = 'project'
 let g:ctrlsf_mapping = {
    \ "next": "n",
    \ "prev": "N",
    \ }
 let g:ctrlsf_auto_close = {
    \ "normal" : 0,
    \ "compact": 0
    \ }
 let g:ctrlsf_auto_focus = {
    \ "at": "done",
    \ "duration_less_than": 1000
    \ }
 let g:ctrlsf_auto_preview = 1
 let g:ctrlsf_search_mode = 'async'
 let g:ctrlsf_preview_position = 'inside' " preview window splits ctrlsf pillar.

let me know if I should file a separate bug report. thanks.

kevinhwang91 commented 3 years ago
Error detected while processing function ctrlsf#Search[15]..<SNR>179_ExecSearch[18]..<SNR>179_DoSearchAsync[1]..ctrlsf#backend#RunAsync[4]..<SNR>189_BuildCommand[113]..ctrlsf#opt#GetPath[30]..ctrlsf#fs#FindProject
Root:
line   11:
E121: Undefined variable: marker
E116: Invalid arguments for function empty(marker)

https://github.com/dyng/ctrlsf.vim/pull/305

dyng commented 3 years ago

any chance to implement auto close preview upon opening a match in the original window? since the original window has the whole buffer, there seems to be no need for the preview window for the moment, and its screen can be relieved for other use.

makes sense for your use case (let g:ctrlsf_auto_close = 0), I'll address it.

ctrlsf seems broken with b8b0a66.

I have fixed it, sorry for the inconvenience to you! (and @kevinhwang91 )

dyng commented 3 years ago

@ri-aje I have updated the code branch, please have a try!

ri-aje commented 3 years ago

@ri-aje I have updated the code branch, please have a try!

thank you. worked great to my test. I will just wait for it merged.