lukas-reineke / indent-blankline.nvim

Indent guides for Neovim
MIT License
4.17k stars 102 forks source link

Question: Auto refresh in split window #610

Closed Ursescu closed 1 year ago

Ursescu commented 1 year ago

Hello,

Problem that I am facing: Having vertical split with another buffer with a file opened. File is changed outside NVIM, NVIM will reload the file and update the buffer, but indents will not auto-updated, but only when cursor is moved in that window.

Question: Is it possible to auto-refresh that buffer?

I tried to read the README and the possible options to give for plugin setup, I couldn't find anything that would solve my issue.

My configuration (very basic):

    require('indent_blankline').setup({
        show_current_context = true,
        show_current_context_start = false,
        space_char_blankline = " ",
    })
lukas-reineke commented 1 year ago

That should work out of the box. Can you write down the steps and config to reproduce this?

Ursescu commented 1 year ago

Minimal configuration (in my env) that I can do: init.lua

require('defaults')
require('plugins').setup()

lua/defaults.lua:

local opt = vim.opt
local cmd = vim.cmd
local wo = vim.wo

vim.g.zoomwintab_hidetabbar = 0

vim.bo.expandtab = true
opt.expandtab = true
opt.ts = 4
opt.sw = 4
opt.number = true
opt.showcmd = true
opt.laststatus = 2
opt.incsearch = true
opt.ignorecase = true
opt.smartcase = true
opt.number = true
opt.relativenumber = true
opt.jumpoptions = 'stack'
wo.wrap = false
cmd([[set listchars=tab:-->,extends:>,precedes:<,space:·]])
wo.list = true
opt.scrolloff = 8
opt.sidescrolloff = 8
opt.splitright = true
opt.swapfile = false
opt.backup = false
opt.termguicolors = true
opt.fixeol = false
opt.title = true
cmd("set titlestring=NVIM:\\ %{substitute(getcwd(),\\ $HOME,\\ '~',\\ '')}")

-- CMP Setup
opt.completeopt = { 'menu', 'menuone', 'noselect' }

-- Auto-session
opt.sessionoptions = 'blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal,localoptions'

-- Set nvim
vim.g.python3_host_prog = os.getenv('HOME') .. '/.pyenv/versions/py3nvim/bin/python'
vim.g.loaded_perl_provider = 0

-- cmd('colorscheme tokyonight-night')

lua/plugins.lua:

local M = {}

function M.setup()
    -- Indicate first time installation
    local packer_bootstrap = false

    -- packer.nvim configuration
    local conf = {
        profile = {
            enable = true,
            threshold = 0, -- the amount in ms that a plugins load time must be over for it to be included in the profile
        },
        display = {
            open_fn = function()
                return require('packer.util').float { border = 'rounded' }
            end,
        },
    }

    -- Check if packer.nvim is installed
    -- Run PackerCompile if there are changes in this file
    local function packer_init()
        local fn = vim.fn
        local install_path = fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim'
        if fn.empty(fn.glob(install_path)) > 0 then
            packer_bootstrap = fn.system {
                'git',
                'clone',
                '--depth',
                '1',
                'https://github.com/wbthomason/packer.nvim',
                install_path,
            }
            vim.cmd [[packadd packer.nvim]]
        end

        -- Run PackerCompile if there are changes in this file
        -- vim.cmd 'autocmd BufWritePost plugins.lua source <afile> | PackerCompile'
        local packer_grp = vim.api.nvim_create_augroup('packer_user_config', { clear = true })
        --        vim.api.nvim_create_autocmd(
        --            { 'BufWritePost' },
        --            { pattern = 'init.lua', command = 'source <afile> | PackerCompile', group = packer_grp }
        --        )
    end

    -- Plugins
    local function plugins(use)
        -- Packer itself
        use 'wbthomason/packer.nvim'
        use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate',
            config = function()
                require('config.nvim-treesitter').setup()
            end
        }
        use {
            'lukas-reineke/indent-blankline.nvim',
            config = function()
                require('config.indent').setup()
            end
        }
        -- Bootstrap Neovim
        if packer_bootstrap then
            print 'Neovim restart is required after installation!'
            require('packer').sync()
        end
    end

    -- Init and start packer
    packer_init()
    local packer = require 'packer'

    -- Performance
    -- pcall(require, 'impatient')
    -- pcall(require, 'packer_compiled')

    packer.init(conf)
    packer.startup(plugins)
end

return M

lua/config/indent.lua (setup called from plugins.lua):

local M = {}

function M.setup()
    require('indent_blankline').setup({
        show_current_context = true,
        show_current_context_start = false,
        space_char_blankline = " ",
    })
end

-- M.setup()
return M

Experiment: First step, opening the files:

Second step, edit init.lua file from VIM:

Focus right window in NVIM:

Ursescu commented 1 year ago

Special configuration with tokyonight colorscheme it's really messy (not sure if this is related):

lukas-reineke commented 1 year ago

Sorry, I still can't reproduce it. It works fine for me.

Can you check if version 3 has the same issue? Version 3 is not released yet, but you can try it with the v3 branch https://github.com/lukas-reineke/indent-blankline.nvim/tree/v3

The setup call is

require"ibl".setup()
Ursescu commented 1 year ago

Hello, I am surprised that on your side working fine.. I tried V3 branch but now it's even weirder, it's not updating when moving the cursor right for example, only updates it when I lift my finger off the key.

https://github.com/lukas-reineke/indent-blankline.nvim/assets/15110622/be1eeefa-ae3e-44e0-8879-e9c557cfdbc0

lukas-reineke commented 1 year ago

only updates it when I lift my finger off the key.

This was done for performance, but I agree with horizontal scrolling this is weird. I pushed a fix for that. But this is unrelated to the original issue.

Ursescu commented 1 year ago

Not sure what changed, but after reverting from V3 to original, now it works OK... I tested with your latest patch, it seems fine, the only thing I didn't like (didn't know if can configure) was that nested indents were not shown like this: image

Anyway thanks for this amazing plugin, you may close the issue if there is nothing else to test.

lukas-reineke commented 1 year ago

but after reverting from V3 to original, now it works OK

Great! V3 handles different buffer refresh much better. V2 should have handled this is well, but it's very possible there is a bug somewhere I can't easily reproduce.

If you want to use v3 right now, please be aware it is still not 100% stable. Things might break over the next couple of weeks until it is released.

If you find anything else wrong, please open another issue.

indents were not shown like this

You can configure this, take a look at :help ibl.config.indent.smart_indent_cap