Reputation: 9397
This is a followup (but a distinct question) to this question, which I'll reiterate here for completion.
I have a Vim mapping to start searching (ack-grep with ack.vim plugin) for a pattern from the directory that is the current directory (so the result after :pwd). This mapping works when I'm looking at a buffer.
I want to use the same mapping while I'm in netrw. But, I want to change the current directory (:pwd) to the directory netrw is showing me, so the search will be started from the directory I'm looking at. I know I can do this with the netrw c command. How do I give the c
command from within a function?
I've tried:
function! StartAckSearch()
" If we're in netrw change the current directory to the directory we're
" viewing
if &ft ==# 'netrw'
echo 'in netrw'
c
endif
endfunction
nnoremap <Leader>a :call StartAckSearch()<CR>
And:
I've tried:
function! StartAckSearch()
" If we're in netrw change the current directory to the directory we're
" viewing
if &ft ==# 'netrw'
echo 'in netrw'
execute 'c'
endif
endfunction
nnoremap <Leader>a :call StartAckSearch()<CR>
But they both don't work.
Question How do I call a netrw command using Vimscript? (If my question can be rephrased to be clearer, please go ahead)
Upvotes: 0
Views: 580