You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Ubuntu 24.04(WSL)的PowerShell中配置Windows风格快捷键?

解决方案:让WSL Ubuntu中的PowerShell匹配Windows端行为

不用手动逐条复制键绑定,只需通过以下步骤配置PSReadLine即可对齐Windows端的快捷键和自动补全逻辑:

1. 确保PSReadLine为最新版本

在WSL的PowerShell中执行以下命令更新PSReadLine:

Install-Module -Name PSReadLine -Force -SkipPublisherCheck

2. 修改PowerShell配置文件

执行命令打开配置文件:

notepad $PROFILE

若文件不存在,先创建:

New-Item -Path $PROFILE -ItemType File -Force

在配置文件中添加以下内容:

# 设置编辑模式为Windows风格,自动应用Windows默认键绑定
Set-PSReadLineOption -EditMode Windows

# 配置Tab循环补全(与Windows端一致)
Set-PSReadLineKeyHandler -Key Tab -Function TabCompleteNext
Set-PSReadLineKeyHandler -Key Shift+Tab -Function TabCompletePrevious

# 可选:对齐Windows端历史搜索快捷键
Set-PSReadLineKeyHandler -Key F8 -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key Shift+F8 -Function HistorySearchForward

3. 生效配置

保存配置文件后,重启PowerShell,或执行以下命令加载配置:

. $PROFILE

验证配置

执行以下命令查看键绑定是否已对齐:

Get-PSReadLineKeyHandler

参考:Windows与Linux端默认键绑定对比

Windows端默认键绑定

Basic editing functions
=======================

Key              Function            Description
---              --------            -----------
Enter            AcceptLine          Accept the input or move to the next line if input is missing a closing token.
Shift+Enter      AddLine             Move the cursor to the next line without attempting to execute the input
Backspace        BackwardDeleteChar  Delete the character before the cursor
Ctrl+h           BackwardDeleteChar  Delete the character before the cursor
Ctrl+Home        BackwardDeleteInput Delete text from the cursor to the start of the input
Ctrl+Backspace   BackwardKillWord    Move the text from the start of the current or previous word to the cursor to the
                                     kill ring
Ctrl+w           BackwardKillWord    Move the text from the start of the current or previous word to the cursor to the
                                     kill ring
Ctrl+C           Copy                Copy selected region to the system clipboard.  If no region is selected, copy the
                                     whole line
Ctrl+c           CopyOrCancelLine    Either copy selected text to the clipboard, or if no text is selected, cancel
                                     editing the line with CancelLine.
Ctrl+x           Cut                 Delete selected region placing deleted text in the system clipboard
Delete           DeleteChar          Delete the character under the cursor
Ctrl+End         ForwardDeleteInput  Delete text from the cursor to the end of the input
Ctrl+Enter       InsertLineAbove     Inserts a new empty line above the current line without attempting to execute the
                                     input
Shift+Ctrl+Enter InsertLineBelow     Inserts a new empty line below the current line without attempting to execute the
                                     input
Alt+d            KillWord            Move the text from the cursor to the end of the current or next word to the kill
                                     ring
Ctrl+Delete      KillWord            Move the text from the cursor to the end of the current or next word to the kill
                                     ring
Ctrl+v           Paste               Paste text from the system clipboard
Shift+Insert     Paste               Paste text from the system clipboard
Ctrl+y           Redo                Redo an undo
Escape           RevertLine          Equivalent to undo all edits (clears the line except lines imported from history)
Ctrl+z           Undo                Undo a previous edit
Alt+.            YankLastArg         Copy the text of the last argument to the input

Cursor movement functions
=========================

Key             Function        Description
---             --------        -----------
LeftArrow       BackwardChar    Move the cursor back one character
Ctrl+LeftArrow  BackwardWord    Move the cursor to the beginning of the current or previous word
Home            BeginningOfLine Move the cursor to the beginning of the line
End             EndOfLine       Move the cursor to the end of the line
RightArrow      ForwardChar     Move the cursor forward one character
Ctrl+]          GotoBrace       Go to matching brace
Ctrl+RightArrow NextWord        Move the cursor forward to the start of the next word

History functions
=================

Key       Function              Description
---       --------              -----------
Alt+F7    ClearHistory          Remove all items from the command line history (not PowerShell history)
Ctrl+s    ForwardSearchHistory  Search history forward interactively
F8        HistorySearchBackward Search for the previous item in the history that starts with the current input - like
                                PreviousHistory if the input is empty
Shift+F8  HistorySearchForward  Search for the next item in the history that starts with the current input - like
                                NextHistory if the input is empty
DownArrow NextHistory           Replace the input with the next item in the history
UpArrow   PreviousHistory       Replace the input with the previous item in the history
Ctrl+r    ReverseSearchHistory  Search history backwards interactively

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

Key           Function            Description
---           --------            -----------
Ctrl+@        MenuComplete        Complete the input if there is a single completion, otherwise complete the input by
                                  selecting from a menu of possible completions.
Ctrl+Spacebar MenuComplete        Complete the input if there is a single completion, otherwise complete the input by
                                  selecting from a menu of possible completions.
Tab           TabCompleteNext     Complete the input using the next completion
Shift+Tab     TabCompletePrevious Complete the input using the previous completion

Prediction functions
====================

Key Function                  Description
--- --------                  -----------
F4  ShowFullPredictionTooltip Show the full tooltip of the selected list-view item in the terminal's alternate screen
                              buffer.
F2  SwitchPredictionView      Switch between the inline and list prediction views.

Miscellaneous functions
=======================

Key           Function              Description
---           --------              -----------
Ctrl+l        ClearScreen           Clear the screen and redraw the current line at the top of the screen
Alt+0         DigitArgument         Start or accumulate a numeric argument to other functions
Alt+1         DigitArgument         Start or accumulate a numeric argument to other functions
Alt+2         DigitArgument         Start or accumulate a numeric argument to other functions
Alt+3         DigitArgument         Start or accumulate a numeric argument to other functions
Alt+4         DigitArgument         Start or accumulate a numeric argument to other functions
Alt+5         DigitArgument         Start or accumulate a numeric argument to other functions
Alt+6         DigitArgument         Start or accumulate a numeric argument to other functions
Alt+7         DigitArgument         Start or accumulate a numeric argument to other functions
Alt+8         DigitArgument         Start or accumulate a numeric argument to other functions
Alt+9         DigitArgument         Start or accumulate a numeric argument to other functions
Alt+-         DigitArgument         Start or accumulate a numeric argument to other functions
PageDown      ScrollDisplayDown     Scroll the display down one screen
Ctrl+PageDown ScrollDisplayDownLine Scroll the display down one line
PageUp        ScrollDisplayUp       Scroll the display up one screen
Ctrl+PageUp   ScrollDisplayUpLine   Scroll the display up one line
F1            ShowCommandHelp       Shows help for the command at the cursor in an alternate screen buffer.
Ctrl+Alt+?    ShowKeyBindings       Show all key bindings
Alt+h         ShowParameterHelp     Shows help for the parameter at the cursor.
Alt+?         WhatIsKey             Show the key binding for the next chord entered

Selection functions
===================

Key                   Function              Description
---                   --------              -----------
Ctrl+a                SelectAll             Select the entire line. Moves the cursor to the end of the line
Shift+LeftArrow       SelectBackwardChar    Adjust the current selection to include the previous character
Shift+Home            SelectBackwardsLine   Adjust the current selection to include from the cursor to the start of
                                            the line
Shift+Ctrl+LeftArrow  SelectBackwardWord    Adjust the current selection to include the previous word
Alt+a                 SelectCommandArgument Make visual selection of the command arguments.
Shift+RightArrow      SelectForwardChar     Adjust the current selection to include the next character
Shift+End             SelectLine            Adjust the current selection to include from the cursor to the end of the
                                            line
Shift+Ctrl+RightArrow SelectNextWord        Adjust the current selection to include the next word

Search functions
================

Key      Function                Description
---      --------                -----------
F3       CharacterSearch         Read a character and move the cursor to the next occurrence of that character
Shift+F3 CharacterSearchBackward Read a character and move the cursor to the previous occurrence of that character

Linux端默认键绑定

Basic editing functions
=======================

Key              Function              Description
---              --------              -----------
Ctrl+g           Abort                 Abort the current operation, e.g. incremental history search
Ctrl+o           AcceptAndGetNext      Accept the current line and recall the next line from history after the current line finishes
                                        executing
Enter            AcceptLine            Accept the input or move to the next line if input is missing a closing token.
Shift+Enter      AddLine               Move the cursor to the next line without attempting to execute the input
Backspace        BackwardDeleteChar    Delete the character before the cursor
Ctrl+Backspace   BackwardDeleteChar    Delete the character before the cursor
Ctrl+u           BackwardKillInput     Move the text from the cursor to the beginning of the input to the kill ring
Ctrl+x,Backspace BackwardKillInput     Move the text from the cursor to the beginning of the input to the kill ring
Alt+Backspace    BackwardKillWord      Move the text from the start of the current or previous word to the cursor to the kill ring
Escape,Backspace BackwardKillWord      Move the text from the start of the current or previous word to the cursor to the kill ring
Alt+c            CapitalizeWord        Find the next word starting from the current position and then upcase the first character and
                                        downcase the remaining characters.
Escape,c         CapitalizeWord        Find the next word starting from the current position and then upcase the first character and
                                        downcase the remaining characters.
Ctrl+c           CopyOrCancelLine      Either copy selected text to the clipboard, or if no text is selected, cancel editing the lin
                                       e with CancelLine.
Delete           DeleteChar            Delete the character under the cursor
Ctrl+d           DeleteCharOrExit      Delete the character under the cursor, or if the line is empty, exit the process.
Alt+l            DowncaseWord          Find the next word starting from the current position and then make it lower case.
Escape,l         DowncaseWord          Find the next word starting from the current position and then make it lower case.
Ctrl+k           KillLine              Move the text from the cursor to the end of the input to the kill ring
Alt+d            KillWord              Move the text from the cursor to the end of the current or next word to the kill ring
Escape,d         KillWord              Move the text from the cursor to the end of the current or next word to the kill ring
Alt+r            RevertLine            Equivalent to undo all edits (clears the line except lines imported from history)
Escape,r         RevertLine            Equivalent to undo all edits (clears the line except lines imported from history)
Ctrl+t           SwapCharacters        Swap the current character with the character before it.
Ctrl+_           Undo                  Undo a previous edit
Ctrl+x,Ctrl+u    Undo                  Undo a previous edit
Ctrl+w           UnixWordRubout        Move the text from the cursor to the start of the current or previous whitespace delimited wo
                                       rd to the kill ring
Alt+u            UpcaseWord            Find the next word starting from the current position and then make it upper case.
Escape,u         UpcaseWord            Find the next word starting from the current position and then make it upper case.
Ctrl+m           ValidateAndAcceptLine Accept the input or move to the next line if input is missing a closing token.
                                       If there are other parse errors, unresolved commands, or incorrect parameters, show the error
                                        and continue editing.
Ctrl+y           Yank                  Copy the text from the current kill ring position to the input
Alt+.            YankLastArg           Copy the text of the last argument to the input
Alt+_            YankLastArg           Copy the text of the last argument to the input
Escape,.         YankLastArg           Copy the text of the last argument to the input
Escape,_         YankLastArg           Copy the text of the last argument to the input
Ctrl+Alt+y       YankNthArg            Copy the text of the first argument to the input
Escape,Ctrl+y    YankNthArg            Copy the text of the first argument to the input
Alt+y            YankPop               Replace the previously yanked text with the text from the next kill ring position
Escape,y         YankPop               Replace the previously yanked text with the text from the next kill ring position

Cursor movement functions
=========================

Key        Function        Description
---        --------        -----------
LeftArrow  BackwardChar    Move the cursor back one character
Ctrl+b     BackwardChar    Move the cursor back one character
Alt+b      BackwardWord    Move the cursor to the beginning of the current or previous word
Escape,b   BackwardWord    Move the cursor to the beginning of the current or previous word
Home       BeginningOfLine Move the cursor to the beginning of the line
Ctrl+a     BeginningOfLine Move the cursor to the beginning of the line
End        EndOfLine       Move the cursor to the end of the line
Ctrl+e     EndOfLine       Move the cursor to the end of the line
RightArrow ForwardChar     Move the cursor forward one character
Ctrl+f     ForwardChar     Move the cursor forward one character
Alt+f      ForwardWord     Move the cursor forward to the end of the current word, or if between words, to the end of the next word.

Escape,f   ForwardWord     Move the cursor forward to the end of the current word, or if between words, to the end of the next word.


History functions
=================

Key       Function             Description
---       --------             -----------
Alt+<     BeginningOfHistory   Move to the first item in the history
Alt+>     EndOfHistory         Move to the last item (the current input) in the history
Ctrl+s    ForwardSearchHistory Search history forward interactively
DownArrow NextHistory          Replace the input with the next item in the history
Ctrl+n    NextHistory          Replace the input with the next item in the history
UpArrow   PreviousHistory      Replace the input with the previous item in the history
Ctrl+p    PreviousHistory      Replace the input with the previous item in the history
Ctrl+r    ReverseSearchHistory Search history backwards interactively

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

Key   Function            Description
---   --------            -----------
Tab   Complete            Complete the input if there is a single completion, otherwise complete the input with common prefix for al
                          l completions.  Show possible completions if pressed a second time.
Alt+= PossibleCompletions Display the possible completions without changing the input

Prediction functions
====================

Key Function                  Description
--- --------                  -----------
F4  ShowFullPredictionTooltip Show the full tooltip of the selected list-view item in the terminal's alternate screen buffer.
F2  SwitchPredictionView      Switch between the inline and list prediction views.

Miscellaneous functions
=======================

Key           Function          Description
---           --------          -----------
Ctrl+l        ClearScreen       Clear the screen and redraw the current line at the top of the screen
Alt+0         DigitArgument     Start or accumulate a numeric argument to other functions
Alt+1         DigitArgument     Start or accumulate a numeric argument to other functions
Alt+2         DigitArgument     Start or accumulate a numeric argument to other functions
Alt+3         DigitArgument     Start or accumulate a numeric argument to other functions
Alt+4         DigitArgument     Start or accumulate a numeric argument to other functions
Alt+5         DigitArgument     Start or accumulate a numeric argument to other functions
Alt+6         DigitArgument     Start or accumulate a numeric argument to other functions
Alt+7         DigitArgument     Start or accumulate a numeric argument to other functions
Alt+8         DigitArgument     Start or accumulate a numeric argument to other functions
Alt+9         DigitArgument     Start or accumulate a numeric argument to other functions
Alt+-         DigitArgument     Start or accumulate a numeric argument to other functions
F1            ShowCommandHelp   Shows help for the command at the cursor in an alternate screen buffer.
Ctrl+Alt+?    ShowKeyBindings   Show all key bindings
Alt+h         ShowParameterHelp Shows help for the parameter at the cursor.
Ctrl+x,Ctrl+e ViEditVisually    Invokes the console compatible editor specified by $env:VISUAL or $env:EDITOR on the current command
                                 line.
Alt+?         WhatIsKey         Show the key binding for the next chord entered

Selection functions
===================

Key              Function              Description
---              --------              -----------
Ctrl+x,Ctrl+x    ExchangePointAndMark  Mark the location of the cursor and move the cursor to the position of the previous mark
Shift+LeftArrow  SelectBackwardChar    Adjust the current selection to include the previous character
Shift+Home       SelectBackwardsLine   Adjust the current selection to include from the cursor to the start of the line
Alt+B            SelectBackwardWord    Adjust the current selection to include the previous word
Alt+a            SelectCommandArgument Make visual selection of the command arguments.
Shift+RightArrow SelectForwardChar     Adjust the current selection to include the next character
Alt+F            SelectForwardWord     Adjust the current selection to include the next word using ForwardWord
Shift+End        SelectLine            Adjust the current selection to include from the cursor to the end of the line
Ctrl+@           SetMark               Mark the location of the cursor
Alt+Spacebar     SetMark               Mark the location of the cursor

Search functions
================

Key        Function                Description
---        --------                -----------
Ctrl+]     CharacterSearch         Read a character and move the cursor to the next occurrence of that character
Ctrl+Alt+] CharacterSearchBackward Read a character and move the cursor to the previous occurrence of that character

内容的提问来源于stack exchange,提问作者Hyperbo Lee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 07:22:06