
记录一下常见PC的快捷指令,主要是博主经常忘记,这里记录一下,方便后续查看。
Windows
终端配置
Windows 终端增强配置速查
基础环境
# 安装 PowerShell 7(管理员)
winget install Microsoft.PowerShell
# 创建配置文件
if (!(Test-Path $PROFILE)) { New-Item -Path $PROFILE -ItemType File -Force }
notepad $PROFILE
核心配置
# 历史预测与提示
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle InlineView
# 快捷键:Ctrl+A/E 跳转行首行尾
Set-PSReadLineKeyHandler -Key Ctrl+a -Function BeginningOfLine
Set-PSReadLineKeyHandler -Key Ctrl+e -Function EndOfLine
# 上下箭头匹配前缀
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
# 默认 UTF-8
$PSDefaultParameterValues['*:Encoding'] = 'UTF8'
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
工具安装
# 安装(PowerShell 7 中执行)
winget install lsd
winget install sharkdp.bat --name bat
# 若提示找不到命令,修复 Path(执行后重启终端)
$lsdPath = "${env:LOCALAPPDATA}\Microsoft\WinGet\Packages\lsd-rs.lsd_Microsoft.Winget.Source_8wekyb3d8bbwe"
$batPath = (Get-ChildItem "${env:LOCALAPPDATA}\Microsoft\WinGet\Packages" -Recurse -Filter "bat.exe" | Select-Object -First 1).DirectoryName
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
[Environment]::SetEnvironmentVariable("Path", "$userPath;$lsdPath;$batPath", "User")
别名设置
function ls { lsd $args }
function ll { lsd -la $args }
function la { lsd -a $args }
function cat { bat -p $args } # 纯文本兼容
function catl { bat $args } # 带高亮行号
验证指令
lsd --version # 显示版本即成功
bat README.md # 高亮显示文件
Get-PSReadLineOption | Select-Object PredictionSource # 检查预测开启
Mac
删除
- 清空废纸篓:
Cmd + Shift + Delete - 直接删除不经过废纸篓:
Option + Cmd + Delete - 反向删除:
Fn + Delete
命令行指令提示插件
# 安装插件
mkdir -p ~/.oh-my-zsh/custom/plugins
git clone https://github.com/zsh-users/zsh-autosuggestions \
~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting \
~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
# 注册插件生效
code ~/.zshrc
# 找到 plugins=()
# 改成 plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
source ~/.zshrc # 配置生效

命令行快速到行首尾
快速把光标跳到行首的默认快捷键是:
Ctrl + A
快速把光标跳到行尾的默认快捷键是:
Ctrl + E
Linux
终端里的快捷键
下面按 Bash / Readline 的默认 Emacs 键位记录。终端软件、Shell 或自定义配置可能覆盖这些键,和桌面环境快捷键也不是一回事。
| 快捷键 | 做什么 |
|---|---|
| Ctrl + A / E | 移到行首 / 行尾 |
| Ctrl + U / K | 删除光标之前 / 之后的当前行内容 |
| Ctrl + W | 按空白边界删除光标前一个词 |
| Alt + B / F | 向前 / 向后移动一个词 |
| Ctrl + Y | 放回最近删除的文本 |
| Ctrl + R | 反向搜索命令历史 |
| Ctrl + L | 重绘屏幕,把当前输入留在可见位置 |
Ctrl + R 找到历史命令后,可以先用方向键退出搜索再修改,不要看到类似的命令就直接回车,尤其是涉及删除和远程操作的时候。
停止、挂起和返回
- Ctrl + C:通常中断前台程序。
- Ctrl + Z:通常挂起前台任务,不等于退出;用
jobs查看,fg放回前台。 - Ctrl + D:在空输入行上通常表示 EOF,可能退出 Shell;有输入时,它也可能是删除光标处字符。
这些行为取决于终端和程序是否处理相应信号。进入 Vim、交互式 REPL 等程序后,按它们自己的键位规则来。
常用查看指令
pwd # 当前目录
ls -lah # 文件、权限和大小
less app.log # 分页看日志,q 退出
tail -n 50 app.log # 最后 50 行
tail -f app.log # 持续看新增日志,Ctrl+C 结束
jobs # 当前 Shell 的后台与挂起任务
Bash 里可以用 bind -P 查看当前按键绑定。经常使用的快捷键先记这一小组就够了,不需要一次把所有组合背下来。