[英]Changing directory in Git-Bash: using Windows-style directory addresses in MINGW64 on Windows machines
git-bash.exe
, or MINGW64
, recognizes cd
commands for directories whose addresses are given in form of: /Drive_Name/Folder1/Subfolder1
. git-bash.exe
或MINGW64
识别其地址以: /Drive_Name/Folder1/Subfolder1
形式给出的目录的cd
命令。 An example for changing to home dir for a Windows machine users is: cd /c/users/USERNAME
. 更改为Windows计算机用户的主目录的示例是:
cd /c/users/USERNAME
。
Is it possible to use the following syntax? 是否可以使用以下语法?
cd c:\\users\\USERNAME
Note, the directory address is given in its "native" format: the syntax for which the Windows OS recognizes. cd c:\\users\\USERNAME
注意,目录地址以“本机”格式给出:Windows操作系统识别的语法。
Alternatively, is there a way to automatically change all the backward slashes into forward slashes when pasting into the Git-bash window? 或者,有没有办法在粘贴到Git-bash窗口时自动将所有反斜杠更改为正斜杠?
I am using git-bash.exe
on a daily basis: to pull and push to Github, to run latexmk
for compiling my *.tex
documents and to SSH my Linux machines. 我每天都在使用
git-bash.exe
:拉动并推送到Github,运行latexmk
来编译我的*.tex
文件和SSH我的Linux机器。 It would be nice to quickly start a git-bash.exe
process at the desired directory location. 在所需的目录位置快速启动
git-bash.exe
进程会很不错。 And, when on Windows OS, getting addresses in form of C:\\users\\USERNAME\\project
is the default. 而且,在Windows操作系统上,以
C:\\users\\USERNAME\\project
形式获取地址是默认设置。
git-bash.exe
likes: git-bash.exe
喜欢的语法分类: /c/users/USERNAME
; /c/users/USERNAME
; c:/users/USERNAME
; c:/users/USERNAME
; c:\\\\users\\\\USERNAME
(credits: @VonC ) c:\\\\users\\\\USERNAME
(credit: @VonC ) A valid alternative is to have some third-party process to monitor the clipboard, and switch all the backward backward slashes into forward slashes. 有效的替代方法是使用某些第三方进程来监视剪贴板,并将所有向后反斜杠切换为正斜杠。 In my case, this could happen:
就我而言,这可能发生:
[Solved] In Vim , when I use the following mapping to fetch the "parent directory" of the file: nnoremap <leader><leader>p :let @* = expand("%:p:h")<CR>
[解决]在Vim中 ,当我使用以下映射来获取文件的“父目录”时:
nnoremap <leader><leader>p :let @* = expand("%:p:h")<CR>
set shellslash
, see "tentative solution" for more details. set shellslash
,有关详细信息,请参阅“暂定解决方案”。 Though some clipboard-monitor/recording apps: to simply recognize that the string being assigned to the system clipboard is an address for a folder/directory, and replace all backward slashes to be forward slashes. 虽然一些剪贴板监视/录制应用程序:只是简单地识别分配给系统剪贴板的字符串是文件夹/目录的地址,并将所有反斜杠替换为正斜杠。
In .vimrc
(or _vimrc
for Windows), use setting: set shellslash
, and use the following mapping to copy the addresses: 在
.vimrc
(或Windows的_vimrc
)中,使用设置: set shellslash
,并使用以下映射来复制地址:
Absolute directory to the file: 文件的绝对目录:
nnoremap <leader><leader>f :let @* = expand("%:p")<CR>
Absolute directory to the parent folder: 父文件夹的绝对目录:
nnoremap <leader><leader>p :let @* = expand("%:p:h")<CR>
Ref: Is it possible to make vim use forward slashes on windows? 参考: 是否可以让vim在Windows上使用正斜杠?
Other mappings that are helpful: 其他有用的映射:
" File Name only, without extension nnoremap <leader><leader>n :let @* = expand("%:t:r")<CR> " Extension. nnoremap <leader><leader>e :let @* = expand("%:t:e")<CR> " Copy the line number with file name nnoremap <leader><leader>l :let @* = expand("%:p").":".line(".")<CR>
What this solution builds on are: 该解决方案的基础是:
git-bash.exe
's ability to recognize addresses of the following form: c:/users/USERNAME/document
, where the forward slashes are used as divider. git-bash.exe
能够识别以下格式的地址: c:/users/USERNAME/document
,其中正斜杠用作分隔符。
Vim's native function expand("%:p")
(with other flags) that can copy directory-info to clipboard. Vim的本机函数
expand("%:p")
(带有其他标志)可以将directory-info复制到剪贴板。
Is it possible to use the following syntax?
是否可以使用以下语法?
cd c:\users\USERNAME
I just tried with the latest Git 2.13.3 bash: it works, but I had to type: 我刚尝试使用最新的Git 2.13.3 bash:它可以工作,但我必须输入:
cd c:\\users\\USERNAME
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.