跳至内容

导入语句顺序

TIP

  • 当在 $Profile 中添加 Import-Module PSCompletions 时,它的位置很重要
  • 在部分场景中,错误的导入顺序可能会导致 PSCompletions 无法正常工作
  1. 如果你需要使用 PSReadLine 相关的配置命令

    • 请将它们放在 Import-Module PSCompletions 之前
    powershell
    # Get-PSReadLineOption
    $params = @{
       # 列表视图: InlineView/ListView
       PredictionViewStyle = 'ListView'
       # 关闭响铃: Audible/Visual/None
       BellStyle           = 'None'
       # 编辑模式: Windows/Emacs/Vi
       EditMode            = 'Vi'
    }
    Set-PSReadLineOption @params
    Set-PSReadLineKeyHandler -Key 'Ctrl+z' -Function Undo
    Import-Module PSCompletions
    powershell
    # Get-PSReadLineOption
    Set-PSReadLineOption -PredictionViewStyle ListView -BellStyle None -EditMode vi
    Set-PSReadLineKeyHandler -Key 'Ctrl+z' -Function Undo
    Import-Module PSCompletions