1

I'm writting a function to integrates NERDTree with Ack. The goal is to create a "Find in Directory".

I create this:

function! Fif_NERDTreeGetPath()
  let nodePath = g:NERDTreeFileNode.GetSelected().path.str()
  return nodePath
endfunction
:command! -nargs=+ Fif :Ack "<args>" Fif_NERDTreeGetPath()

The function Fif_NERDTreeGetPath() returns the correct path for the directory that cursor is on.

But, when I execute Fif word it return:

:ack -s -H --nopager --nocolor --nogroup --column "word" Fif_NERDTreeGetPath()

It's almost right. The problem is the path is not being returned. I'm expecting something like:

:ack -s -H --nopager --nocolor --nogroup --column "word" /path/to/directory/

This is my first vim function. I don't know how to solve. Tks!

2
  • 2
    you need execute: vi.stackexchange.com/q/21392/10604
    – D. Ben Knoble
    Apr 16, 2020 at 17:46
  • @D.BenKnoble Tks, execute solves. The final command for Find In Files with NERDTree and Ack.vim is: :command! -nargs=+ Fif let node_path = g:NERDTreeFileNode.GetSelected().path.str() | :execute "normal! \<c-w>\<c-w>" | :execute ':Ack "<args>" ' . node_path . When I position the cursor on the NerdTree directory node, I run :Fif keyword and everything works fine. Apr 17, 2020 at 15:24

0

Browse other questions tagged or ask your own question.