File size: 5,666 Bytes
1244914
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env zsh

# ZSH Keyboard Shortcuts - Display ZLE keyboard shortcuts
# Shows platform-specific keyboard shortcuts for ZSH Line Editor

# ANSI codes
RESET='\033[0m'
BOLD='\033[1m'
DIM='\033[2m'
CYAN='\033[0;36m'

# Text formatting helpers - auto-reset
function bold() { echo "${BOLD}${1}${RESET}"; }
function dim() { echo "${DIM}${1}${RESET}"; }
function cyan() { echo "${CYAN}${1}${RESET}"; }

# Helper function to print section headers
function print_section() {
    echo ""
    echo "$(bold "$1")"
}

# Helper function to print shortcuts with automatic padding
# Usage: print_shortcut "key" "description"
# If only one argument, prints it as-is (for special messages)
function print_shortcut() {
    local key=$1
    local description=$2

    if [[ -z "$description" ]]; then
        # Single argument - print as-is (for configuration lines)
        echo "  $(dim "${key}")"
    else
        # Two arguments - pad the key and align descriptions
        # Calculate padding based on key length (max 20 chars for alignment)
        local padding=20
        local key_len=${#key}
        local pad_len=$((padding - key_len))
        local pad=""
        if [[ $pad_len -gt 0 ]]; then
            printf -v pad "%${pad_len}s" ""
        fi
        printf "  $(cyan "%s")%s%s\n" "$key" "$pad" "$description"
    fi
}

# Detect platform
platform="unknown"
alt_key="Alt"
if [[ "$(uname)" == "Darwin" ]]; then
    platform="macOS"
    alt_key="Option"
elif [[ "$(uname)" == "Linux" ]]; then
    platform="Linux"
elif [[ "$(uname)" =~ "MINGW" ]] || [[ "$(uname)" =~ "MSYS" ]] || [[ "$(uname)" =~ "CYGWIN" ]] || [[ -n "$WINDIR" ]]; then
    platform="Windows"
fi

# Detect if vi/vim mode is enabled
vi_mode=false
# Check if main keymap is bound to viins or vicmd
if bindkey -lL main 2>/dev/null | grep -q "bindkey -A viins main\|bindkey -A vicmd main"; then
    vi_mode=true
fi

# Show platform and mode info
print_section "Configuration"
if [[ "$platform" != "unknown" ]]; then
    print_shortcut "Platform: ${platform}"
fi
if [[ "$vi_mode" == "true" ]]; then
    print_shortcut "Mode: Vi/Vim keybindings"
else
    print_shortcut "Mode: Emacs keybindings (default)"
fi

if [[ "$vi_mode" == "true" ]]; then
    # Vim mode shortcuts
    print_section "Mode Switching"
    print_shortcut "ESC / Ctrl+[" "Enter command mode (normal)"
    print_shortcut "i" "Enter insert mode"
    print_shortcut "a" "Enter insert mode (after cursor)"
    print_shortcut "A" "Enter insert mode (end of line)"
    print_shortcut "I" "Enter insert mode (start of line)"
    
    print_section "Navigation (Command Mode)"        
    print_shortcut "w" "Move forward one word"
    print_shortcut "b" "Move backward one word"
    print_shortcut "0 / ^" "Move to beginning of line"
    print_shortcut "\$" "Move to end of line"        
    
    print_section "Editing (Command Mode)"
    print_shortcut "dd" "Delete entire line"
    print_shortcut "D" "Delete from cursor to end of line"
    print_shortcut "cc" "Change entire line"
    print_shortcut "C" "Change from cursor to end of line"
    print_shortcut "cw" "Change word"
    print_shortcut "dw" "Delete word"
    print_shortcut "u" "Undo"
    print_shortcut "p" "Paste after cursor"
    print_shortcut "P" "Paste before cursor"
    
    print_section "History (Command Mode)"
    print_shortcut "k / ↑" "Previous command"
    print_shortcut "j / ↓" "Next command"
    print_shortcut "/" "Search history backward"
    print_shortcut "?" "Search history forward"
    print_shortcut "n" "Next search match"
    print_shortcut "N" "Previous search match"
    
    print_section "Insert Mode"
    print_shortcut "Ctrl+W" "Delete word before cursor"
    print_shortcut "Ctrl+U" "Delete from cursor to start"
    
    print_section "Other"
    print_shortcut "v" "Edit command in \$EDITOR"
    print_shortcut "Ctrl+L" "Clear screen"
    print_shortcut "Ctrl+C" "Cancel current command"
    print_shortcut "Ctrl+Z" "Suspend current command"
    print_shortcut "Tab" "Complete command/path"
else
    # Emacs mode shortcuts (default)
    print_section "Line Navigation"
    print_shortcut "Ctrl+A" "Move to beginning of line"
    print_shortcut "Ctrl+E" "Move to end of line"        
    print_shortcut "${alt_key}+F" "Move forward one word"
    print_shortcut "${alt_key}+B" "Move backward one word"
    
    print_section "Editing"
    print_shortcut "Ctrl+U" "Kill line before cursor"
    print_shortcut "Ctrl+K" "Kill line after cursor"
    print_shortcut "Ctrl+W" "Kill word before cursor"
    print_shortcut "${alt_key}+D" "Kill word after cursor"
    print_shortcut "Ctrl+Y" "Yank (paste) killed text"
    print_shortcut "Ctrl+_" "Undo last edit"            
    
    print_section "History"
    print_shortcut "Ctrl+R" "Search command history backward"
    print_shortcut "Ctrl+S" "Search command history forward"
    print_shortcut "Ctrl+P / ↑" "Previous command"
    print_shortcut "Ctrl+N / ↓" "Next command"
    print_shortcut "${alt_key}+<" "Move to first history entry"
    print_shortcut "${alt_key}+>" "Move to last history entry"
    
    print_section "Other"
    print_shortcut "Ctrl+L" "Clear screen"
    print_shortcut "Ctrl+C" "Cancel current command"
    print_shortcut "Ctrl+Z" "Suspend current command"
    print_shortcut "Tab" "Complete command/path"
    
    echo ""
    if [[ "$platform" == "macOS" ]]; then
        echo "  $(dim "If Option key shortcuts don't work, run: forge zsh doctor")"
    elif [[ "$platform" == "Linux" ]]; then
        echo "  $(dim "If Alt key shortcuts don't work, run: forge zsh doctor")"
    fi
    echo "  $(dim "To enable Vi mode, add to ~/.zshrc: bindkey -v")"
fi

echo ""