Skip to content

Instantly share code, notes, and snippets.

@Pcw-Life
Last active November 24, 2024 09:37
Show Gist options
  • Select an option

  • Save Pcw-Life/0f10da756a593764ec477e3941ffc7db to your computer and use it in GitHub Desktop.

Select an option

Save Pcw-Life/0f10da756a593764ec477e3941ffc7db to your computer and use it in GitHub Desktop.
Key Command Cheat Sheets
#**Keyboard Commands and Shortcuts**
##*Terminals*
[Linux Terminal](https://gist.github.com/Pcw-Life/0f10da756a593764ec477e3941ffc7db#file-linix-terminal-commands)
[Mac Terminal](https://gist.github.com/Pcw-Life/0f10da756a593764ec477e3941ffc7db#file-mac-terminal-commands)
##*Softwares & Terminal Add Ons*
[Nano Text Editor](https://gist.github.com/Pcw-Life/0f10da756a593764ec477e3941ffc7db#file-nano-commands)
[Vim Text Editor](https://gist.github.com/Pcw-Life/0f10da756a593764ec477e3941ffc7db#file-vim-commands)
[VScode](https://gist.github.com/Pcw-Life/0f10da756a593764ec477e3941ffc7db#file-vs-code-commands)
[fzf - cli fuzzy finder](https://gist.github.com/Pcw-Life/0f10da756a593764ec477e3941ffc7db#file-fzf-cli-fuzzy-finder)
###Overview and Key Bindings
`fzf` is a command-line fuzzy finder, a powerful and interactive tool for searching and selecting items from a list. It is highly customizable and can be integrated into various workflows, including file searching, command history navigation, and Git operations.
#### Key Features of `fzf`:
- **Blazing Fast Search**: Performs real-time fuzzy searching on large data sets.
- **Extensibility**: Can be integrated with shell commands to enhance productivity.
- **Interactive Interface**: Provides an interactive and visually appealing interface.
- **Cross-Platform**: Works on Linux, macOS, and Windows (via WSL or Cygwin).
---
### Default Key Bindings for `fzf`
When `fzf` is installed, it provides a set of default key bindings for common tasks in the terminal. Below is a breakdown of its functionalities and key bindings:
#### Shell Key Bindings:
1. **CTRL + R**
- **Function**: Fuzzy search through the command history.
- **Use Case**: Quickly find and reuse previously executed commands.
2. **CTRL + T**
- **Function**: Fuzzy search for files and directories under the current directory.
- **Use Case**: Quickly locate and open files.
3. **ALT + C**
- **Function**: Fuzzy search for subdirectories under the current directory and `cd` into the selected directory.
- **Use Case**: Navigate directories faster.
#### Fuzzy Search Commands:
- `fzf --preview '<command>'`:
- Enables a preview window showing the output of a command applied to the selected item.
- Example: `fzf --preview 'cat {}'` to preview the contents of selected files.
- `fzf --multi`:
- Allows multiple selections with `TAB` key.
- Example: `ls | fzf --multi`.
---
### Customizing Key Bindings
To customize or extend `fzf` key bindings, include the following in your `.bashrc` or `.zshrc`:
```bash
# Enable fzf key bindings
if [ -f ~/.fzf.bash ]; then
source ~/.fzf.bash
fi
# Custom binding for file search
bind -x '"\C-f": "fzf | xargs -o vim"' # Open selected file in Vim
# Custom binding for searching processes
bind -x '"\C-p": "ps aux | fzf | awk '{print $2}' | xargs kill"' # Select process to kill
```
---
### Common Use Cases
1. **Search Command History**:
```bash
fzf --history
```
Quickly search and execute previous commands.
2. **Search Files and Open in Editor**:
```bash
find . -type f | fzf | xargs vim
```
Locate a file and open it in Vim or your preferred editor.
3. **Preview File Contents**:
```bash
find . -type f | fzf --preview 'cat {}'
```
View file contents during selection.
4. **Git Integration**:
- Search and checkout branches:
```bash
git branch | fzf | xargs git checkout
```
- Search and apply stash:
```bash
git stash list | fzf | awk '{print $1}' | xargs git stash apply
```
---
### Advanced Options
- **Custom Layout**:
Customize how `fzf` appears on the terminal using options:
```bash
fzf --height=40% --layout=reverse --border
```
- `--height=40%`: Set the height of the fzf interface.
- `--layout=reverse`: Show the search input at the bottom.
- `--border`: Display a border around the fzf window.
- **Search by File Type**:
```bash
find . -type f -name "*.txt" | fzf
```
---
### Installation Verification
To ensure `fzf` key bindings are loaded, run:
```bash
source ~/.fzf.bash
```
# Linux Terminal Commands (Raspberry Pi)
## File System Navigation
- **ls** - List directory contents
- **cd directory** - Change to specified directory
- **pwd** - Show current directory path
- **mkdir directory** - Create a new directory
- **rm filename** - Remove a file
- **rm -r directory** - Remove a directory and its contents
- **mv source target** - Move or rename files and directories
- **cp source target** - Copy files and directories
## File Viewing & Editing
- **cat filename** - Display contents of a file
- **less filename** - View file contents one page at a time
- **nano filename** - Open file in Nano editor
- **head filename** - Show first 10 lines of file
- **tail filename** - Show last 10 lines of file
- **touch filename** - Create an empty file or update timestamp
## System & Process Management
- **top** - Display active processes
- **ps aux** - List all running processes
- **kill PID** - Kill a process with a specified PID
- **sudo shutdown -h now** - Shut down immediately
- **sudo reboot** - Reboot the Raspberry Pi
## Disk Usage
- **df -h** - Show disk usage
- **du -sh directory** - Show directory size
## Network
- **ifconfig** - Display network interfaces
- **ping address** - Ping a network address
- **curl URL** - Retrieve content from URL
- **wget URL** - Download files from URL
## Package Management (APT)
- **sudo apt update** - Update package lists
- **sudo apt upgrade** - Upgrade all packages
- **sudo apt install package** - Install a package
# macOS Terminal Commands
## File System Navigation
- **ls** - List directory contents
- **cd directory** - Change to specified directory
- **pwd** - Show current directory path
- **mkdir directory** - Create a new directory
- **rm filename** - Remove a file
- **rm -r directory** - Remove a directory and its contents
- **mv source target** - Move or rename files and directories
- **cp source target** - Copy files and directories
- **pwd** - show current path
## File Viewing & Editing
- **cat filename** - Display contents of a file
- **less filename** - View file contents one page at a time
- **nano filename** - Open file in Nano editor
- **open filename** - Open file with default application
- **touch filename** - Create an empty file or update timestamp
## System & Process Management
- **top** - Display active processes
- **ps aux** - List all running processes
- **kill PID** - Kill a process with a specified PID
- **sudo shutdown -h now** - Shut down immediately
- **sudo reboot** - Reboot the computer
## Disk Usage
- **df -h** - Show disk usage
- **du -sh directory** - Show directory size
## Network
- **ifconfig** - Display network interfaces
- **ping address** - Ping a network address
- **curl URL** - Retrieve content from URL
- **wget URL** - Download files from URL (requires installation)
## Package Management
- **brew install package** - Install a package using Homebrew
- **brew update** - Update Homebrew
- **brew upgrade package** - Upgrade a specific package
# Nano Key Commands
## Basic Navigation
- **Ctrl + A** - Move to the beginning of the line
- **Ctrl + E** - Move to the end of the line
- **Ctrl + Y** - Move up one page
- **Ctrl + V** - Move down one page
- **Ctrl + _** - Go to a specific line
## Editing Text
- **Ctrl + K** - Cut text (line or selection)
- **Ctrl + U** - Paste text
- **Ctrl + 6** - Start marking text (for cut and paste)
- **Ctrl + W** - Search for text
- **Ctrl + T** - Open spell checker
## Saving and Exiting
- **Ctrl + O** - Write/save file
- **Ctrl + X** - Exit nano
- **Ctrl + G** - Open help
## Other Useful Commands
- **Ctrl + R** - Insert another file
- **Ctrl + C** - Show the current cursor position
- **Alt + U** - Undo last action
- **Alt + E** - Redo last action
# Let's create a comprehensive list of Vim commands and save them into a text file.
vim_commands = """
# Vim Key Commands
## Basic Modes
- **i** - Insert mode
- **Esc** - Return to Normal mode
- **v** - Visual mode
- **V** - Visual Line mode
- **Ctrl + v** - Visual Block mode
- **:q** - Quit
- **:w** - Write/save file
- **:wq** - Save and quit
- **:q!** - Quit without saving
- **:x** - Save and exit (same as :wq)
## Navigation
- **h** - Move left
- **j** - Move down
- **k** - Move up
- **l** - Move right
- **0** - Move to beginning of line
- **$** - Move to end of line
- **w** - Move to beginning of next word
- **b** - Move to beginning of previous word
- **G** - Move to last line of file
- **gg** - Move to first line of file
- **Ctrl + f** - Scroll down one screen
- **Ctrl + b** - Scroll up one screen
## Editing Text
- **x** - Delete character under cursor
- **dd** - Delete current line
- **d3w** - Delete three words
- **u** - Undo last change
- **Ctrl + r** - Redo last undone change
- **y** - Yank (copy) selection
- **p** - Paste after cursor
- **P** - Paste before cursor
- **r** - Replace single character
- **cw** - Change (replace) word
- **c$** - Change (replace) to end of line
## Visual Mode
- **v** - Start visual mode
- **V** - Visual line mode
- **Ctrl + v** - Visual block mode
- **y** - Yank (copy) selected text
- **d** - Delete selected text
- **>** - Indent selection
- **<** - Outdent selection
## Searching
- **/text** - Search forward for "text"
- **?text** - Search backward for "text"
- **n** - Repeat last search in same direction
- **N** - Repeat last search in opposite direction
- **:%s/old/new/g** - Substitute all instances of "old" with "new"
## File Management
- **:e filename** - Open a file named "filename"
- **:w** - Save the file
- **:w filename** - Save as "filename"
- **:q** - Quit
- **:wq** - Save and quit
- **:q!** - Quit without saving
## Tabs
- **:tabnew filename** - Open file in a new tab
- **gt** - Go to next tab
- **gT** - Go to previous tab
- **:tabclose** - Close current tab
## Window Management
- **:split filename** - Split window horizontally and open file
- **:vsplit filename** - Split window vertically and open file
- **Ctrl + w + h** - Move to left window
- **Ctrl + w + j** - Move to below window
- **Ctrl + w + k** - Move to above window
- **Ctrl + w + l** - Move to right window
- **Ctrl + w + q** - Close window
- **Ctrl + w + o** - Close all windows except the current one
## Macros
- **qa** - Start recording macro in register "a"
- **q** - Stop recording macro
- **@a** - Run macro from register "a"
## Miscellaneous
- **:set number** - Show line numbers
- **:set nonumber** - Hide line numbers
- **:set wrap** - Wrap long lines
- **:set nowrap** - Don't wrap long lines
- **:help** - Open Vim help
"""
# Save the commands to a text file
file_path = "/mnt/data/vim_commands_master_list.txt"
with open(file_path, "w") as file:
file.write(vim_commands)
file_path
# VSCode Key Commands
## General
- **Ctrl/Cmd + Shift + P** - Open Command Palette
- **Ctrl/Cmd + P** - Quick Open, Go to File
- **Ctrl/Cmd + Shift + N** - New Window
- **Ctrl/Cmd + W** - Close Window
- **Ctrl/Cmd + ,** - Open Settings
## Editing
- **Ctrl/Cmd + X** - Cut line
- **Ctrl/Cmd + C** - Copy line
- **Ctrl/Cmd + V** - Paste
- **Ctrl/Cmd + Z** - Undo
- **Ctrl/Cmd + Y** - Redo
- **Ctrl/Cmd + D** - Select next match
- **Ctrl/Cmd + L** - Select entire line
## Navigation
- **Ctrl/Cmd + B** - Toggle Sidebar
- **Ctrl/Cmd + Shift + E** - Show Explorer
- **Ctrl/Cmd + Shift + F** - Search
- **Ctrl/Cmd + G** - Go to Line
- **Ctrl/Cmd + T** - Go to Symbol
## Debugging
- **F5** - Start Debugging
- **Shift + F5** - Stop Debugging
- **F9** - Toggle Breakpoint
- **F10** - Step Over
- **F11** - Step Into
## Terminal
- **Ctrl/Cmd + `** - Toggle Integrated Terminal
- **Ctrl/Cmd + Shift + C** - Copy Path of Active File
- **Ctrl/Cmd + K, Ctrl/Cmd + O** - Open Folder in New Window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment