Skip to main content

Powershell Hotkeys Emacs

·1435 words·7 mins
Powershell
Table of Contents

Set Edit Mode
#

Set-PSReadLineOption -EditMode Emacs

put it in the powershell initialization script:

  • profile.ps1 in the same directory with pwsh.exe ($PSHOME)
  • or $PROFILE, by default %USERPFORILE%/Documents/PowerShell/Microsoft.PowerShell_profile.ps1

View Unbounded Commands
#

Get-PSReadLineKeyHandler -Unbound

View Specific Key Binding
#

Alt+?, then enter keys, and bounded command will be shown

View Key Bindings
#

Get-PSReadLineKeyHandler, which prints:

Basic editing functions
#

KeyFunctionDescription
Ctrl+gAbortAbort the current operation, e.g. incremental history search
Ctrl+oAcceptAndGetNextAccept the current line and recall the next line from history after the current line finishes executing
EnterAcceptLineAccept the input or move to the next line if input is missing a closing token.
Shift+EnterAddLineMove the cursor to the next line without attempting to execute the input
BackspaceBackwardDeleteCharDelete the character before the cursor
Ctrl+BackspaceBackwardDeleteCharDelete the character before the cursor
Ctrl+hBackwardDeleteCharDelete the character before the cursor
Ctrl+uBackwardKillInputMove the text from the cursor to the beginning of the input to the kill ring
Ctrl+x,BackspaceBackwardKillInputMove the text from the cursor to the beginning of the input to the kill ring
Alt+BackspaceBackwardKillWordMove the text from the start of the current or previous word to the cursor to the kill ring
Escape,BackspaceBackwardKillWordMove the text from the start of the current or previous word to the cursor to the kill ring
Alt+cCapitalizeWordFind the next word starting from the current position and then upcase the first character and downcase the remaining characters.
Escape,cCapitalizeWordFind the next word starting from the current position and then upcase the first character and downcase the remaining characters.
Ctrl+cCopyOrCancelLineEither copy selected text to the clipboard, or if no text is selected, cancel editing the line with CancelLine.
DeleteDeleteCharDelete the character under the cursor
Ctrl+dDeleteCharOrExitDelete the character under the cursor, or if the line is empty, exit the process.
Alt+lDowncaseWordFind the next word starting from the current position and then make it lower case.
Escape,lDowncaseWordFind the next word starting from the current position and then make it lower case.
Ctrl+kKillLineMove the text from the cursor to the end of the input to the kill ring
Alt+dKillWordMove the text from the cursor to the end of the current or next word to the kill ring
Escape,dKillWordMove the text from the cursor to the end of the current or next word to the kill ring
Alt+rRevertLineEquivalent to undo all edits (clears the line except lines imported from history)
Escape,rRevertLineEquivalent to undo all edits (clears the line except lines imported from history)
Ctrl+tSwapCharactersSwap the current character with the character before it.
Ctrl+_UndoUndo a previous edit
Ctrl+x,Ctrl+uUndoUndo a previous edit
Ctrl+wUnixWordRuboutMove the text from the cursor to the start of the current or previous whitespace delimited word to the kill ring
Alt+uUpcaseWordFind the next word starting from the current position and then make it upper case.
Escape,uUpcaseWordFind the next word starting from the current position and then make it upper case.
Ctrl+mValidateAndAcceptLineAccept 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+yYankCopy the text from the current kill ring position to the input
Alt+.YankLastArgCopy the text of the last argument to the input
Alt+_YankLastArgCopy the text of the last argument to the input
Escape,.YankLastArgCopy the text of the last argument to the input
Escape,_YankLastArgCopy the text of the last argument to the input
Ctrl+Alt+yYankNthArgCopy the text of the first argument to the input
Escape,Ctrl+yYankNthArgCopy the text of the first argument to the input
Alt+yYankPopReplace the previously yanked text with the text from the next kill ring position
Escape,yYankPopReplace the previously yanked text with the text from the next kill ring position

Cursor movement functions
#

KeyFunctionDescription
LeftArrowBackwardCharMove the cursor back one character
Ctrl+bBackwardCharMove the cursor back one character
Alt+bBackwardWordMove the cursor to the beginning of the current or previous word
Escape,bBackwardWordMove the cursor to the beginning of the current or previous word
HomeBeginningOfLineMove the cursor to the beginning of the line
Ctrl+aBeginningOfLineMove the cursor to the beginning of the line
EndEndOfLineMove the cursor to the end of the line
Ctrl+eEndOfLineMove the cursor to the end of the line
RightArrowForwardCharMove the cursor forward one character
Ctrl+fForwardCharMove the cursor forward one character
Alt+fForwardWordMove the cursor forward to the end of the current word, or if between words, to the end of the next word.
Escape,fForwardWordMove the cursor forward to the end of the current word, or if between words, to the end of the next word.

History functions
#

KeyFunctionDescription
Alt+«/kbd>BeginningOfHistoryMove to the first item in the history
Alt+>EndOfHistoryMove to the last item (the current input) in the history
Ctrl+sForwardSearchHistorySearch history forward interactively
DownArrowNextHistoryReplace the input with the next item in the history
Ctrl+nNextHistoryReplace the input with the next item in the history
UpArrowPreviousHistoryReplace the input with the previous item in the history
Ctrl+pPreviousHistoryReplace the input with the previous item in the history
Ctrl+rReverseSearchHistorySearch history backwards interactively

Completion functions
#

KeyFunctionDescription
TabCompleteComplete the input if there is a single completion, otherwise complete the input with common prefix for all completions. Show possible completions if pressed a second time.
Ctrl+SpacebarMenuCompleteComplete the input if there is a single completion, otherwise complete the input by selecting from a menu of possible completions.
Alt+=PossibleCompletionsDisplay the possible completions without changing the input

Prediction functions
#

KeyFunctionDescription
F4ShowFullPredictionTooltipShow the full tooltip of the selected list-view item in the terminal’s alternate screen buffer.
F2SwitchPredictionViewSwitch between the inline and list prediction views.

Miscellaneous functions
#

KeyFunctionDescription
Ctrl+lClearScreenClear the screen and redraw the current line at the top of the screen
Alt+0DigitArgumentStart or accumulate a numeric argument to other functions
Alt+1DigitArgumentStart or accumulate a numeric argument to other functions
Alt+2DigitArgumentStart or accumulate a numeric argument to other functions
Alt+3DigitArgumentStart or accumulate a numeric argument to other functions
Alt+4DigitArgumentStart or accumulate a numeric argument to other functions
Alt+5DigitArgumentStart or accumulate a numeric argument to other functions
Alt+6DigitArgumentStart or accumulate a numeric argument to other functions
Alt+7DigitArgumentStart or accumulate a numeric argument to other functions
Alt+8DigitArgumentStart or accumulate a numeric argument to other functions
Alt+9DigitArgumentStart or accumulate a numeric argument to other functions
Alt+-DigitArgumentStart or accumulate a numeric argument to other functions
PageDownScrollDisplayDownScroll the display down one screen
Ctrl+PageDownScrollDisplayDownLineScroll the display down one line
Ctrl+EndScrollDisplayToCursorScroll the display to the cursor
Ctrl+HomeScrollDisplayTopScroll the display to the top
PageUpScrollDisplayUpScroll the display up one screen
Ctrl+PageUpScrollDisplayUpLineScroll the display up one line
F1ShowCommandHelpShows help for the command at the cursor in an alternate screen buffer.
Ctrl+Alt+?ShowKeyBindingsShow all key bindings
Alt+hShowParameterHelpShows help for the parameter at the cursor.
Ctrl+x,Ctrl+eViEditVisuallyInvokes the console compatible editor specified by $env:VISUAL or $env:EDITOR on the current command line.
Alt+?WhatIsKeyShow the key binding for the next chord entered

Selection functions
#

KeyFunctionDescription
Ctrl+x,Ctrl+xExchangePointAndMarkMark the location of the cursor and move the cursor to the position of the previous mark
Shift+LeftArrowSelectBackwardCharAdjust the current selection to include the previous character
Shift+HomeSelectBackwardsLineAdjust the current selection to include from the cursor to the start of the line
Alt+BSelectBackwardWordAdjust the current selection to include the previous word
Alt+aSelectCommandArgumentMake visual selection of the command arguments.
Shift+RightArrowSelectForwardCharAdjust the current selection to include the next character
Alt+FSelectForwardWordAdjust the current selection to include the next word using ForwardWord
Shift+EndSelectLineAdjust the current selection to include from the cursor to the end of the line
Ctrl+@SetMarkMark the location of the cursor

Search functions
#

KeyFunctionDescription
Ctrl+]CharacterSearchRead a character and move the cursor to the next occurrence of that character
Ctrl+Alt+]CharacterSearchBackwardRead a character and move the cursor to the previous occurrence of that character

Sources
#