On 2021-12-10, バクダンくん wrote:
> Thank you for your comment!
> 
>     The reason for using :cd this way on Windows is that this is how cd
>     works at the Command Prompt, so it is more natural for Windows
>     users.
> 
> That may be natural, but not useful. Also, Microsoft recently encourages to
> switch to PowerShell 7, in which cd (alias of Set-Location) command without an
> argument changes the working directory to the home directory.

I didn't know that.  Thanks.  I occasionally have to use Power
Shell, but not often.

>     How about putting this in your vimrc instead. It avoids Yet Another
>     Option.
> 
>     if has("win32")
>       cabbrev <expr> cd ((getcmdtype() == ':' && getcmdpos() <= 3) ? 'Cd' : 
> 'cd')
>       command! -nargs=? -complete=file Cd if !empty(expand("<args>")) | cd 
> <args> | else | cd $USERPROFILE | endif
>     endif
> 
> I have tried similar solution, but it has some problems:
> 
>   • I just don't want to define a command for this simple feature that Unix
>     version already has. Using :Cd command is weird for me.

Agreed, but that's what the abbreviation is for.  It changes :cd to
:Cd automatically so you can continue to type :cd.

>   • Your method does not cover a feature that :cd echoes the new working
>     directory. Somehow :cd<CR> echoes, but :Cd<CR> and :Cd Desktop do not. I
>     want to keep this feature because it is helpful.

I don't care about that myself--it seems redundant--but I'm sure
that a command or function could be crafted to do that.

> To meet my wants, I need to write the next script in my vimrc, but it maps 
> <CR>
> on command line mode so I expect some side effects.
> 
> if has('win32')
>   function! s:expand_alias() abort
>     if getcmdtype() !=# ':'
>       return "\<CR>"
>     endif
>     let cmdline = getcmdline()
>     for [pattern, alias] in [
>           \   ['^\s*[tl]\?cd\s*$', "$HOME\<CR>\<Cmd>pwd\<CR>"],
>           \   ['^\s*[tl]\?cd\s', "\<CR>\<Cmd>pwd\<CR>"],
>           \ ]
>       if cmdline =~# pattern
>         return alias
>       endif
>     endfor
>     return "\<CR>"
>   endfunction
>   cnoremap <expr> <CR> <SID>expand_alias()
> endif
> 
> The change of C code is smaller than this script, and would have less side
> effects.

I think you could get the behavior you want by modifying my :Cd
command to call a function that would :cd and :pwd as you have done
above.  That would avoid mapping <CR> and should have no side
effects.

Your proposal isn't horrible, it's just one of those things that
could be done with a script and tuned to do exactly what you want
without having to worry about what other users want.

There's usually a trade-off between adding a feature in a script or
in C, and to avoid making Vim more difficult to maintain and to
understand, I usually prefer using a script.

On the other hand, if enough users would benefit from having :cd
behave according to your patch, that would be better than all those
users having to write or copy your script.

Regards,
Gary

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20211211073025.GB7422%40phoenix.

Raspunde prin e-mail lui