Closed MuhammadMuradG closed 4 years ago
Issue-Label Bot is automatically applying the label feature_request
to this issue, with a confidence of 0.55. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!
Links: app homepage, dashboard and code for this bot.
You can use the Vim API to execute cd
action to change the directory
Thanks for your guidance, I created the following vim script:
autocmd BufEnter * silent! let dir = getcwd()
autocmd BufEnter * call CocAction('runCommand', 'explorer.doAction', 'closest', {'name': 'cd', 'args': [dir]})
they are working correctly when I call them in command mode (:
) but when I put them in my init.vim
the following error is produced after open nvim:
Make sure this script call after CocNvimInit
autocmd User CocNvimInit call s:initCoc()
This is my script:
" Sure scripts are called after CocNvimInit
autocmd User CocNvimInit call s:initCoc()
nmap <space>e :CocCommand explorer<CR>
autocmd BufEnter * if (winnr("$") == 1 && &filetype == 'coc-explorer') | q | endif
" Automatically open coc-explorer
autocmd BufEnter * silent! let dir = getcwd()
autocmd VimEnter * if argc() == 1 | exe 'CocCommand explorer --no-focus ' . dir | endif
autocmd VimEnter * if argc() == 0 | Startify | exe 'CocCommand explorer --no-focus ' . dir | endif
autocmd BufEnter * call CocAction('runCommand', 'explorer.doAction', 'closest', {'name': 'cd', 'args': [dir]})
autocmd User CocNvimInit call s:coc_inited()
Declare a s:coc_inited()
function, and put your scripts into this function.
When I use CocNvimInit
event the following error is appear:
So, I use CocExplorerOpenPost
event instead which works fine.
@weirongxu Thanks again for your guidance.
For who interested with this behaviour, put the following in the init.vim
(for NeoVim):
" Sure the following script is called after CocExplorerOpenPost
function s:explorer_inited()
autocmd BufEnter * if (&filetype != 'coc-explorer') | exe 'silent! let dir = getcwd()'
autocmd BufEnter * call CocAction("runCommand", "explorer.doAction", "closest", {"name": "cd", "args": [dir]})
endfunction
autocmd User CocExplorerOpenPost call s:explorer_inited()
Sorry, but when use the previous script all things seem good except when I am trying open file from coc-explorer which leads to the nvim stuck and does not respond to any command. I tried using BufWinEnter
event instead of BufEnter
event but that leaded to open the selected file but still nvim stuck and does not respond to any command.
Could you please provide me with probable event or group of event or the solve of the problem?
Use CocActionAsync
instead of the CocAction
, BTW, you should save the previous dir to avoid calling cd redundantly
Everything seem working good now! Thanks again for your help.
I want to change the current work directory of explorer each time I navigate between different buffers of different path.
Is there an option or command that provides this feature?
PS: This feature is available only when the opened files are in the same directory by highlighted the current opened file.