glacambre / firenvim

Embed Neovim in Chrome, Firefox & others.
GNU General Public License v3.0
4.68k stars 144 forks source link

Modest proposal to enhance usability #1475

Closed cassepipe closed 1 year ago

cassepipe commented 1 year ago

Written from the comfort of a neovim instance running in my browser:

The web is full of small textboxes and the non-wrapping behaviour of neovim within the browser is a bit of a pain to me. Being able to see the most of the typed content within the available view port appears to be a resonable feature.

Soft wrap is not quite up to the task as it is quite unintuitive: You want to move the next line but you're actually on the same line! So maybe it would be reasonable to modify the local mapping of j/k and gj/gk.

There is the possibilty of setting a fixed textwidth for hardwrapping but it is quite limited: Choose to big and your text will expand, choose too low and you will feel restrained compared to your textbox's size.

Maybe we need to update the hard wrap setting dynamically.

I am interested in your take!

justinmk commented 1 year ago

you can do this in your config

if !get(g:, 'started_by_firenvim')
  ...
endif
glacambre commented 1 year ago

Choose to big and your text will expand, choose too low and you will feel restrained compared to your textbox's size.

The solution is simple: choose a value that matches your textbox's size :). For example:

function! Hardwrap()
  execute("set textwidth=" .. (winwidth(0) - 1))
endfunction
if !get(g:, 'started_by_firenvim')
  au VimResized * call Hardwrap()
  au UIEnter * call Hardwrap()
endif

It looks like Neovim doesn't have window-specific resize events, but for Firenvim this shouldn't matter as there rarely is a reason to use multiple windows. I'll close this issue but feel free to ask more questions if you need more help :).

ariel-frischer commented 1 year ago

For lua I have something like the following:

if g.started_by_firenvim then
    api.nvim_set_option("laststatus", 0)
    api.nvim_set_option("showtabline", 0)
    g.startify_disable_at_vimenter = 1
    vim.cmd "set wrap linebreak"
cassepipe commented 1 year ago

@ariel-frischer Thank you. Your solution does not really address the issue though : The problem with soft wrapping is that what you can't be sure the next line is really a line or the coninuation of the line before. This does not play well with vim commands.

Unless you are writing some code, you probably want hardwrapping.

@glacambre's solution does address that issue.