!
运行shell命令而没有问题。我还尝试过实验shell和shellquote变量,但也不起作用。
我尝试使用Bash(MSYS2)代替cmd.exe,但仍然没有运气。(
!
仍然有效)问题可能是shell变量或某些权限。
非常感谢任何帮助!
!
运行shell命令而没有问题。!
仍然有效)我认为在init.vim
中使用let $PATH .= ';C:\cygwin64\bin'
可能足以解决shell问题。
我尝试了推荐的vim样式,如http://vim.wikia.com/wiki/Use_cygwin_shell。这会导致vim-fugitive和vim-plug出现错误提示,例如/usr/bin/bash命令未找到
(通过git push,git log)或无法创建前导目录
(通过克隆repos时的vim-plug)。禁用它们后,fugitive和plug又可以正常工作了。
这个$TERM
选项可能会引起兴趣:https://neovim.io/doc/user/term.html#$TERM
我花了很长时间,但终于成功让Git Bash作为缓冲区打开,并且使用了!命令。我只在Windows 7上测试过,但这对你来说可能同样有效。
安装Git for windows,它也提供了一个Git Bash环境,我假设它被称为C:\Program Files (x86)\Git\bin\bash.exe。如果您有32位系统或想要使用64位Git for Windows,则需要在下面的脚本中将~2更改为~1。
现在,您应该能够使用以下命令从常规Windows CMD提示符启动git bash:
cmd.exe /c "C:\Progra~2\Git\bin\bash.exe --login -i"
" Terminal settings
" cc for commandline, cs for split first, ce to exit
:tnoremap <ESC> <C-\><C-n>
if has("win32")
" Note, you need to empty the file Git\etc\motd
" to get rid of the 'Welcome to Git' message
set shell=cmd.exe
nnoremap <Leader>cc :term<CR>adoskey.cmd<CR>cmd.exe /c "C:\\Progra~1\Git\bin\bash.exe --login -i"<CR>clear<CR>
nnoremap <Leader>cs :sp<CR>:wincmd j<CR>:term<CR>adoskey.cmd<CR>cls<CR>cmd.exe /c "C:\\Progra~1\Git\bin\bash.exe --login -i"<CR>clear<CR>
nnoremap <Leader>cd :term<CR>adoskey.cmd<CR>cls<CR>
nnoremap <Leader>csd :sp<CR>:wincmd j<CR>:term<CR>adoskey.cmd<CR>cls<CR>
else
nnoremap <Leader>cc :term<CR>A
nnoremap <Leader>cs :sp<CR>:wincmd j<CR>:term<CR>A
endif
augroup TerminalMappings
autocmd!
if has("win32")
autocmd TermOpen * nnoremap <buffer> <C-E> aexit<CR>exit<CR>
autocmd TermOpen * tnoremap <buffer> <C-E> exit<CR>exit<CR>
else
autocmd TermOpen * nnoremap <buffer> <C-E> aexit<CR>
autocmd TermOpen * tnoremap <buffer> <C-E> exit<CR>
endif
augroup END
" Make the split bigger
nnoremap <Leader>b 8<C-W>+<CR>
nnoremap <Leader>B 50<C-W>+<CR>
" Make the split wider
nnoremap <Leader>w 8<C-W>><CR>
nnoremap <Leader>W 56<C-W>><CR>
第一条命令将Control-[和ESC重新映射为退出终端模式,这似乎非常自然,但默认情况下并不是这样的 - 正常模式允许您使用cntrl-B进行滚动回退,使用通常的命令(或使用easy-motion)跳转到包含shell命令的行,并使用yypa<Enter>
执行它。
设置shell=cmd.exe实际上并不是必需的,因为在安装vim时它是Windows的默认设置,但是明确说明可以帮助您以后更改此设置。
我在绑定中使用这些助记符; 'c'表示命令行,'s'表示拆分,'d'表示DOS(Windows CMD),'e'表示退出。 这给出了以下选项:
<leader>cc full screen bash terminal
<leader>cs - split screen bash terminal (used 99% of the time by me)
<leader>cd - full screen DOS terminal
<leader>csd - split screen DOS terminal
<leader>e - exit terminal
我还加载了doskey.cmd
,它在PATH中某个可访问的位置,在我的情况下包含以下内容:
@echo off
DOSKEY ls=dir
DOSKEY which=where
DOSKEY mv=move
DOSKEY c=cls
DOSKEY clear=cls
DOSKEY bash=cmd.exe /c "C:\\Progra~1\Git\bin\bash.exe --login -i"
DOSKEY cp=copy
DOSKEY ..=cd ..
DOSKEY ...=cd ..\..
DOSKEY ....=cd ..\..\..
DOSKEY .....=cd ..\..\..\..
DOSKEY ......=cd ..\..\..\..\..
DOSKEY .......=cd ..\..\..\..\..\..
DOSKEY ........=cd ..\..\..\..\..\..\..
DOSKEY .........=cd ..\..\..\..\..\..\..\..
这类似于 ~/.bashrc 文件中的别名,并且允许我使用<leader>cd
,并输入bash
来切换到bash。
%PROGRAMFILES%
或转义\
空格,而不是依赖于Windows奇怪的DOS名称行为。 - CervEd