### Run Local VimGolf Challenge Source: https://context7.com/dstein64/vimgolf/llms.txt Execute a VimGolf challenge locally using specified start and end files. This allows for practice without an internet connection. You can also provide initial keystrokes to start the challenge. ```bash # Create test files echo "hello world" > /tmp/start.txt echo "world" > /tmp/end.txt # Play local challenge vimgolf local /tmp/start.txt /tmp/end.txt # Play with initial keystrokes vimgolf local /tmp/start.txt /tmp/end.txt "dW" # Interactive session flow: # Launching vimgolf session # [Vim opens with start.txt - user edits to match end.txt] # Here are your keystrokes: dWZZ # Success! Your output matches. # Your score: 4 # [r] Retry the current challenge # [q] Quit vimgolf # Choice> q # Thanks for playing! ``` -------------------------------- ### Vim Golf Local Challenge Source: https://context7.com/dstein64/vimgolf/llms.txt Run Vim Golf challenges locally using start and end files, with optional initial keystrokes. ```APIDOC ## vimgolf local ### Description Runs a local challenge using your own input and output files without requiring internet connectivity or a vimgolf.com account. Useful for practice or creating custom challenges. ### Usage ```bash # Create test files echo "hello world" > /tmp/start.txt echo "world" > /tmp/end.txt # Play local challenge vimgolf local /tmp/start.txt /tmp/end.txt # Play with initial keystrokes vimgolf local /tmp/start.txt /tmp/end.txt "dW" ``` ### Interactive Session Flow ``` # Launching vimgolf session # [Vim opens with start.txt - user edits to match end.txt] # Here are your keystrokes: dWZZ # Success! Your output matches. # Your score: 4 # [r] Retry the current challenge # [q] Quit vimgolf # Choice> q # Thanks for playing! ``` ``` -------------------------------- ### Check VimGolf Client Version Source: https://context7.com/dstein64/vimgolf/llms.txt Display the currently installed version of the VimGolf client. This is useful for ensuring you are running the latest version or for troubleshooting. ```bash vimgolf version # Output: # 0.5.3 ``` -------------------------------- ### VimGolf CLI: Display Version Source: https://context7.com/dstein64/vimgolf/llms.txt The 'vimgolf version' command displays the currently installed version of the VimGolf client. This is useful for checking compatibility or reporting issues. ```bash vimgolf version ``` -------------------------------- ### VimGolf CLI: Show Challenge Details Source: https://context7.com/dstein64/vimgolf/llms.txt The 'vimgolf show' command displays detailed information about a specific VimGolf challenge. This includes the challenge name, description, leaderboard, and the start and end file content. Challenge IDs can be the full vimgolf.com ID or a relative ID from a previous 'list' command. ```bash # Show challenge using vimgolf.com ID vimgolf show 5ca2bc786b547e000c77fd52 # Show challenge using relative ID from last list command vimgolf show +3 ``` -------------------------------- ### VimGolf CLI: Play Remote Challenge Source: https://context7.com/dstein64/vimgolf/llms.txt The 'vimgolf put' command initiates and plays a challenge hosted on vimgolf.com. It downloads the challenge, opens Vim with the starting text, and records user keystrokes. After completion, it displays the score and provides options to retry, view diff, upload results, or exit. It also supports pre-entering initial keystrokes. ```bash # Play a challenge from vimgolf.com vimgolf put 5ca2bc786b547e000c77fd52 # Play using relative ID from last list command vimgolf put +1 # Play with initial keystrokes pre-entered vimgolf put 5ca2bc786b547e000c77fd52 "ihello world" ``` -------------------------------- ### VimGolf CLI: View Challenge Diff Source: https://context7.com/dstein64/vimgolf/llms.txt The 'vimgolf diff' command opens a Vim diff view for a specified challenge. This allows users to visually compare the start file (input) and end file (target) side-by-side, aiding in understanding the required text transformations before attempting the challenge. ```bash # View diff for a challenge using vimgolf.com ID vimgolf diff 5ca2bc786b547e000c77fd52 # View diff using relative ID from last list command vimgolf diff +1 ``` -------------------------------- ### Make HTTP Requests (Python) Source: https://context7.com/dstein64/vimgolf/llms.txt Provides a function `http_request` for making HTTP requests, specifically designed to handle user agent requirements for vimgolf.com API calls. It shows examples of fetching raw HTML content and structured JSON data from the API. ```python from vimgolf.vimgolf import http_request import json # Fetch challenge list HTML response = http_request('https://www.vimgolf.com/') # response.code: 200 # response.msg: 'OK' # response.body: HTML content string # Fetch challenge data as JSON response = http_request('https://www.vimgolf.com/challenges/5ca2bc786b547e000c77fd52.json') challenge = json.loads(response.body) start_text = challenge['in']['data'] end_text = challenge['out']['data'] file_type = challenge['in']['type'] ``` -------------------------------- ### Key Sequence Syntax Source: https://context7.com/dstein64/vimgolf/llms.txt Understand how to represent special keys in the KEYS parameter for commands like `put` and `local`. ```APIDOC ## Key Sequence Syntax ### Special Keys in KEYS Parameter When using the optional KEYS parameter with `put` or `local` commands, special keys are specified using angle bracket notation. The `<` character is assumed to start a special sequence if possible; use `` to enter a literal `<`. #### Examples ```bash # Enter insert mode, type text, escape back to normal mode vimgolf local in.txt out.txt "ihello worldZZ" # Use arrow keys vimgolf local in.txt out.txt "xZZ" # Example: Insert a line with special characters vimgolf local in.txt out.txt "ihtmlbodyZZ" ``` #### Supported Special Keys - `` - Escape key - `` - Carriage return (Enter) - `` - Tab key - `` - Backspace - `` - Delete - `` - Up arrow - `` - Down arrow - `` - Left arrow - `` - Right arrow - `` - Home key - `` - End key - `` - Page Up - ``- Page Down - ``-``- Function keys - `` - Control+A (works for any letter) - `` - Shift+Tab - `` - Literal `<` character - `` - Space character - `` - Backslash character - `` - Pipe character `|` ``` -------------------------------- ### VimGolf CLI: Display Help Message Source: https://context7.com/dstein64/vimgolf/llms.txt The 'vimgolf help' command displays a comprehensive help message outlining all available commands and their usage syntax. This is the primary command for understanding the client's capabilities. ```bash vimgolf help ``` -------------------------------- ### VimGolf CLI: Run Local Challenge Source: https://context7.com/dstein64/vimgolf/llms.txt The 'vimgolf local' command allows users to play challenges locally using their own input and output files. This command is useful for practicing or testing custom challenges without needing to interact with the vimgolf.com server. ```bash # Launch local challenge with specified input and output files vimgolf local input.txt output.txt ``` -------------------------------- ### Environment Variables Source: https://context7.com/dstein64/vimgolf/llms.txt Configure Vim Golf behavior using environment variables. ```APIDOC ## Environment Variables ### GOLF_HOST Specifies a custom vimgolf server URL. Defaults to `https://www.vimgolf.com`. #### Usage ```bash # Use a custom vimgolf server export GOLF_HOST="https://custom-vimgolf-server.com" vimgolf list ``` ### GOLF_VIM Specifies which Vim executable to use. Defaults to `vim`. Supports vim, gvim, mvim, nvim, and nvim-qt. #### Usage ```bash # Use neovim instead of vim export GOLF_VIM="nvim" vimgolf put 5ca2bc786b547e000c77fd52 # Use GUI vim export GOLF_VIM="gvim" vimgolf local input.txt output.txt ``` ``` -------------------------------- ### VimGolf CLI: List Challenges Source: https://context7.com/dstein64/vimgolf/llms.txt The 'vimgolf list' command retrieves and displays a list of challenges from vimgolf.com. It supports pagination, allowing users to specify the page number and the number of challenges to display per page. Results are cached for faster access. ```bash # List first 10 challenges (default) vimgolf list # List challenges from page 2 vimgolf list 2 # List only 5 challenges from page 1 vimgolf list 1:5 # List 20 challenges from page 3 vimgolf list 3:20 ``` -------------------------------- ### Vim Golf Version Source: https://context7.com/dstein64/vimgolf/llms.txt Display the current version of the Vim Golf client. ```APIDOC ## vimgolf version ### Description Displays the current version of the vimgolf client. ### Usage ```bash vimgolf version ``` ### Output Example ``` 0.5.3 ``` ``` -------------------------------- ### Python: HTML Parsing Utilities Source: https://context7.com/dstein64/vimgolf/llms.txt Import and use various HTML parsing functions from the `vimgolf.html` module. These utilities help in extracting challenge data from VimGolf website HTML content. ```python from vimgolf.html import ( parse_html, get_element_by_id, get_elements_by_classname, get_elements_by_tagname, get_text, NodeType, ) ``` -------------------------------- ### Python API: HTML Parsing Utilities Source: https://context7.com/dstein64/vimgolf/llms.txt Provides simple HTML parsing utilities for extracting challenge data from vimgolf.com. ```APIDOC ### HTML Parsing Functions Simple HTML parsing utilities used to extract challenge data from vimgolf.com HTML pages. ```python from vimgolf.html import ( parse_html, get_element_by_id, get_elements_by_classname, get_elements_by_tagname, get_text, NodeType, ) ``` ``` -------------------------------- ### Python API: tokenize_keycode_reprs Source: https://context7.com/dstein64/vimgolf/llms.txt Tokenizes a string of keycode representations into individual key tokens. ```APIDOC ### tokenize_keycode_reprs Function Tokenizes a string of keycode representations (like those used in the KEYS parameter) into individual key tokens. ```python from vimgolf.keys import tokenize_keycode_reprs # Tokenize a keystroke sequence keys = 'iasd' tokens = tokenize_keycode_reprs(keys) # Result: ['i', '', 'a', 's', 'd', ''] # Mixed case is handled keys = 'ihelloZZ' tokens = tokenize_keycode_reprs(keys) # Result: ['i', 'h', 'e', 'l', 'l', 'o', '', 'Z', 'Z'] # Special sequences with modifiers keys = 'vw' tokens = tokenize_keycode_reprs(keys) # Result: ['', 'v', '', 'w'] # Literal < using keys = 'ihtml' tokens = tokenize_keycode_reprs(keys) # Result: ['i', '', 'h', 't', 'm', 'l', '', ''] ``` ``` -------------------------------- ### Configure Custom VimGolf Server Host Source: https://context7.com/dstein64/vimgolf/llms.txt Set the GOLF_HOST environment variable to specify a custom URL for the VimGolf server. This is useful for testing or using alternative server instances. ```bash # Use a custom vimgolf server export GOLF_HOST="https://custom-vimgolf-server.com" vimgolf list ``` -------------------------------- ### Python API: parse_keycodes Source: https://context7.com/dstein64/vimgolf/llms.txt Parses raw keystroke bytes recorded by Vim's `-w` option into a list of keycode byte strings. ```APIDOC ### parse_keycodes Function Parses raw keystroke bytes recorded by Vim's `-w` option into a list of keycode byte strings. Each keycode is represented as a 2-byte value. ```python from vimgolf.keys import parse_keycodes, get_keycode_repr # Raw bytes from vim's keylog (example: typing "ab") raw_keys = bytes([0x61, 0x62, 0x1b]) # 'a', 'b', escape # Parse into keycodes keycodes = parse_keycodes(raw_keys) # Result: [b'\x00a', b'\x00b', b'\x00\x1b'] # Convert to human-readable representations readable_keys = [get_keycode_repr(kc) for kc in keycodes] # Result: ['a', 'b', ''] # Example with special keys (0x80 prefix indicates 2-byte sequence) raw_special = bytes([0x80, ord('k'), ord('u')]) # Up arrow keycodes = parse_keycodes(raw_special) readable = get_keycode_repr(keycodes[0]) # Result: '' ``` ``` -------------------------------- ### VimGolf CLI: Configure API Key Source: https://context7.com/dstein64/vimgolf/llms.txt The 'vimgolf config' command is used to set or display the VimGolf API key. This key is essential for uploading scores to vimgolf.com and is stored locally. It requires a 32-character alphanumeric string obtained from the user's vimgolf.com account. ```bash # Display current API key vimgolf config # Set a new API key (32-character alphanumeric string from vimgolf.com) vimgolf config abc123def456ghi789jkl012mno345pq ``` -------------------------------- ### Python: Tokenize Keystroke Representations Source: https://context7.com/dstein64/vimgolf/llms.txt Utilize the `tokenize_keycode_reprs` function from `vimgolf.keys` to break down a string of keycode representations into individual key tokens. This handles special sequences and modifiers. ```python from vimgolf.keys import tokenize_keycode_reprs # Tokenize a keystroke sequence keys = 'iasd' tokens = tokenize_keycode_reprs(keys) # Result: ['i', '', 'a', 's', 'd', ''] # Mixed case is handled keys = 'ihelloZZ' tokens = tokenize_keycode_reprs(keys) # Result: ['i', 'h', 'e', 'l', 'l', 'o', '', 'Z', 'Z'] # Special sequences with modifiers keys = 'vw' tokens = tokenize_keycode_reprs(keys) # Result: ['', 'v', '', 'w'] # Literal < using keys = 'ihtml' tokens = tokenize_keycode_reprs(keys) # Result: ['i', '', 'h', 't', 'm', 'l', '', ''] ``` -------------------------------- ### Configure Vim Executable for VimGolf Source: https://context7.com/dstein64/vimgolf/llms.txt Set the GOLF_VIM environment variable to choose which Vim executable VimGolf should use. Supports various Vim versions including nvim and gvim. ```bash # Use neovim instead of vim export GOLF_VIM="nvim" vimgolf put 5ca2bc786b547e000c77fd52 # Use GUI vim export GOLF_VIM="gvim" vimgolf local input.txt output.txt ``` -------------------------------- ### VimGolf Special Keys Syntax Source: https://context7.com/dstein64/vimgolf/llms.txt Learn how to represent special keys within the KEYS parameter for VimGolf commands like 'put' and 'local'. Special keys are enclosed in angle brackets. ```bash # Enter insert mode, type text, escape back to normal mode vimgolf local in.txt out.txt "ihello worldZZ" # Use arrow keys vimgolf local in.txt out.txt "xZZ" # Special key examples: # - Escape key # - Carriage return (Enter) # - Tab key # - Backspace # - Delete # - Up arrow # - Down arrow # - Left arrow # - Right arrow # - Home key # - End key # - Page Up # - Page Down # -- Function keys # - Control+A (works for any letter) # - Shift+Tab # - Literal < character # - Space character # - Backslash character # - Pipe character | # Example: Insert a line with special characters vimgolf local in.txt out.txt "ihtmlbodyZZ" ``` -------------------------------- ### Parse HTML and Extract Data (Python) Source: https://context7.com/dstein64/vimgolf/llms.txt Demonstrates parsing HTML content using utility functions to find elements by ID, class name, and tag name. It also shows how to extract text content and attributes from HTML nodes. This is useful for scraping data from web pages. ```python html = '''
Challenge Name 100 entries

Description text

''' nodes = parse_html(html) content = get_element_by_id(nodes, 'content') challenges = get_elements_by_classname(nodes, 'challenge') for challenge in challenges: anchor = get_elements_by_tagname(challenge.children, 'a')[0] name = get_text([anchor]) href = anchor.get_attr('href') print(f"Challenge: {name}, URL: {href}") ``` -------------------------------- ### Python: Parse Vim Keystroke Bytes Source: https://context7.com/dstein64/vimgolf/llms.txt Use the `parse_keycodes` function from `vimgolf.keys` to convert raw keystroke bytes recorded by Vim into a list of keycode byte strings. `get_keycode_repr` converts these to human-readable strings. ```python from vimgolf.keys import parse_keycodes, get_keycode_repr # Raw bytes from vim's keylog (example: typing "ab") raw_keys = bytes([0x61, 0x62, 0x1b]) # 'a', 'b', escape # Parse into keycodes keycodes = parse_keycodes(raw_keys) # Result: [b'\x00a', b'\x00b', b'\x00\x1b'] # Convert to human-readable representations readable_keys = [get_keycode_repr(kc) for kc in keycodes] # Result: ['a', 'b', ''] # Example with special keys (0x80 prefix indicates 2-byte sequence) raw_special = bytes([0x80, ord('k'), ord('u')]) # Up arrow keycodes = parse_keycodes(raw_special) readable = get_keycode_repr(keycodes[0]) # Result: '' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.