Nvim-tree.lua: nowrap for luatree buffer only

Created on 17 Nov 2020  路  10Comments  路  Source: kyazdani42/nvim-tree.lua

The change in https://github.com/kyazdani42/nvim-tree.lua/commit/0602058af5a40e5c0cd4c1eda2e780627538dfd6 sets nowrap for the window, which affects all buffers in that window, not just luatree. But I do want wrap for my other buffers.

help doc says wrap is a window scoped option, I guess why the above commit used the function vim.api.nvim_win_set_option. But I'm able to set wrap for the luatree buffer only with the following autocmd:

autocmd FileType LuaTree setlocal nowrap

Not sure how to replicate this with neovim's lua api. Maybe just vim.api.nvim_command('setlocal nowrap')?

Most helpful comment

vim.wo[tree.winnr].wrap = false

@kyazdani42
I tried it ,it works.
And the reason why api.nvim_win_set_option(tree.winnr, 'wrap', false) didn't work, is because tree.winnr is a function that returns winnr, so it should be api.nvim_win_set_option(tree.winnr(), 'wrap', false).

I've made a PR to fix this

All 10 comments

well i agree this is strange indeed. I really don't like window options it's a pain every time because they follow the window options set from their opening parent.
I wonder if you'd set wrap in you vimrc, would this still be an issue ?

well i agree this is strange indeed. I really don't like window options it's a pain every time because they follow the window options set from their opening parent.
I wonder if you'd set wrap in you vimrc, would this still be an issue ?

setting wrap in vimrc doesn't work.
I think the problem is that the draw function in renderer.lua keeps setting wrap to false with api.nvim_win_set_option(tree.winnr, 'wrap', false).

Isn't this a neovim issue ? Setting the option to the window shouldn't set the option to all windows right ?

Isn't this a neovim issue ? Setting the option to the window shouldn't set the option to all windows right ?

no, nvim_win_set_option is just doing what it's supposed to do. Setting an option at window level should affect all splits in that window.

I often open lua tree in the left split and write code in the right split. So I hope luatree don't set the wrap option at window level.

The solution in my mind is this:

  1. delete the line api.nvim_win_set_option(tree.winnr, 'wrap', false) in renderer.lua,
  2. add an auto command such as autocmd FileType LuaTree setlocal nowrap somewhere

This way it will only affect the luatree split

maybe using vim.wo[tree.winnr].wrap = false would work ? Could you try it and tell if this fixes your issue ?

maybe using vim.wo[tree.winnr].wrap = false would work ? Could you try it and tell if this fixes your issue ?

I don't think this will work.
It still set wrap at window level, which affects all splits in that window.

@smartding that's not quire right. If you create a split then both buffers are in windows, i.e. each split is a window. The "container" above a window is a tabpage.

|                     |                     |
|     window 1        |         window 2    |
|                     |                     |
|                     |                     |
|                     |                     |

@smartding that's not quire right. If you create a split then both _buffers_ are in _windows_, i.e. each split _is_ a window. The "container" above a window is a tabpage.

|                     |                     |
|     window 1        |         window 2    |
|                     |                     |
|                     |                     |
|                     |                     |

So conceptually, it's tab > window ? I thought it's tab > window > split window

vim.wo[tree.winnr].wrap = false

@kyazdani42
I tried it ,it works.
And the reason why api.nvim_win_set_option(tree.winnr, 'wrap', false) didn't work, is because tree.winnr is a function that returns winnr, so it should be api.nvim_win_set_option(tree.winnr(), 'wrap', false).

I've made a PR to fix this

window > split window

This distinction doesn't really exist. Every window is contained inside a tab page, when you split one window into two you just create another window there isn't really a special case for split windows they are just regular windows. So that tab page goes from containing one window to containing two.

Was this page helpful?
0 / 5 - 0 ratings