junegunn / junegunn/fzf.vim

Question/Bug: doing :cd doesn't honor expand('%:p:h') for fzf#run

Open
#1,273 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Vim Script
Stars
10.3k
Forks
608
Avg merge
5d 8h
Merged PRs (30d)
2

Description

- [x] I have fzf 0.23.0 or above
- [x] I have read through https://github.com/junegunn/fzf.vim/blob/master/README.md
- [x] I have read through https://github.com/junegunn/fzf/blob/master/README-VIM.md
- [x] I have read through the manual page of fzf (`man fzf`)
- [x] I have searched through the existing issues

Let's say I change current directory using ``:cd`` to ``~/dira/dirb/dirc``, if I then call following function from any file it always returns fzf results from directory ``dirc``. This does not happen if I do not manually do ``:cd`` after opening neovim (i.e the function correctly recognizes the directory of current file and runs fzf in that directory (``expand('%:p:h')``)).

```vim
function! FZFWithDevIcons()
let l:fzf_files_options = ' -m --bind ctrl-d:preview-page-down,ctrl-u:preview-page-up'
" --preview "bat --color always --style numbers {2..}"

function! s:files()
let l:command = $FZF_DEFAULT_COMMAND . ' ' . expand('%:p:h') . ' | devicon-lookup'
echomsg l:command
let l:files = split(system(l:command), '\n')
return l:files
endfunction

function! s:edit_file(items)
let items = a:items
let i = 1
let ln = len(items)
while i < ln
let item = items[i]
let parts = split(item, ' ')
let file_path = get(parts, 1, '')
let items[i] = file_path
let i += 1
endwhile
call s:Sink(items)
endfunction

let opts = fzf#wrap({})
let opts.source = files()
let s:Sink = opts['sink*']
let opts['sink*'] = function('s:edit_file')
let opts.options .= l:fzf_files_options
call fzf#run(opts)
endfunction
```

P.S. Source of the above snippet: https://github.com/ryanoasis/vim-devicons/issues/106#issuecomment-578685009
P.S. Source of devicon-lookup: https://github.com/coreyja/devicon-lookup

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.