Blog

It's minimal, but I'm posting things.


Vim.fzf find string in project

Using the vim.fzf plugin, you here is how to search in files and open the matched file at the matched line number.

" Search string in current project files {{{
function! EditFileAtLineFromFzf(fzf_line)
  let parts = split(a:fzf_line, ":")
  let project_root = getcwd()
  let filepath = parts[0]
  let fileline = parts[1]
  " let filecolumn = parts[2]
  execute 'e ' . project_root . '/' . filepath . '|' . fileline
endfunction
command! -bang -nargs=* SearchInProject
      \ call fzf#vim#grep(
	  \ g:fzf_default_command . ' -- ' . fzf#shellescape(<q-args>) . ' ' . getcwd()  . ' | sed s\|' . getcwd() . '/\|\|',
	  \  fzf#vim#with_preview(
		\ {'sink': function('EditFileAtLineFromFzf'),
		\ 	'options': ['--layout=reverse', '--info=inline', '--preview', "'" . g:fzf_default_preview_command . "'"]}), <bang>0)
"  search string in current working directory files }}}
nnoremap <silent> <leader>wf :SearchInProject<CR>
nnoremap <silent> <C-f> :SearchInProject<CR>

Published on 2025-05-27T05:03:21.455599Z
Last updated on 2025-05-27T05:03:21.455599Z