red*_*888 2 vim shell powershell
我的 vimrc 中已经有这个:
set shell=powershell
set shellcmdflag=-command
Run Code Online (Sandbox Code Playgroud)
现在我想向 powershell 传递当前文件的路径,以便它可以运行它。我试过这个:
nnoremap <C-q> :! expand('%:p')<cr>
Run Code Online (Sandbox Code Playgroud)
这是我在 powershell 中看到的:
powershell -command " expand('\\path\to\my\file....
Run Code Online (Sandbox Code Playgroud)
显然这不起作用,因为我在那里有那个该死的expand()。如何将当前文件的完整路径传递到 shell?
另外,在有人说之前,我有自己的映射,用于视觉块,这就是我重新映射的原因<C-q>
%像( )这样的特殊字符:help cmdline-special会被 Vim 自动扩展为“在可以使用文件名的地方”(引自帮助)。这包括:!命令,因此以下内容就足够了:
nnoremap <C-q> :! %:p<CR>
Run Code Online (Sandbox Code Playgroud)
现在,如果您想做比 更复杂的修改:p,有两个选择:
:execute:nnoremap <C-q> :execute '!' expand('%:p')<CR><C-R>与表达式寄存器一起使用:nnoremap <C-q> :! <C-r>=expand('%:p')<CR><CR>