如何在 PowerShell 中绑定 TabCompleteNext/TabCompletePrevious?

如何在 PowerShell 中绑定 TabCompleteNext/TabCompletePrevious?

我尝试使用以下命令在 PowerShell 7.2.4 中绑定 Ctrl-N 和 Ctrl-P,但它们没有效果 - 新的绑定不起作用。

Remove-PSReadLineKeyHandler Tab
Remove-PSReadLineKeyHandler Tab -ViMode Command
Remove-PSReadLineKeyHandler Shift-Tab
Remove-PSReadLineKeyHandler Shift-Tab -ViMode Command

Set-PSReadLineKeyHandler Ctrl+N -Function TabCompleteNext
Set-PSReadLineKeyHandler Ctrl+P -Function TabCompletePrevious
Set-PSReadLineKeyHandler Ctrl+N -Function TabCompleteNext -ViMode Command
Set-PSReadLineKeyHandler Ctrl+P -Function TabCompletePrevious -ViMode Command

Get-PSReadLineKeyHandler

...

Completion functions
====================

Key             Function            Description
---             --------            -----------
Ctrl+Spacebar   PossibleCompletions Display the possible completions without changing the input
<Ctrl+Spacebar> PossibleCompletions Display the possible completions without changing the input
Ctrl+N          TabCompleteNext     Complete the input using the next completion
<Ctrl+N>        TabCompleteNext     Complete the input using the next completion
Ctrl+P          TabCompletePrevious Complete the input using the previous completion
<Ctrl+P>        TabCompletePrevious Complete the input using the previous completion

我也尝试了以下方法,但没有效果:

Set-PSReadLineKeyHandler Ctrl+N -Function ViTabCompleteNext
Set-PSReadLineKeyHandler Ctrl+P -Function ViTabCompletePrevious
Set-PSReadLineKeyHandler Ctrl+N -Function ViTabCompleteNext -ViMode Command
Set-PSReadLineKeyHandler Ctrl+P -Function ViTabCompletePrevious -ViMode Command

知道如何在 PowerShell 中绑定 TabCompleteNext/TabCompletePrevious 吗?

答案1

此 PowerShell 命令非常棘手。问题是您指定了“Ctrl+N”,但却输入了“Ctrl+n”。

此命令对我有用:

Set-PSReadLineKeyHandler -Key Ctrl+n -Function TabCompleteNext

来源 : Set-PSReadLineKeyHandler - 键 Ctrl+U 不起作用 #1396

相关内容