A fresh Windows 11 installation already contains the component that makes PowerShell comfortable to type into, and few people ever open its settings. PSReadLine owns the command line itself. It draws the text, interprets each keystroke, keeps the scrollable history, and colors syntax while the line is still being edited. The module loads without being asked in Windows PowerShell 5.1 and in PowerShell 7, yet its defaults are restrained. Suggestions stay off, and the palette looks inherited from a text console of another era. The part that turns a bare prompt into a tool that stops getting in the way lives in a profile script and depends on the order of its lines.
Where the Bundled Module Stops and the Profile Begins
Windows 11 carries Windows PowerShell 5.1 in $PSHOME and, once installed, PowerShell 7 beside it. Each host ships its own copy: the 5.1 build sits on the 2.0 release line, while PowerShell 7 carries a newer build with list view and plugin prediction. Get-Module PSReadLine | Select-Object Version, Path shows which copy a session loaded. The module is not cosmetic. It defines the PSConsoleHostReadLine function that the console host calls for a line of input, which is why every keystroke passes through it.
A newer release installs into the user scope, which the host prefers: Install-Module PSReadLine -Scope CurrentUser -Force. Options set in a session are never written down, though. Close the Windows Terminal tab and the next window starts from the old defaults.
Persistence belongs to a profile script. $PROFILE.CurrentUserAllHosts resolves to Documents\PowerShell\profile.ps1 for PowerShell 7 and to Documents\WindowsPowerShell\profile.ps1 for 5.1. A third file dot-sourced by both profiles keeps the hosts in step and avoids a second copy that drifts. Profiles load for script runs too unless -NoProfile is passed, which is why automation that must not inherit personal settings passes it.
Choosing an Edit Mode That Matches Years of Habit
-EditMode accepts three values, and the choice is closer to a keyboard layout than to a color theme. Windows, the default, keeps Home and End at the ends of the line, Ctrl+Left and Ctrl+Right moving by word, and F8 walking backward through history that matches the text already typed. Emacs maps Ctrl+A and Ctrl+E to the ends, Ctrl+K to cut after the cursor, Ctrl+Y to paste that text back, and Ctrl+R to a reverse search that narrows with each character. Vi adds a command mode reached with Esc, where dd deletes a line, yy copies it, and / starts a search that n repeats.
The default suits administrators who live in Notepad and Visual Studio, because those editors taught the same chords. Emacs rewards anyone who also works on Linux, where Bash and most editors that imitate it accept those keys. Vi pays off for people already fluent in Vim; for them -ViModeIndicator Cursor is worth adding, since the cursor shape then reveals which mode is active.
One detail trips up almost everyone who writes a profile by hand. Setting -EditMode discards every binding registered with Set-PSReadLineKeyHandler. The mode has to come first. A profile that binds keys at the top and sets the mode at the bottom loses all of them, and the symptom reads as a broken terminal.
History Files That Outlast the Window That Wrote Them
PSReadLine keeps two histories: the in-memory list the arrow keys walk and the file on disk that feeds the next session. -HistorySaveStyle decides how the two meet. SaveIncrementally, the default, appends each command as it runs, so a crash costs one line at most and a second terminal sees the command at once. SaveAtExit writes once on close and loses the session if the window closes the hard way. SaveNothing suits a shared kiosk account and little else.
The file lives at $env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt unless -HistorySavePath says otherwise. Both hosts can point at the same file, so a command typed in 5.1 can be recalled in 7. Pointing the path at a missing folder fails on the first write, so the profile creates the folder before it sets the option. A history file shared by several accounts should be readable only by those accounts, because every command typed into the console is stored there in plain text.
New-Item -ItemType Directory -Path "$HOME\PSReadLine" -Force | Out-Null
Set-PSReadLineOption -HistorySaveStyle SaveIncrementally
Set-PSReadLineOption -HistorySavePath "$HOME\PSReadLine\console_history.txt"
Set-PSReadLineOption -AddToHistoryHandler {
param([string]$line) $line -notmatch '(?i)password|secret'
}
-MaximumHistoryCount caps how many entries are kept. Low tens of thousands cost little at startup; six figures add a visible delay to every new window and slow the search. -HistoryNoDuplicates is subtler than its name. Duplicates still reach the file, preserving the order of work, but recall shows only the most recent copy, which stops the arrow keys from cycling through the same three commands. Search ignores case by default, which suits command names, and -HistorySearchCaseSensitive matters only for paths on shares that treat case as significant.
The handler in that block receives each command line and decides whether to store it. Returning $false for anything resembling a credential keeps passwords out of a plain text file that backups copy and sync tools replicate. It is a habit rather than a guarantee, since a typist can shape a secret the pattern misses. Because the file is plain text, any editor can search it and a damaged line is easy to delete.
Predictive Text Before Any Predictor Module Is Installed
Prediction arrived in PSReadLine 2.1 and became usable in 2.2, which added the list view and the combined source. -PredictionSource History needs nothing beyond the history file that already exists. With InlineView, the suggested remainder appears in gray after the cursor, and the Right Arrow at the end of the line accepts it. With ListView, a menu opens under the prompt, arrows move through the candidates, and Enter accepts the highlighted one. Each entry carries a tag such as [History] naming its source.
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineKeyHandler -Chord 'Alt+RightArrow' -Function AcceptSuggestion
HistoryAndPlugin adds predictors that other modules register through the CommandPrediction interface, which PowerShell 7.1 introduced. Plugin predictions can read the current directory, the previous error, or a module's naming conventions. They also need maintenance, so a two-step rollout makes sense: history for a week, then plugins if the machine runs PowerShell 7.
The failure mode is worth naming. Suggestions reflect whatever the history contains, including wrong or obsolete commands, and a familiar gray string invites Enter without reading. A history pruned of one-off experiments produces better suggestions than a very long one. AcceptSuggestion and AcceptNextSuggestionWord arrive unbound, so binding one of them gives a deliberate way to accept without touching the arrow keys.
Color Rules That Keep a Long Pipeline Legible
Syntax coloring is token based. The parser classifies each piece of the line as a command, parameter, string, number, variable, operator, member, keyword, or comment, and -Colors maps those classes to values. The hashtable accepts ConsoleColor names such as Cyan, or ANSI escape sequences for terminals that support 256 colors. Named colors give sixteen choices and work everywhere. Escape sequences give finer control and degrade to plain text in hosts that do not parse them.
Set-PSReadLineOption -Colors @{
Command = 'Cyan'
Parameter = 'DarkCyan'
String = 'Green'
Comment = 'DarkGray'
}
Judgment matters more than the palette. Four to six colors cover most work: commands, parameters, strings, comments, and an accent for variables or errors. Coloring every class turns a pipeline into a paint chart, and the eye stops using color as a signal. Contrast is the other constraint, since one profile runs in a dark terminal and a light one; a mid-tone gray that works on black is nearly invisible on white. Selection and InlinePrediction deserve separate attention, because both draw muted text that must stay distinguishable. A quick test is to type a broken command next to a long string, then read the result on both the light and the dark theme in use, since a palette that passes on one often fails on the other.
Error controls how a line that fails to parse is shown before it is accepted. A red reserved for that moment is more useful than red everywhere. (Get-PSReadLineOption).Colors returns the current table, which shows what a theme or another module has already changed.
Custom Key Handlers for Steps You Repeat Every Day
Set-PSReadLineKeyHandler takes a chord and either a named function or a script block. The built-ins cover the useful cases: prefix search through history, incremental reverse search, menu completion, and acceptance of a prediction. A chord can be a sequence such as Ctrl+x,Ctrl+l, which is how two-stroke bindings are expressed.
Set-PSReadLineKeyHandler -Chord 'UpArrow' -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Chord 'DownArrow' -Function HistorySearchForward
Set-PSReadLineKeyHandler -Chord 'Ctrl+Alt+g' -ScriptBlock {
param($key, $arg)
$branch = git rev-parse --abbrev-ref HEAD 2>$null
if ($LASTEXITCODE -eq 0) {
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($branch)
}
}
Script blocks reach the buffer through the PSConsoleReadLine class. Insert adds text at the cursor, Replace overwrites a range, GetBufferState returns the current line and cursor position through [ref] parameters, SetCursorPosition moves the caret, and AcceptLine runs what has been typed. A handler that only inserts text is the safest kind, because it cannot leave the line half edited.
Three cautions apply. Handlers run on the thread that reads keys, so a slow command inside one freezes typing until it returns; the git lookup above takes milliseconds in a normal repository and would be a poor place for a network call. Exceptions print to the console and can leave the display in an odd state, so a guard clause and a $null check are cheap insurance. Bindings reset whenever -EditMode is set, and in Vi mode -ViMode limits a binding to one mode.
The arrow bindings deserve a note. With them, typing git and pressing Up finds the last command that started with those letters instead of the last command of any kind. That change removes more wasted keystrokes than any other line in the profile, and it costs nothing to reverse.
One Profile Block Worth Copying to Every Machine
The settings are most manageable as one hashtable splatted into a single call, with key handlers after it. The guard keeps the file quiet in hosts that never load the module, such as the console inside some editors.
if ($Host.Name -ne 'ConsoleHost') { return }
$options = @{
EditMode = 'Emacs'
HistorySaveStyle = 'SaveIncrementally'
PredictionSource = 'History'
}
Set-PSReadLineOption @options
Set-PSReadLineKeyHandler -Chord 'UpArrow' -Function HistorySearchBackward
Testing without a restart is a matter of dot-sourcing: . $PROFILE. If a setting throws, the error names the line and the change can be backed out before it reaches a new window. Get-PSReadLineKeyHandler | Where-Object Function -eq 'AcceptSuggestion' confirms a binding is live, and Remove-PSReadLineKeyHandler -Chord 'Ctrl+Alt+g' takes one away when chords collide.
Backing up the file is worth the trouble, because it is small, portable, and built from accumulated decisions. The profile should also stay fast. Every new terminal pays its cost, and a file that imports five modules to decorate a prompt is felt each time a window opens. Measure-Command { . $PROFILE } gives a number, and one that keeps climbing is the signal that decoration has outgrown the tool.
None of this needs new software on Windows 11 or a plugin repository. PSReadLine already reads every command that gets typed, and the profile only tells it which habits to honor. Prefix search, a suggestion accepted without retyping, a string that ends where the eye expects, a branch name pasted from a lookup a moment earlier: the gains are small and they arrive several dozen times a day.
The configuration is also portable. One plain text file, no dependencies beyond the module that ships with the operating system, and every line explainable a year later. That combination deserves protecting, because a shell that is slightly better every month, with the improvements stored where they can be read and reviewed, outlasts any single feature.