### Install Firenvim with lazy.nvim Source: https://github.com/glacambre/firenvim/blob/master/README.md Use this configuration for the lazy.nvim plugin manager to install Firenvim. Ensure the build step is included to run the post-install script. ```lua { 'glacambre/firenvim', build = ":call firenvim#install(0)" } ``` -------------------------------- ### Install Firenvim from source with Neovim Source: https://github.com/glacambre/firenvim/blob/master/README.md Install Firenvim using Neovim's headless mode. This command executes the post-install script and then quits Neovim. ```sh $ nvim --headless "+call firenvim#install(0) | q" ``` -------------------------------- ### Install Firenvim with vim-plug Source: https://github.com/glacambre/firenvim/blob/master/README.md Configure vim-plug to install Firenvim. The 'do' hook ensures the post-install script is executed after installation. ```vim Plug 'glacambre/firenvim', { 'do': { _ -> firenvim#install(0) } } ``` -------------------------------- ### Install Firenvim Neovim Plugin Source: https://github.com/glacambre/firenvim/blob/master/TROUBLESHOOTING.md Run this command within Neovim to install the Firenvim plugin. Check the output for success or specific error messages. ```vim call firenvim#install(0) ``` ```vim call firenvim#install(1) ``` -------------------------------- ### Install Firenvim with minpac Source: https://github.com/glacambre/firenvim/blob/master/README.md Add Firenvim using the minpac plugin manager. This configuration includes options for lazy loading and executing the post-install script. ```vim call minpac#add('glacambre/firenvim', { 'type': 'opt', 'do': 'packadd firenvim | call firenvim#install(0)'}) if exists('g:started_by_firenvim') packadd firenvim endif ``` -------------------------------- ### Build Firenvim without Docker Source: https://github.com/glacambre/firenvim/blob/master/CONTRIBUTING.md Build Firenvim locally using npm. This requires NodeJS, npm, and Neovim >= 0.4. It installs dependencies, builds the project, and installs manifests. ```sh git clone https://github.com/glacambre/firenvim cd firenvim npm install npm run build npm run install_manifests ``` -------------------------------- ### Override Takeover Setting for UK Websites Source: https://github.com/glacambre/firenvim/blob/master/README.md Provide an example of overriding a local setting for specific URLs. This snippet increases the priority of a new regex to ensure it takes precedence over the default '.*' pattern for UK websites, changing the 'takeover' behavior. ```lua vim.g.firenvim_config.localSettings["https?://[^/]+\.co\.uk/"] = { takeover = 'never', priority = 1 } ``` -------------------------------- ### Focus Page or Input Field with Firenvim Source: https://github.com/glacambre/firenvim/blob/master/README.md Map keys to `firenvim#focus_page()` or `firenvim#focus_input()` to move focus from the editor back to the web page or an input field. This example maps double Escape to focus the page. ```lua vim.api.nvim_set_keymap("n", "", "call firenvim#focus_page()", {}) ``` -------------------------------- ### Site-Specific Editor Settings Source: https://github.com/glacambre/firenvim/wiki/Filetypes-for-websites-&-more Applies custom editor settings for specific websites. For example, it can change the colorscheme for GitHub or configure key mappings for chat applications like Riot.im to better suit their interaction models. ```vim let l:bufname=expand('%:t') if l:bufname =~? 'github.com' colorscheme github elseif l:bufname =~? 'riot.im' " for chat apps. Enter sends the message and deletes the buffer. " Shift enter is normal return. Insert mode by default. " Note that slack and gitter probably don't respond appropriately to press_keys. Workarounds might directly call javascript functions to send the messages. normal! i inoremap :w:call firenvim#press_keys("CR>")ggdGa inoremap endif ``` -------------------------------- ### Conditionally Set Neovim Statusline with Firenvim Source: https://github.com/glacambre/firenvim/blob/master/README.md Set Neovim's laststatus option differently based on whether Firenvim started the instance. This is useful for distinguishing between normal Neovim sessions and those managed by Firenvim. ```lua if vim.g.started_by_firenvim == true then vim.o.laststatus = 0 else vim.o.laststatus = 2 end ``` -------------------------------- ### Initialize Monaco Editor Synchronously Source: https://github.com/glacambre/firenvim/blob/master/tests/pages/monaco.html Configure the paths for Monaco Editor and create an editor instance. Ensure the 'vs' path is correctly set relative to your project. ```javascript var require = { paths: { 'vs': '../node_modules/monaco-editor/min/vs' } }; var editor = monaco.editor.create(document.getElementById('container'), { value: [ 'function x() {', '\tconsole.log("Hello world!");', '}' ].join('\n'), language: 'typescript' }); ``` -------------------------------- ### Check Flatpak/Snap Permissions Source: https://github.com/glacambre/firenvim/blob/master/TROUBLESHOOTING.md Verify if Flatpak or Snap sandboxing is preventing Firenvim from running. Adjust permissions if necessary. ```bash flatpak permissions webextensions ``` ```bash flatpak permission-set webextensions firenvim snap.firefox yes ``` -------------------------------- ### Build Firenvim with Docker Source: https://github.com/glacambre/firenvim/blob/master/CONTRIBUTING.md Use this command to build Firenvim using Docker, requiring Docker 18.09+ for BuildKit support. The output is directed to the 'target' directory. ```sh git clone https://github.com/glacambre/firenvim cd firenvim DOCKER_BUILDKIT=1 docker build . -t firenvim --output target ``` -------------------------------- ### Fast Webpack Builds for Firenvim Source: https://github.com/glacambre/firenvim/blob/master/CONTRIBUTING.md Use these commands for faster, targeted builds during development. They allow you to build only for Firefox or Chrome, speeding up iteration. ```sh "$(npm bin)/webpack --env=firefox" ``` ```sh "$(npm bin)/webpack" --env=chrome ``` -------------------------------- ### Initialize Ace Editor and Set Mode Source: https://github.com/glacambre/firenvim/blob/master/tests/pages/ace.html Initializes the Ace editor and sets the session mode to JavaScript. Ensure the editor element exists in the DOM. ```javascript var editor = ace.edit("editor"); editor.getSession().setMode("ace/mode/javascript"); ``` -------------------------------- ### Create Basic CodeMirror Instance Source: https://github.com/glacambre/firenvim/blob/master/tests/pages/codemirror.html Initializes a CodeMirror instance from a textarea element. Enables line numbers for better readability. ```html ``` ```javascript var editor = CodeMirror.fromTextArea(myTextarea, { lineNumbers: true }); ``` -------------------------------- ### Configure Firenvim Command Line Source: https://github.com/glacambre/firenvim/blob/master/README.md Choose the command line interface for Firenvim. Options include 'neovim' for Neovim's built-in command line, 'firenvim' for Firenvim's own command line, or 'none' to disable it. ```lua vim.g.firenvim_config.localSettings['.*'] = { cmdline = 'firenvim' } ``` -------------------------------- ### Default Firenvim Global and Local Settings Source: https://github.com/glacambre/firenvim/blob/master/README.md Define the default Firenvim configuration object, including global settings and local settings with a catch-all pattern. This sets the 'cmdline', 'content', 'priority', 'selector', and 'takeover' options for all websites. ```lua vim.g.firenvim_config = { globalSettings = { alt = "all" }, localSettings = { ['.*'] = { cmdline = "neovim", content = "text", priority = 0, selector = "textarea", takeover = "always" } } } ``` -------------------------------- ### Test Firenvim Script Execution Source: https://github.com/glacambre/firenvim/blob/master/TROUBLESHOOTING.md Execute the Firenvim script with sample input to verify its functionality and output format. This helps confirm the script is created and executable. ```sh echo 'abcde{}' | ${XDG_DATA_HOME:-${HOME}/.local/share}/firenvim/firenvim ``` -------------------------------- ### Configure Firenvim Local Settings (Vimscript) Source: https://github.com/glacambre/firenvim/wiki/Broken-Websites Use this Vimscript configuration to define local settings for Firenvim, including selectors for text input elements and takeover priorities for specific websites. ```vim g:firenvim_config = { \ 'localSettings': { \ '.*': { \ 'cmdline': 'firenvim', \ 'priority': 0, \ 'selector': 'textarea:not([readonly]):not([class="handsontableInput"]), \ 'takeover': 'always', \ }, \ '.*notion.so.*': { 'priority': 9, 'takeover': 'never', }, \ '.*docs.google.com.*': { 'priority': 9, 'takeover': 'never', }, \ } } ``` -------------------------------- ### Configure Firenvim Takeover Setting Source: https://github.com/glacambre/firenvim/blob/master/README.md Set the 'takeover' behavior for Firenvim. Use 'always' to always take over elements, 'empty' for only empty elements, 'never' to disable automatic takeover, 'nonempty' for non-empty elements, or 'once' for the first interaction. ```lua vim.g.firenvim_config.localSettings['.*'] = { takeover = 'always' } ``` -------------------------------- ### Configure Firenvim Content Fetching Source: https://github.com/glacambre/firenvim/blob/master/README.md Control how Firenvim reads element content. Set to 'html' to fetch content as HTML or 'text' for plaintext. The default is 'text'. ```lua vim.g.firenvim_config.localSettings['.*'] = { content = 'html' } ``` -------------------------------- ### Configure Firenvim Local Settings (Lua) Source: https://github.com/glacambre/firenvim/wiki/Broken-Websites This Lua configuration achieves the same goal as the Vimscript version, allowing fine-grained control over Firenvim's behavior on specific websites by defining local settings and selectors. ```lua vim.g.firenvim_config = { localSettings = { [ [[.*]] ] = { cmdline = 'firenvim', priority = 0, selector = 'textarea:not([readonly]):not([class="handsontableInput"]), takeover = 'always', }, [ [[.*notion.so.*]] ] = { priority = 9, takeover = 'never', }, [ [[.*docs.google.com.*]] ] = { priority = 9, takeover = 'never', }, }, } ``` -------------------------------- ### Configure CodeMirror with HTML Mode Source: https://github.com/glacambre/firenvim/blob/master/tests/pages/codemirror.html Creates a CodeMirror instance from a textarea, configuring it for HTML mode with line numbers and bracket matching. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("demotext"), { lineNumbers: true, mode: "text/html", matchBrackets: true }); ``` -------------------------------- ### Configure Firenvim to Ignore Keys Source: https://github.com/glacambre/firenvim/blob/master/README.md Set key-value pairs in `globalSettings.ignoreKeys` to make Firenvim ignore specific key presses in Neovim modes. Use 'all' to ignore keys in all modes. Ensure correct modifier order and keyboard layout representation. ```lua vim.g.firenvim_config = { globalSettings = { ignoreKeys = { all = { '' }, normal = { '', '' } } } } ``` -------------------------------- ### Set Filetype for GitHub Buffers Source: https://github.com/glacambre/firenvim/blob/master/README.md Configure an autocommand to set the filetype to markdown for buffers matching the GitHub domain pattern. This demonstrates how to apply specific settings based on buffer names derived from URLs. ```lua vim.api.nvim_create_autocmd({'BufEnter'}, { pattern = "github.com_*.txt", command = "set filetype=markdown" }) ``` -------------------------------- ### Redirect Neovim Stderr for Debugging Source: https://github.com/glacambre/firenvim/blob/master/TROUBLESHOOTING.md Append this to the exec line in the Firenvim script to redirect Neovim's stderr to a file for debugging init.vim issues. This is an alternative to using `echo` or `echom` before Firenvim is loaded. ```sh 2>>/tmp/stderr | tee -a /tmp/stdout ``` -------------------------------- ### Set Filetype for Websites Source: https://github.com/glacambre/firenvim/wiki/Filetypes-for-websites-&-more Automatically sets the filetype based on the buffer's filename, which often contains the website domain. Useful for applying syntax highlighting and editor features specific to content from sites like GitHub, Kaggle, or Stack Exchange. ```vim let l:bufname=expand('%:t') if l:bufname =~? 'github.com' set ft=markdown elseif l:bufname =~? 'cocalc.com' || l:bufname =~? 'kaggleusercontent.com' set ft=python elseif l:bufname =~? 'localhost' " Jupyter notebooks don't have any more specific buffer information. " If you use some other locally hosted app you want editing function in, set it here. set ft=python elseif l:bufname =~? 'reddit.com' set ft=markdown elseif l:bufname =~? 'stackexchange.com' || l:bufname =~? 'stackoverflow.com' set ft=markdown elseif l:bufname =~? 'slack.com' || l:bufname =~? 'gitter.com' set ft=markdown endif ``` -------------------------------- ### Configure Firenvim Keybinding Behavior Source: https://github.com/glacambre/firenvim/blob/master/README.md Control how Firenvim handles specific keybindings that may conflict with browser defaults. Set keybindings to 'noop' to prevent Firenvim from intercepting them, or 'default' to allow Firenvim to emulate the browser's default behavior. ```lua vim.g.firenvim_config = { globalSettings = { [''] = 'noop', [''] = 'default' } } ``` -------------------------------- ### Detect Firenvim Connection with UIEnter Autocmd Source: https://github.com/glacambre/firenvim/blob/master/README.md Use the UIEnter autocmd event to detect when Firenvim connects to Neovim. This allows for dynamic configuration changes, such as setting the laststatus option, specifically when Firenvim is active. ```lua vim.api.nvim_create_autocmd({'UIEnter'}, { callback = function(event) local client = vim.api.nvim_get_chan_info(vim.v.event.chan).client if client ~= nil and client.name == "Firenvim" then vim.o.laststatus = 0 end end }) ``` -------------------------------- ### Set Firenvim PATH with Prologue Source: https://github.com/glacambre/firenvim/blob/master/TROUBLESHOOTING.md Use this command to set the correct PATH for Firenvim if it differs from your shell's PATH. This command sets the PATH in stone and requires re-running to update. ```sh nvim --headless -c "call firenvim#install(0, 'export PATH="$PATH"')" -c quit ``` -------------------------------- ### Send Key Events to Webpage Input Source: https://github.com/glacambre/firenvim/blob/master/README.md Use `firenvim#press_keys()` to send key events to the underlying input field. This function takes a list of vim-like keys. Note that it triggers an event rather than adding text. Special handling is needed for keys like `` to be typed literally using `CR>`. ```lua vim.api.nvim_create_autocmd({'BufEnter', { pattern = "riot.im_*", command = [[inoremap :w:call firenvim#press_keys("CR>")ggdGa]], }) ``` -------------------------------- ### Configure Firenvim Filename Format Source: https://github.com/glacambre/firenvim/blob/master/README.md Customize the filename format used by Firenvim. This setting supports placeholders like hostname, pathname, selector, timestamp, and extension, with optional length limits specified as percentages. The default format is provided for reference. ```lua vim.g.firenvim_config = { localSettings = { ['.*'] = { filename = '/tmp/{hostname}_{pathname%10}.{extension}' } } } ``` -------------------------------- ### Configure Firenvim Message Timeout Source: https://github.com/glacambre/firenvim/blob/master/README.md Set a timeout in milliseconds to automatically hide the external command line if Neovim fails to send a stop message. This prevents the command line from remaining visible indefinitely. ```lua vim.g.firenvim_config = { globalSettings = { cmdlineTimeout = 3000 } } ``` -------------------------------- ### Automatically Sync Changes with BufWrite Source: https://github.com/glacambre/firenvim/blob/master/README.md Configure Firenvim to automatically synchronize buffer changes to the page by using the BufWrite event. This ensures all modifications are written to the page upon saving. ```lua vim.api.nvim_create_autocmd({'TextChanged', 'TextChangedI'}, { nested = true, command = "write" }) ``` -------------------------------- ### Throttle Buffer Writes with Timer Source: https://github.com/glacambre/firenvim/blob/master/README.md Implement a throttled approach for synchronizing buffer changes to prevent performance issues with large buffers. This uses a timer to limit write operations to once every 10 seconds. ```lua vim.api.nvim_create_autocmd({'TextChanged', 'TextChangedI'}, { callback = function(e) if vim.g.timer_started == true then return end vim.g.timer_started = true vim.fn.timer_start(10000, function() vim.g.timer_started = false vim.cmd('silent write') end) end }) ``` -------------------------------- ### Execute JavaScript in the Page with Firenvim Source: https://github.com/glacambre/firenvim/blob/master/README.md Use `firenvim#eval_js` to execute a JavaScript expression in the current web page. The code must be a valid JavaScript expression, not a statement. A function can be provided to process the expression's result. Note that Content Security Policy (CSP) may prevent evaluation. ```lua vim.fn['firenvim#eval_js']('alert("Hello World!")', 'MyFunction') ``` -------------------------------- ### Handle Key Events in Textarea Source: https://github.com/glacambre/firenvim/blob/master/tests/pages/chat.html Attaches a keyup event listener to the textarea to detect specific key presses and combinations (Ctrl+Enter, Ctrl+A, 'b', Space) and appends corresponding text to the textarea's value. Ensures the textarea remains focused. ```javascript addEventListener("load", () => { const textarea = document.getElementById("content-input"); textarea.addEventListener("keyup", (e) => { if (e.key === "Enter" && e.ctrlKey && e.keyCode === 13) { textarea.value += " pressed!"; } else if (e.key === "A" && e.ctrlKey) { textarea.value += " pressed!"; } else if (e.key === "b" && !e.ctrlKey) { textarea.value += "b pressed!"; } else if (e.key === " " && !e.ctrlKey) { textarea.value += "Space pressed!"; } textarea.focus(); }); }); ``` -------------------------------- ### Default Firenvim Selector for Textareas and Textboxes Source: https://github.com/glacambre/firenvim/blob/master/README.md Configure the default CSS selector for Firenvim to target textareas (excluding readonly ones) and divs with the role 'textbox'. This defines the elements Firenvim will automatically attempt to control. ```lua vim.g.firenvim_config.localSettings['.*'] = { selector = 'textarea:not([readonly], [aria-readonly]), div[role="textbox"]' } ``` -------------------------------- ### Insert Textarea Button Source: https://github.com/glacambre/firenvim/blob/master/tests/pages/dynamic.html Adds a button that creates and appends a new textarea element to the document body, then focuses it. ```javascript const btn = document.getElementById("insert-textarea"); btn.addEventListener("click", () => { const textarea = document.createElement("textarea"); document.body.appendChild(textarea); textarea.focus(); }); ``` -------------------------------- ### Configure macOS Alt Key Behavior Source: https://github.com/glacambre/firenvim/blob/master/README.md Adjust how Firenvim handles the 'alt' key on macOS. By default, it drops the alt key for non-alphanumeric characters to avoid issues with special characters. Set 'alt' to 'all' to forward all alt key events. ```lua vim.g.firenvim_config.globalSettings.alt = 'all' ``` -------------------------------- ### Insert Textarea Dynamically Source: https://github.com/glacambre/firenvim/blob/master/tests/pages/dynamic_nested.html Attaches an event listener to a button to create and append a new div containing a textarea to the document body when clicked. The textarea is then focused. ```javascript const btn = document.getElementById("insert-textarea"); btn.addEventListener("click", () => { const div = document.createElement("div"); const textarea = document.createElement("textarea"); div.appendChild(textarea); document.body.appendChild(div); textarea.focus(); }); ``` -------------------------------- ### Hide Firenvim Frame Source: https://github.com/glacambre/firenvim/blob/master/README.md Map a key to `firenvim#hide_frame()` to temporarily hide the Firenvim frame. The frame can be brought back by unfocusing and refocusing the textarea or manually triggering Firenvim. ```lua vim.api.nvim_set_keymap("n", "", "call firenvim#hide_frame()", {}) ``` -------------------------------- ### Observe DOM Mutations and Remove Nodes Source: https://github.com/glacambre/firenvim/blob/master/tests/pages/disappearing.html This JavaScript code sets up a MutationObserver to watch for changes in the document's body. When new nodes are added, it immediately removes them and disconnects the observer. This is useful for testing scenarios where elements should not persist on the page. ```javascript window.addEventListener("load", () => { const observer = new MutationObserver((mutations, observer) => { let removed = false; for (const mutation of mutations) { for (let node of mutation.addedNodes) { node.remove(); removed = true; } } if (removed) { observer.disconnect(); } }); observer.observe(document.body, { childList: true, subtree: true }); }); ``` -------------------------------- ### Resize Textarea Rows and Columns Source: https://github.com/glacambre/firenvim/blob/master/tests/pages/resize.html Attaches a click event listener to a button that halves the 'rows' and 'cols' attributes of a textarea element when clicked. Ensure the button and textarea elements with the specified IDs exist on the page. ```javascript const button = document.getElementById("button"); button.addEventListener("click", evt => { const textarea = document.getElementById("content-input"); textarea.rows /= 2; textarea.cols /= 2; }); ``` -------------------------------- ### Exclude Elements with Specific Class from Firenvim Source: https://github.com/glacambre/firenvim/blob/master/README.md Customize the Firenvim selector using the CSS :not() pseudo-selector to exclude elements with a specific class attribute. This allows fine-grained control over which elements Firenvim should take over. ```lua vim.g.firenvim_config.localSettings['.*'] = { selector = 'textarea:not([class=xxx])' } ``` -------------------------------- ### Restrict Firenvim to Simple Textareas Source: https://github.com/glacambre/firenvim/blob/master/README.md Modify the Firenvim selector to only target simple textarea elements. This configuration excludes rich text editors and other complex elements, ensuring Firenvim only activates on basic text input fields. ```lua vim.g.firenvim_config.localSettings['.*'] = { selector = 'textarea' } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.