Turn your browser into a Neovim client.
Just click on any textarea and it will be immediately replaced by an instance of Firenvim. When you want to set the content of the now hidden textarea to the content of the Neovim instance, just :w
. If you want to close the Firenvim overlay and return to the textarea run :q
. If you selected an element where you expected the Firenvim frame to appear and it didn't, try pressing <C-e>
.
Before installing anything please read SECURITY.md and make sure you're okay with everything mentioned. In the event you think of a way to compromise Firenvim, please send me an email (you can find my address in my commits).
-
Make sure you are using Neovim 0.4.0 or later. This plugin will not work with vanilla VIM or Vimr.
-
Check if the luabitop package is available by running
:lua bit.band(1,1)
in Neovim. If this throws an error, you will need to install it. -
Install Firenvim as a VIM plugin as you would any other, then run the built in post-install hook script.
-
Plug 'glacambre/firenvim', { 'do': { _ -> firenvim#install(0) } }
-
call dein#add('glacambre/firenvim', { 'hook_post_update': { _ -> firenvim#install(0) } })
-
call minpac#add('glacambre/firenvim', { 'do': { _ -> firenvim#install(0) } })
-
Install the plugin as you usually would, then run this shell command:
$ nvim --headless "+call firenvim#install(0) | q"
-
-
Finally install Firenvim in your browser from Mozilla's store or Google's.
Installing from source requires NodeJS, npm
, and Neovim >= 0.4.
First, install Firenvim like a regular vim plugin (either by changing your runtime path manually or by using your favourite plugin manager).
Then, run the following commands:
git clone https://git.sr.ht/~glacambre/firenvim
cd firenvim
npm install
npm run build
npm run install_manifests
These commands should create three directories: target/chrome
, target/firefox
and target/xpi
.
Go to about:addons
, click on the cog icon and select install addon from file
(note: this might require setting xpinstall.signatures.required
to false in about:config
).
Go to chrome://extensions
, enable "Developer mode", click on Load unpacked
and select the target/chrome
directory.
Other browsers aren't supported for now. Opera, Vivaldi and other Chromium-based browsers should however work just like in Chromium and have similar install steps. Brave and Edge might work, Safari doesn't (it doesn't support Webextensions).
Firenvim currently requires the following permissions for the following reasons:
- Access your data for all websites: this is necessary in order to be able to append elements (= the neovim iframe) to the DOM.
- Exchange messages with programs other than Firefox: this is necessary in order to be able to start neovim instances.
- Access browser tabs: This is required in order to find out what the currently active tab is.
You can configure the keybinding to manually trigger Firenvim (<C-e>
by default) in the shortcuts menu in about://addons
on Firefox, or in chrome://extensions/shortcuts
on Chrome.
Temporarily disabling (and re-enabling) Firenvim in a tab can be done either by clicking on the firenvim button next to the urlbar or by configuring a browser shortcut (see the previous section to find out how browser shortcuts can be configured).
The rest of Firenvim is configured by creating a variable named g:firenvim_config
in your init.vim. This variable is a dictionary containing the key "localSettings". g:firenvim_config["localSettings"]
is a dictionary the keys of which have to be a Javascript pattern matching a URL and the values of which are dictionaries containing settings that apply for all URLs matched by the Javascript pattern. When multiple patterns match a same URL, the pattern with the highest "priority" value is used.
Here's an example g:firenvim_config
that matches the default configuration:
let g:firenvim_config = {
\ 'localSettings': {
\ '.*': {
\ 'selector': 'textarea, div[role="textbox"]',
\ 'priority': 0,
\ 'takeover': 'always',
\ }
\ }
\ }
This means that for all URLs (".*
"), textareas will be turned into Firenvim instances. Here's an example that will make Firenvim not take over any elements, except for Github's textareas:
let g:firenvim_config = {
\ 'localSettings': {
\ '.*': { 'selector': '', 'priority': 0, },
\ 'github\.com': { 'selector': 'textarea', 'priority': 1 },
\ }
\ }
Note that even with this config, manually triggering Firenvim will still work on every page.
Firenvim has a setting named takeover
that can be set to always
, empty
or once
. When set to always
, firenvim will always take over elements for you. When set to empty
, firenvim will only take over empty elements. When set to once
, Firenvim will take over elements the first time you select them, which means that after :q
'ing firenvim, you'll have to manually trigger it to make it appear again. Here's how to use the takeover
setting:
let g:firenvim_config = {
\ 'localSettings': {
\ '.*': { 'takeover': 'empty' }
\ }
\ }
Since Firenvim just uses the BufWrite event in order to detect when it needs to write neovim's buffers to the page, Firenvim can be made to automatically synchronize all changes like this:
au TextChanged * ++nested write
au TextChangedI * ++nested write
Depending on how large the edited buffer is, this could be a little slow. A better approach would then be to delay writes, like this:
let g:dont_write = v:false
function! My_Write(timer) abort
let g:dont_write = v:false
write
endfunction
function! Delay_My_Write() abort
if g:dont_write
return
end
let g:dont_write = v:true
call timer_start(10000, 'My_Write')
endfunction
au TextChanged * ++nested call Delay_My_Write()
au TextChangedI * ++nested call Delay_My_Write()
You can move focus from the editor back to the page or the input field by calling firenvim#focus_page
or firenvim#focus_input
. Here's an example that does exactly this if you press <Esc>
twice while in normal mode:
nnoremap <Esc><Esc> :call firenvim#focus_page()<CR>
There is also a function named firenvim#hide_frame()
which will temporarily hide the firenvim frame. You will then be able to bring the neovim frame back either by unfocusing and refocusing the textarea or by using the keybinding to manually trigger firenvim.
nnoremap <C-z> :call firenvim#hide_frame()<CR>
A function named firenvim#press_keys()
will allow you to send key events to the underlying input field by taking a list of vim-like keys (e.g. a
, <CR>
, <Space>
…) as argument. Note that this only "triggers" an event, it does not add text to the input field. It can be useful with chat apps, if used like this:
au BufEnter riot.im_* inoremap <CR> <Esc>:w<CR>:call firenvim#press_keys("<LT>CR>")<CR>ggdGa
Known Issues: some chat apps do not react to firenvim#press_keys (e.g. Slack). Others steal focus from the neovim frame (e.g. Riot.im).
You can chose to use an external command line (and thus save a line of space) by setting the localSetting named cmdline
to firenvim
:
let g:firenvim_config = {
\ 'localSettings': {
\ '.*': { 'cmdline' : 'firenvim' }
\}
\}
On OSX, on certain layouts (e.g. the swedish layout), pressing special characters (e.g. @
) requires combining Alt
and another key. Because of browser/OS limitations, it is impossible to tell the difference between a user trying to press <A-@>
and just @
. Because of that, on OSX, Firenvim decides to ignore the Alt key when you press any non-alphanumerical key. This behavior can be changed by setting the alt
setting of the globalSettings
configuration to all
, like this:
let g:firenvim_config = {
\ "globalSettings": {
\ "alt": "all"
\}
\}
Non-OSX users can get the default OSX behavior by setting the alt
setting to alphanum
(but they shouldn't ever need to do that).
When it starts Neovim, Firenvim sets the variable g:started_by_firenvim
which you can check to run different code in your init.vim. For example:
if exists('g:started_by_firenvim')
set laststatus=0
else
set laststatus=2
endif
Alternatively, you can detect Firenvim using the UIEnter
autocmd event:
function! s:IsFirenvimActive(event) abort
if !exists('*nvim_get_chan_info')
return 0
endif
let l:ui = nvim_get_chan_info(a:event.chan)
return has_key(l:ui, 'client') && has_key(l:ui.client, "name") &&
\ l:ui.client.name is# "Firenvim"
endfunction
function! OnUIEnter(event) abort
if s:IsFirenvimActive(a:event)
set laststatus=0
endif
endfunction
autocmd UIEnter * call OnUIEnter(deepcopy(v:event))
Similarly, you can detect when Firenvim disconnects from a Neovim instance with the UILeave
autocommand.
If you want to use different settings depending on the textarea you're currently editing, you can use autocommands to do that too. All buffers are named like this: domainname_page_selector.txt
(see the toFileName function). This means that you can for example set the file type to markdown for all GitHub buffers:
au BufEnter github.com_*.txt set filetype=markdown
The main issue with Firenvim is that some keybindings (e.g. <C-w>
) are not overridable. I circumvent this issue by running a patched version of Firefox.
- Tridactyl, provides vim-like keybindings to use Firefox. Also lets you edit input fields and text areas in your favourite editor with its
:editor
command. - GhostText, lets you edit text areas in your editor with a single click. Requires installing a plugin in your editor too. Features live updates!
- Textern, a Firefox addon that lets you edit text areas in your editor without requiring you to install a plugin in your editor.
- withExEditor, same thing as Textern, except you can also edit/view a page's source with your editor.