lambdalisue / vim-fern

🌿 General purpose asynchronous tree viewer written in Pure Vim script
MIT License
1.29k stars 49 forks source link

The ability to automatically change current working directory #107

Closed Shatur closed 4 years ago

Shatur commented 4 years ago

NERDTree have the ability to automatically synchronize vim working directory with current root. Could you add an option for it in Fern? For example, change vim working directory on fern-action-leave, fern-action-enter, etc. and on reveal.

lambdalisue commented 4 years ago

Probably, this tip helps you.

https://github.com/lambdalisue/fern.vim/wiki/Tips#perform-tcd-when-enterleave-only-in-drawer-style

Shatur commented 4 years ago

Thanks for the tip! I tried it, but it not works as expected for me. After performing this action I stay in the previous directory. For example: asciicast

I would expect to stay in the drawer directory after cd.

lambdalisue commented 4 years ago

Got it. It's a bit complicated than I thought and the tips does not work currently. I'm working on this issue on #108 👍

Shatur commented 4 years ago

@lambdalisue, thanks! Should I use on of these commands in the tip above instead?

lambdalisue commented 4 years ago

I'll mention you once the PR become ready to test 👍

Shatur commented 4 years ago

Okay, thanks :)

Shatur commented 4 years ago

I tried the following mappings, but this the directory still mapped to the previous dir. Am I using it ok?

nmap <buffer><expr> <S-k> '<Plug>(fern-action-leave)<Plug>(fern-action-cd:root)'
nmap <buffer><expr> <C-CR> '<Plug>(fern-action-enter)<Plug>(fern-action-cd:root)'
lambdalisue commented 4 years ago

That's why the PR said "partial". Please check #108 and give me your opinion. @Shatur95


And actually your usage was wrong. You need to use " and escape <Plug> or <C-x> or soon with \ when you use string in mapping

Shatur commented 4 years ago

That's why the PR said "partial". Please check #108 and give me your opinion.

Tested, works! But it looks like fern-action-cd:root changes directory only for current fern buffer. I would expect to change directory globally.

And actually your usage was wrong. You need to use " and escape or or soon with \ when you use string in mapping

Did not know about it. I used the following mappings and it works as expected:

nmap <buffer><expr> m '<Plug>(fern-action-move)'
nmap <buffer><expr> r '<Plug>(fern-action-rename)'
nmap <buffer><expr> d '<Plug>(fern-action-trash)'
nmap <buffer><expr> y '<Plug>(fern-action-clipboard-copy)'
nmap <buffer><expr> c '<Plug>(fern-action-clipboard-move)'

Also, the following works too:

nmap <buffer><expr><silent> <S-k> '<Plug>(fern-action-leave):call fern#smart#ready("\<Plug>(fern-action-tcd:root)")<CR>'
nmap <buffer><expr><silent> <C-CR> '<Plug>(fern-action-enter):call fern#smart#ready("\<Plug>(fern-action-tcd:root)")<CR>'

Also, in documentation you have examples without ' and ". Is it a typo?

lambdalisue commented 4 years ago

Tested, works! But it looks like fern-action-cd:root changes directory only for current fern buffer. I would expect to change directory globally.

It's strange. I confirmed that cd action invoke :cd command and it change global cwd. Are you sure that no :lcd or :tcd had applied? These command fix cwd on buffers.

Also, in documentation you have examples without ' and ". Is it a typo?

My bad. I didn't know that ' is accepted and \ escape is not required for <expr> mapping. These are required for :normal thus I mis-understood.

Only `2` does not work ```vim nmap 1 (fern-action-debug) nmap 2 '(fern-action-debug)' nmap 3 '(fern-action-debug)' nmap 4 "(fern-action-debug)" nmap 5 '\(fern-action-debug)' nmap 6 "\(fern-action-debug)" ```
lambdalisue commented 4 years ago

I changed the way. Please check https://github.com/lambdalisue/fern.vim/pull/112 @Shatur95

Shatur commented 4 years ago

I like new way much more :) Tested, it works, but I have the same issue with cd. Here is the video, maybe I doing something wrong: asciicast (I missed \ for enter action, but it do not used on the video)

Only 2 does not work

Yes, also it looks like mappings to keyboard with <expr> works too:

nmap <buffer><expr> m '<Plug>(fern-action-move)'
nmap <buffer><expr> r '<Plug>(fern-action-rename)'
nmap <buffer><expr> d '<Plug>(fern-action-trash)'
nmap <buffer><expr> y '<Plug>(fern-action-clipboard-copy)'
lambdalisue commented 4 years ago

I'd love to classify the issue so please execute cd:root action and cd action directly (from hitting a) and see what happen.

Additionally, I guess that cd:root or cd does not work on your environment so please provide me your environment information (OS, Vim/Neovim, version, etc.)

lambdalisue commented 4 years ago

Closed by #112

Shatur commented 4 years ago

You are right, the problem is in cd and cd:root command in my environment. I will test without any plugins first (except fern.vim) and then will open a new issue.

The last thing about current issue: I can automatically make a command to cd:root after Fern execution in my shortcut, but maybe add an option to cd to current root automatically on -reveal?

Shatur commented 4 years ago

I will test without any plugins first (except fern.vim) and then will open a new issue.

I'm very sorry, the issue not in fern.vim at all. For some reason when opening a buffer from Startify :cd (even Ex command) do not affects to this opened buffer when executed in other buffer. Very strange.

lambdalisue commented 4 years ago

Then Startify may invoke :lcd or :tcd internally. Use tcd:root action instead then.

Shatur commented 4 years ago

Then Startify may invoke :lcd or :tcd internally. Use tcd:root action instead then.

I tried, even :tcd Ex command not work :(

Shatur commented 4 years ago

I tried, even :tcd Ex command not work :(

I looked as Startify source code and it uses :lcd. After :lcd I can't change current directory for such buffers even with :tcd.

lambdalisue commented 4 years ago

I tried, even :tcd Ex command not work :(

That's sad. But I understand that lcd is more specific than tcd....

I looked as Startify source code and it uses :lcd. After :lcd I can't change current directory for such buffers even with :tcd.

Then probably you should maka an issue report on startify.