
記錄一下常見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 檢視當前按鍵繫結。經常使用的快捷鍵先記這一小組就夠了,不需要一次把所有組合背下來。