On Windows and other non-Unix system, :cd without an argument just prints the current working directory instead of moving to the home directory.
It is confusing and inconvenient for me using Vim on various OSs including Windows. Also, there is no reason to use :cd for this purpose because :pwd can be used on all environment.
So I added 'cdhome' option to add a way to make its behavior the same with the Unix way.
https://github.com/vim/vim/pull/9324
(8 files)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
![]()
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.
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:
:Cd command is weird for me.: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.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.
—
You are receiving this because you commented.
@Bakudankun pushed 1 commit.
—
You are receiving this because you are subscribed to this thread.
Merging #9324 (354f5c0) into master (f8bc0ce) will decrease coverage by
2.38%.
The diff coverage is100.00%.
@@ Coverage Diff @@ ## master #9324 +/- ## ========================================== - Coverage 90.19% 87.81% -2.39% ========================================== Files 151 149 -2 Lines 170853 171343 +490 ========================================== - Hits 154098 150458 -3640 - Misses 16755 20885 +4130
| Flag | Coverage Δ | |
|---|---|---|
| huge-clang-none | 89.31% <100.00%> (-0.80%) |
⬇️ |
| huge-gcc-none | ? |
|
| huge-gcc-testgui | ? |
|
| huge-gcc-unittests | 2.46% <0.00%> (-0.01%) |
⬇️ |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/ex_docmd.c | 93.13% <100.00%> (-2.80%) |
⬇️ |
| src/libvterm/src/rect.h | 0.00% <0.00%> (-96.56%) |
⬇️ |
| src/libvterm/src/state.c | 40.00% <0.00%> (-49.44%) |
⬇️ |
| src/libvterm/src/keyboard.c | 48.42% <0.00%> (-40.00%) |
⬇️ |
| src/libvterm/include/vterm.h | 0.00% <0.00%> (-37.50%) |
⬇️ |
| src/libvterm/src/pen.c | 47.78% <0.00%> (-36.88%) |
⬇️ |
| src/libvterm/src/encoding.c | 44.55% <0.00%> (-28.72%) |
⬇️ |
| src/libvterm/src/parser.c | 67.08% <0.00%> (-28.70%) |
⬇️ |
| src/if_perl.xs | 63.30% <0.00%> (-27.63%) |
⬇️ |
| src/libvterm/src/vterm.c | 47.03% <0.00%> (-20.41%) |
⬇️ |
| ... and 127 more |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered by Codecov. Last update f8bc0ce...354f5c0. Read the comment docs.
—
You are receiving this because you commented.
$HOME had backslashes while Windows tests because it was evaluated after set shellslash.
I fixed that, and now failing tests are flaky ones.
—
You are receiving this because you commented.
I think this is common enough to add an option for. The suggested abbreviation does it quite well, but not exactly right.
And it needs to be copy/pasted, while setting the option in your vimrc is easy.
—
You are receiving this because you commented.
Hi, @brammool
Thank you for adopting this PR!
However, it seems that the document of 'cdhome' is lost in the patch 8.2.3780.
Please check the options.txt.
—
You are receiving this because you commented.
Let me update the whole file.
—
You are receiving this because you commented.