Commonly used Keyboard Shortcuts

Last updated

January 1, 2023

Modified

May 26, 2024

VSCode

Mac

### General
Cmd  +  Shift + P      # Command Palette                       
Cmd  +  ,              # Open settings                         
Cmd  +  K  Cmd + S     # Keyboard shoutcuts                    
Cmd  +  B              # Toggle sidebar                        

### Terminal
Cmd   + `              # Open/close the terminal                     
Cmd   + Shift + `      # Create a new the terminal                     
Ctrl  + Pgup /  Pgdn   # Switch between terminal
Cmd   + \              # Split pane within a terminal
Alt   + ← / →          # Switch between panel

### Editor
Cmd   + Shift + N      # Open new window                       
Cmd   + Shift + W      # Close window                          
Cmd   + W              # Close tab                             
Cmd   + \              # Split the editor                            
Cmd   + Shift + Tab    # Navigate tabs                         
Cmd   + 1 / 2 / 3      # Navigate tab groups                   
Ctrl  + 1 / 2 / 3      # Navigate window groups                   

### Text
Cmd   + Opt + ↑ / ↓    # Multiple cursor                       
Cmd   + Shift + ↑ / ↓  # Select text                           
Opt   + ↑ / ↓          # Move the line Up / Down               
Shift + Opt + ↑ / ↓    # Copy line Up / Down                   
Cmd   + D              # Select word                           
Cmd   + L              # Select current line                   
Cmd   + Shift + L      # Select similar occurrences            
Cmd   + Shift + K      # Delete current line                   
Cmd   + Backspace      # Delete one word backward              
Opt   + Backspace      # Delete one word backward              

Cmd   + /              # Comment lines                         
Cmd   + G              # Navigate to  line                     
Cmd   + Opt + [  /  ]  # Code folding                          
Cmd   + [  /  ]        # Indent / outdent lines                
Cmd   + K   Cmd + F    # Format selected code                  
Shift + Opt + F        # Format document                       
Opt   + ← / →          # Go to the start / end of the word     
Cmd   + ← / →          # Go to the start / end of the line     
Cmd   + ↑ / ↓          # Go to beginning or end of file        
Cmd   + Shift + F      # Search files                          
Cmd   + F              # Find text                             
Cmd   + Opt + F        # Replace text                          

Windows

Ctrl + Shift + P         # Command Palette                   
Ctrl + ,                 # Open settings                     
Ctrl + K   Ctrl + S      # Keyboard shoutcuts                
Ctrl + B                 # Toggle sidebar                    

Ctrl + Shift + N         # Open new window                   
Ctrl + Shift + W         # Close window                      
Ctrl + W                 # Close tab                         
Ctrl  + J                # Open the terminal                 
Ctrl + \                 # Split view                        
Ctrl + Shift + Tab       # Navigate tabs                     
Ctrl + 1 / 2 / 3         # Navigate tab groups               

Ctrl + Opt + ↑ / ↓       # Multiple cursor                   
Ctrl + Shift + ↑ / ↓     # Select text                       
Alt + ↑ / ↓              # Move the line Up / Down           
Shift + Alt + ↑ / ↓      # Copy line Up / Down               
Ctrl + D                 # Select word                       
Ctrl + L                 # Select current line               
Ctrl + Shift + L         # Select similar occurrences        
Ctrl + Shift + K         # Delete current line               
Ctrl + Backspace         # Delete one word backward          
Alt + Backspace          # Delete one word backward          
Ctrl + G                 # Navigate to  line                 

Ctrl + /                 # Comment lines                     
Ctrl + Shift + [ / ]     # Code folding                      
Ctrl + [  /  ]           # Indent / outdent lines            
Ctrl + K   Ctrl + F      # Format selected code              
Shift + Alt + F          # Format document                   
Alt + ← / →              # Go to the start / end of the word 
Ctrl + ← / →             # Go to the start / end of the line 
Ctrl + ↑ / ↓             # Go to beginning or end of file    
Ctrl + Shift + F         # Search files                      
Ctrl + F                 # Find text                         
Ctrl + H                 # Replace text                      

Zsh/Bash

Ctrl + A              # Move the cursor to the beginning of the line                       
Ctrl + E              # Move the cursor to the end of the line                             
Opt  + ←              # Move the cursor one word backward                                  
Opt  + →              # Move the cursor one word forward                                   
                     # Move the cursor one character backward                             
                     # Move the cursor one character forward                              

Ctrl + U              # Delete the current line                                            
Ctrl + K              # Delete from the cursor to the end of the line                      
Ctrl + L              # Clear the screen                                                   
Ctrl + W              # Delete one word backward                                           
Ctrl + D              # Delete one character forward                                       
Fn   + Backspace      # Delete one character forward                                       
Backspace             # Delete one character backward                                      

Ctrl + _              # Undo the last change                                               
Ctrl + C              # Terminate the running foreground process                           
Ctrl + Z              # Suspend the running foreground process                             
Ctrl + D              # Exit current shell                                                 
                     # Recall the previous command in history                             
                     # Recall the next command in history                                 
Ctrl + R              # Search the command history                                         
Ctrl + G              # Escape from command search mode                                    
!!                    # Execute the last typed command                                     
!pw                   # Execute the last command in history that begins with pw            
TAB                   # Auto-complete the typed command                                    
TAB TAB               # Show list of commands                                              
TAB TAB TAB ...       # Cycle through matched commands                                     

Tmux

### Shortcut in terminal
alias t="tmux"
alias ta="t a -t"
alias tls="t ls"
alias tn="t new -s"
alias tk="t kill-session -t"
alias tks="t kill-server"

### Change defautl prefix in .tmux.conf
set-option -g prefix C-a
bind-key C-a send-prefix

### To enter copy mode, drag mouse to select text first, then paste with 
Ctrl + A + ]

### Sessions
tmux list-sessions
tmux attach-session -t target-session
Ctrl + A + s     # Switch between seesion
Ctrl + A + l     # Switch to the lastest session, regardless of whether it was detached or attached
Ctrl + A + d     # Detach from linux screen session

### Windows
Ctrl + A + w     # List all windows (the current window is marked with "*").
Ctrl + A + ,     # Rename current window
Ctrl + A + →     # Switch to the next window.                                
Ctrl + A + ←     # Switch to the previous window.                            
Ctrl + A + c     # create a new window.                         
Ctrl + A + q     # kill the current window.                                  

### Panes
Shift + ↑     # Switch to the pane above the current one
Shift + ↓     # Switch to the pane below the current one
Shift + ←     # Switch to the pane left of the current one
Shift + →     # Switch to the pane right of the current one
Ctrl + A + x     # kill the current pane.                                  

Screen

### Shortcut in terminal
alias s="screen"   # start a screen session
alias ss="s -S"    # start a named screen session
alias sr="s -r"    # reattach to a screen session
alias sls="s -ls"  # list the current running screen session

### General commands
screen                   # start a screen session
screen -S session_name   # start a named session
screen -r                # reattach to a linux screen
screen -ls               # list the current running screen session

### Shortcuts
Ctrl + A + C            # create a new window (with shell).
Ctrl + A + K            # kill the current window.
Ctrl + A + W            # list all windows (the current window is marked with "*") .
Ctrl + A + 0-9          # go to a window numbered 0-9 .
Ctrl + A + N            # go to the next window.
Ctrl + A  Ctrl + A      # toggle between the current and previous window.
Ctrl + A + A            # rename the current window.
Ctrl + A + S            # split current region horizontally into two regions.
Ctrl + A + |            # split current region vertically into two regions.
Ctrl + A + Tab          # switch the input focus to the next region.
Ctrl + A + Ctrl + A     # toggle between the current and previous windows
Ctrl + A + Q            # close all regions but the current one.
Ctrl + A + X            # close the current region.
Ctrl + A + D            # detach from linux screen session
Ctrl + A + [            # start copy mode
Ctrl + A + ]            # paste copied text
Ctrl + A + ?            # help, display  a list commands
Ctrl + A + Ctrl + \     # quit screen

Vim

### Modes
i    # Switch to insert mode, so you can type
esc  # Swith to command mode (normal mode)

### Saving and quiting
:w   # Write (save)
:q   # Quit
:wq  # write and quit
:q!  # Quit without saving

### Using arrow keys
h        # Left
j        # Down
k        # Up 
l        # Right

###
w        # Next word 
b        # Previous word

/text    # Serach for text
gg       # Go to the first line
G        # Go to the last line
33G      # go to line 33

###