2

I use ctrlx f to autocomplete the file path. But the popup window won't have the dot file (hidden file, here it is the .obsidian.vimrc file I want to find) unless I press . first, then press ctrlx f.

I checked this link https://stackoverflow.com/questions/34122136/autocomplete-hidden-files-in-vim and added the code:

set wildignore-=.*
set wildignore-=*.vimrc

But this won't work. How do I fix it?

0

1 Answer 1

0

We can use a custom function that adds dot-prepended files and directories if there is no pattern before the cursor position.

function! MyCompleteFileName() abort
  " match a (potential) wildcard preceding cursor position
  " NOTE: \f is a filename character, see :h 'isfname'
  let l:pattern = matchstr(strpart(getline('.'), 0, col('.') - 1), '\v(\f|\*|\?)*$')
  let l:file_comp_list = getcompletion(l:pattern, "file")
  if l:pattern == ''
    let l:file_comp_list += getcompletion(".", "file")
  endif
  " let l:file_comp_list += getcompletion(l:pattern, "file_in_path")
  call complete(col('.') - len(l:pattern), l:file_comp_list)

  " must return an empty string to show the menu
  return ''
endfunction

inoremap <C-x><C-F> <C-R>=MyCompleteFileName()<CR>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.