lotabout / skim.vim

vim support for skim
132 stars 19 forks source link

floating window #4

Closed ahmedelgabri closed 5 years ago

ahmedelgabri commented 5 years ago

fzf.vim supports passing a function to let g:fzf_layout = { 'window': 'call FloatingFZF()' } so that you can open the search results in a floating window. https://github.com/junegunn/fzf.vim/issues/664 That doesn't seem to be working with skim.vim though?

lotabout commented 5 years ago

@ahmedelgabri Sorry for late response, you could use let g:skim_layout = { 'window': 'call FloatingFZF()' } for it.

ahmedelgabri commented 5 years ago

@lotabout no worries & thanks!

One last question, can I assume that anything g:fzf_* will be g:skim_* then?

ahmedelgabri commented 5 years ago

I also have two more issues, the preview doesn't seem to be working inside vim nor the ESC key.

This is my config for skim.

if !exists(':SK')
  finish
endif

if !empty(expand($SKIM_CTRL_T_OPTIONS))
  let g:skim_files_options = $SKIM_CTRL_T_OPTIONS . ' --preview-window down:60% '
endif

let g:skim_layout = { 'window': 'enew' }
let g:skim_history_dir = expand('~/.skim-history')
let g:skim_buffers_jump = 1
let g:skim_tags_command = 'ctags -R'

imap <c-x><c-k> <plug>(skim-complete-word)
imap <c-x><c-f> <plug>(skim-complete-path)
imap <c-x><c-j> <plug>(skim-complete-file-ag)
imap <c-x><c-l> <plug>(skim-complete-line)

nnoremap <silent> <leader><leader> :Files<cr>
nnoremap <silent> <Leader>b :Buffers<cr>
nnoremap <silent> <Leader>h :Helptags<cr>

function! s:skim_statusline() abort
  setlocal statusline=%4*\ skim\ %6*V:\ ctrl-v,\ H:\ ctrl-x,\ Tab:\ ctrl-t
endfunction

augroup MySKIM
  autocmd!
  autocmd! User skimStatusLine call <SID>skim_statusline()
augroup END

function! SkimSpellSink(word)
  exe 'normal! "_ciw'.a:word
endfunction

function! SkimSpell()
  let suggestions = spellsuggest(expand('<cword>'))
  return skim#run({'source': suggestions, 'sink': function('SkimSpellSink'), 'down': 10 })
endfunction

nnoremap z= :call SkimSpell()<CR>
export SKIM_DEFAULT_OPTIONS='--min-height 30 --height 50% --reverse --tabstop 2 --multi --margin 0,3,3,3'
export SKIM_CTRL_T_OPTIONS='--preview-window right:50% --preview "(bat --style=numbers,changes --wrap never --color always {} || highlight -O ansi -l {} || cat {} || tree -C {}) 2> /dev/null | head -500" --bind "?:toggle-preview"'
export SKIM_CTRL_R_OPTIONS="--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview' --bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort' --header 'Press CTRL-Y to copy command into clipboard' --border"
export SKIM_ALT_C_OPTIONS="--preview 'tree -C {} 2> /dev/null | head -200'"
lotabout commented 5 years ago

@ahmedelgabri

One last question, can I assume that anything g:fzf* will be g:skim* then?

Unfortunately you can't. The functions fzf are divided into two part, the ones in fzf repo and others in fzf.vim repo. Likewise you could assume all the functions in skim repo are prefixed with skim, but those in skim.vim remained fzf_*.

To be clear, only the following variables/functions are prefixed with skim.

g:skim_colors
g:skim_layout
g:skim_history_dir
g:skim_action
g:skim_prefer_tmux
g:skim_launcher

skim#run
skim#shellescape
skim#wrap
ahmedelgabri commented 5 years ago

Thanks @lotabout, any pointers on why preview & Esc are not working too?

I also have two more issues, the preview doesn't seem to be working inside vim nor the ESC key.

This is my config for skim.

if !exists(':SK')
  finish
endif

if !empty(expand($SKIM_CTRL_T_OPTIONS))
  let g:skim_files_options = $SKIM_CTRL_T_OPTIONS . ' --preview-window down:60% '
endif

let g:skim_layout = { 'window': 'enew' }
let g:skim_history_dir = expand('~/.skim-history')
let g:skim_buffers_jump = 1
let g:skim_tags_command = 'ctags -R'

imap <c-x><c-k> <plug>(skim-complete-word)
imap <c-x><c-f> <plug>(skim-complete-path)
imap <c-x><c-j> <plug>(skim-complete-file-ag)
imap <c-x><c-l> <plug>(skim-complete-line)

nnoremap <silent> <leader><leader> :Files<cr>
nnoremap <silent> <Leader>b :Buffers<cr>
nnoremap <silent> <Leader>h :Helptags<cr>

function! s:skim_statusline() abort
  setlocal statusline=%4*\ skim\ %6*V:\ ctrl-v,\ H:\ ctrl-x,\ Tab:\ ctrl-t
endfunction

augroup MySKIM
  autocmd!
  autocmd! User skimStatusLine call <SID>skim_statusline()
augroup END

function! SkimSpellSink(word)
  exe 'normal! "_ciw'.a:word
endfunction

function! SkimSpell()
  let suggestions = spellsuggest(expand('<cword>'))
  return skim#run({'source': suggestions, 'sink': function('SkimSpellSink'), 'down': 10 })
endfunction

nnoremap z= :call SkimSpell()<CR>
export SKIM_DEFAULT_OPTIONS='--min-height 30 --height 50% --reverse --tabstop 2 --multi --margin 0,3,3,3'
export SKIM_CTRL_T_OPTIONS='--preview-window right:50% --preview "(bat --style=numbers,changes --wrap never --color always {} || highlight -O ansi -l {} || cat {} || tree -C {}) 2> /dev/null | head -500" --bind "?:toggle-preview"'
export SKIM_CTRL_R_OPTIONS="--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview' --bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort' --header 'Press CTRL-Y to copy command into clipboard' --border"
export SKIM_ALT_C_OPTIONS="--preview 'tree -C {} 2> /dev/null | head -200'"
lotabout commented 5 years ago

@ahmedelgabri

Thanks @lotabout, any pointers on why preview & Esc are not working too?

I believe preview window not shown because there is no preview command? Adding let g:fzf_files_options = '--preview="echo {}" --preview-window down:60% ' did bring up the preview window.

As for Esc key, it worked on my machine with your configuration.

ahmedelgabri commented 5 years ago

I believe preview window not shown because there is no preview command? Adding let g:fzf_files_options = '--preview="echo {}" --preview-window down:60% ' did bring up the preview window.

But I'm setting let g:fzf_files_options already to $SKIM_CTRL_T_OPTIONS which contains preview command.

As for Esc key, it worked on my machine with your configuration.

Ok, will see if I have anything wrong in my config then. Because it seems that it works in the CLI fine but not inside vim.

ahmedelgabri commented 5 years ago

Ok so this doesn't work. Which I assume because I'm trying to override the --preview-window from $SKIM_CTRL_T_OPTIONS

let g:skim_files_options = $SKIM_CTRL_T_OPTIONS . ' --preview-window down:60% '

Which is basically something like this

--preview-window right:50% --preview "cat {}" --bind "?:toggle-preview" --preview-window down:60% 

Running this manually in the CLI works fine & the last --preview-window is applied but not inside vim.