Coder Social home page Coder Social logo

Comments (7)

clason avatar clason commented on September 27, 2024 1

If there are no spaces in the 'commentstring', there will be no spaces in the comment.

This is intentional. Feel free to contact the filetype plugin maintainers to change this in Vim.

from neovim.

clason avatar clason commented on September 27, 2024 1

When considered from the user's perspective.

That is not the only relevant perspective, though, and this was chosen as a deliberate compromise.

I understand that the filetype plugin is managed by another people and there is nothing you can do about it.

But you (who clearly care about this) can: contact the maintainer and ask them to add spaces. If they do, the changes will end up here and make you happy.

from neovim.

BoltsJ avatar BoltsJ commented on September 27, 2024 1

FWIW, the built in Vim comment plugin puts in the spaces, so nvim's behavior here differs from upstream Vim.

from neovim.

umlx5h avatar umlx5h commented on September 27, 2024

Okay, I'll use another plugin since it doesn't seem to solve the problem.
I just don't think it is appropriate as the default behavior.

from neovim.

clason avatar clason commented on September 27, 2024

It is exactly because it's default behavior that this is appropriate. It's supposed to be a minimal implementation leveraging existing builtin functionality, not being a VS Code kitchen sink. And, yes, using a more full-featured plugin because you need the additional functionality is perfectly fine (and also intended use).

from neovim.

umlx5h avatar umlx5h commented on September 27, 2024

It is exactly because it's default behavior that this is appropriate.

it may be appropriate in terms of implementation, but it is not appropriate when looking at just the function of commenting. When considered from the user's perspective.

VSCode is just an example of this. If you know an editor that does not use spaces, please let me know.

I understand that the filetype plugin is managed by another people and there is nothing you can do about it.

from neovim.

mkalinski avatar mkalinski commented on September 27, 2024

In case someone finds this having the same issue: if you want to have spaces in commentstring for every filetype without having to contact maintainers for every odd ftplugin, it can be done quite easily with an autocommand:

vim.api.nvim_create_autocmd('FileType', {
    group = vim.api.nvim_create_augroup('commentstring_fix', {}),
    callback = function(ctx)
        local cms_value = vim.api.nvim_get_option_value(
            'commentstring',
            {buf = ctx.buf}
        )

        -- Note that this is the literal '%s'.
        -- All other '%s' in this function are patterns.
        local s_start, s_end = string.find(cms_value, '%s', 1, true)

        if s_start == nil then
            return
        end

        local s_before = s_start - 1
        local s_after = s_end + 1
        local s_prepend = ''
        local s_append = ''

        if s_start > 1
            and string.find(
                string.sub(cms_value, s_before, s_before),
                '%s'
            ) == nil
        then
            s_prepend = ' '
        end

        if s_end < #cms_value
            and string.find(
                string.sub(cms_value, s_after, s_after),
                '%s'
            ) == nil
        then
            s_append = ' '
        end

        if s_prepend ~= '' or s_append ~= '' then
            vim.api.nvim_set_option_value(
                'commentstring',
                table.concat{
                    string.sub(cms_value, 1, s_before),
                    s_prepend,
                    '%s',
                    s_append,
                    string.sub(cms_value, s_after)
                },
                {buf = ctx.buf}
            )
        end
    end
})

from neovim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.