nvimdev/indentmini.nvim

Overlapping content in tab indented files

Closed this issue · 7 comments

If a file that uses tabs for indentation the indent char seem to overlap some content. Please see attached screenshot

Screenshot 2023-10-14 at 00 01 35
config
require('indentmini').setup({
    char = '│',
    exclude = {
        'markdown',
    },
})

Example file from the screenshot

Expected behaviour: indent chars do not overlay file content

if using tab as indent . indentmini shouldn't work . expandtab value ?

Thank you for the reply. expandtab is set to true globally.

vim.opt.expandtab = true

turning it off for a specific buffer fixes the issue. I can add a BufEnter autocommand that would scan the buffer if it uses tabs for indentation and set exapndtab to false for this buffer only. I wonder if you would be okay adding this to your plugin? I am happy to send a PR.

I check expandtab value in there.

or not vim.bo[bufnr].expandtab

for some filetype it use tab as indent . in this situation i think this value shouldn't set to true. for me I usually config indent in after/ftplugin/xxx file like go use indent i config it like this

https://github.com/glepnir/nvim/blob/main/after/ftplugin/go.lua

Unfortunately this is not up to me, personally I use spaces for lua files, the example from the issue post is another lua plugin that I use. Also not everyone uses .editorconfig files. This is why dynamic detection can be a good thing.

For now I settled back to use leadmultispace listchar option to display indentation levels. And dynamically detect what is used for indentation in the file. This solution is not bulletproof but good enough.

local function update_listchars_for_spaces(space_count)
    local leadmultispace = space_count == 2 and '' or ''
    vim.opt.listchars = vim.tbl_extend('force', LIST_CHARS, { leadmultispace = leadmultispace })
    vim.bo.tabstop = space_count
    vim.bo.shiftwidth = space_count
end

vim.api.nvim_create_autocmd('BufReadPost', {
    pattern = { '*' },
    callback = function()
        local lines = vim.api.nvim_buf_get_lines(0, 0, 100, false)
        local tab = '\t'

        -- check if there are indented lines
        -- and set listchars accordingly
        for lnum, line in ipairs(lines) do
            if line:find('^%s') ~= nil then
                local first_char = line:sub(1, 1)
                if first_char == tab then
                    -- do not use spaces in this buffer
                    vim.bo.expandtab = false
                    return
                end
                local indent_level = vim.fn.indent(lnum)
                if indent_level == 2 then
                    return update_listchars_for_spaces(2)
                elseif indent_level == 4 then
                    return update_listchars_for_spaces(4)
                end
            end
        end

        update_listchars_for_spaces(2)
    end,
})

the example from the issue post is another lua plugin that I use.

sry i don't understand this. neovim also supports editorconfig :help editorconfig. except some project (like neovim script file which generate runtime/doc) need lua use space and tab. dynamic also better ...

No worries. The scenario where I hit a problem that motivated me to create this issue is

  1. I am editing my own dot files, all files use spaces for indentations, the plugin works as expected
  2. Within the same session I open one of the plugins source code that uses tabs for indentation and does not have an.editorconfig file

Does this help?

maybe now is fixed.