Git Product home page Git Product logo

nvim-comment's People

Contributors

b3nj5m1n avatar christopher-besch avatar danbyl avatar dedukun avatar gegoune avatar ngxingyu avatar paegodu avatar roeeyn avatar shadmansaleh avatar terrortylor avatar winston0410 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nvim-comment's Issues

Custom mapping is broken

I use the following to configure nvim-comment. After I updated today my mappings broke. I think it was caused by this commit
22f81f9

require('nvim_comment').setup({
    marker_padding = true,
    comment_empty = true
    create_mappings = true
    line_mapping = "<leader>cc",zzzzzzz
    operator_mapping = "<leader>c"
})

Support keymap for {n}gcc

I am looking that something tpope commentary plugin has where I can do 4gcc which would comment current line plus 3 more. I see there is gc4j. Maybe there is a way I could do this already and I just need to create the map myself

Add support to htmldjango files

Hi, adding a single line comments to htmldjango files was straight forward as it was explained in the docs. However, I couldn't find something to add block comment marks.

require'nvim_comment'.setup(
    {
        hook = function()
            if vim.api.nvim_buf_get_option(0, "filetype") == "htmldjango" then
                -- Assumes this is being run in the context of the filetype...
                vim.api.nvim_buf_set_option(0, "commentstring", "{# %s #}")
            end
        end
    }
)
{% comment %} 
<div>
     <p>foo</p>
</div>
{% endcomment %}

This is an example how a block comment should look like. If you point me towards the proper position in the source code, I could try adding it and creating a PR?

Context dependant comment string

Hi, is it possible to comment with different comment strings based on cursor position in multi-context files like those of Vue and React? There is Shougo/context_filetype.vim which could help with figuring out the current context, but not sure how to make it work with nvim-comment.

Wrong comment string for .nix files

When using the plugin inside .nix files, the inserted comment string is /* ... */ while it should be #.

Is it actually the job of this plugin to handle this ? Are the default commentstring values defined elsewhere ?

Thank you for your consideration.

Custom mapping

Hey again.

I have used tcomment for a long time and gotten used to <C-_><C-_> mapping. So I did set line_mapping to it

line_mapping = "<C-_><C-_>"

it works fine except for visual mode. tcomment did support that, I know there is operator_mapping but I would like to keep that set to default value.

Do you think I could somehow map <C-_><C-_> to toggle single line in normal mode and selection in visual mode too?

Thanks!

Set marker_padding dynamically

Iā€™m using padded and unpadded comments. Having a way to create mappings for each would be useful. Ideas:

  • Separate mappings, for example line_mapping_padded and line_mapping_unpadded
  • Expose a function with a marker_padding parameter that can be called in custom mappings

Allow default line commenting to /* */ for C

Hey,
currently line commenting(gcc) comments line starting with // and /* / for block commenting, I like to have / */ commenting for one line comments as well, it's also the default behavior with tpope's commentary plugin

Sub-line comments

Not all languages support this but some like C/C++/Rust support block comments that would allow you to comment text at a finer granularity than lines.

Is there any interest/work on supporting this?

Comment text objects seem not to work

Hi! I have the following nvim_comment setup:

-- Code commenting
require("nvim_comment").setup()

My full config at: https://github.com/maciejzj/dotfiles/blob/master/init.lua

I expect the default setup from nvim-comment's README to include:

-- text object mapping, comment chunk,,
comment_chunk_text_object = "ic",

The comment text objects seem not to work (at least in bash scripts and python).
When I edit a chunk of text like this:

    # Matplotlib components are oververbose < Cursor on this line
    matplotlib.pyplot.set_loglevel('info')

And type cic in normal mode I would expect to change inside comment, yet nothing really happens (nvim enters insert mode).

Versions:
NVIM v0.8.3
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@Ventura-arm64.

nim-comment@e9ac16ab056695cad6461173693069ec070d2b23

Whitespace trim doesn't work on indented blocks as expected

I have comment_empty_trim_whitespace = true but doing a simple comment/uncomment on something like this leaves the middle line with spaces when only the inner block is selected

if true then
  local foo = 1   -- visual mode from here

  foo = foo + 1  -- to here
end

If I select the whole top level statement it works, but if I comment out the middle part it does not, and leaves as many spaces as it was initially indented. This is undesirable, because at least in my experience one does not want whitespace on empty lines in indented code.

I dug into the code a bit and found that the pattern is matched, but the replacement seems wrong

function M.uncomment_line(l, left, right, comment_empty_trim_whitespace)
  local line = l
  if right and right ~= "" then
    line = line:gsub(vim.pesc(right) .. "$", "")
    return line:gsub(vim.pesc(left), "", 1)
  end

  if comment_empty_trim_whitespace and left:match("%s+$") then
    local left_nw = left:match("^(%S+)%s+$")
    if line:match("^%s*" .. left_nw .. "$") then
      print("THIS GETS PRINTED EXACTLY ONCE, BUT NO REPLACEMENT")
      return line:gsub(vim.pesc(left_nw), "", 1)
    end
  end

  return line:gsub(vim.pesc(left), "", 1)
end

Replacing

      return line:gsub(vim.pesc(left_nw), "", 1)

with

      return line:gsub("^%s*" .. vim.pesc(left_nw) .. "%s*", "", 1)

fixes it for me. I don't know much about neovim's APIs, so not sure if this is the best way to do it, but it does seem to work. Testing it even on some bigger code seems to produce the expected results.

Visual Block Modes Doesn't Comment Correct Lines

local foo = 'foo'
local bar = 'bar'
local baz = 'baz'
local foo = 'foo'
local bar = 'bar'
local baz = 'baz'
  1. Go into visual line mode on the first three lines and comment them out with gc
  2. Undo with u
  3. Go into visual block mode over all six lines and comment them out with gc

Only the first three lines will be commented out after the above steps when all 6 lines should be commented out.

Comments with no indent are not toggled

Anything with a comment that has no indent is not toggled, like this for example:

--local test = 0

Actual:

-- --local test = 0

Expected:

local test = 0

This also happens with any language with a comment that has no indent.

Nested comments

Thank you very much for your great plugin!

One thing I'm missing from tpope's plugin is how it solved nested comments. This is especially relevant for the html comments that I use in my markdown files: <!-- comment -->. The problem occurs when you have a text such as:

This is a<!-- comment --> text.

When uncommenting this it becomes:

<!--This is a<!-- comment --> text.-->

That's unexpected because the comment that begins at the beginning of the line now ends at the first -->.

Tpope's plugin solved that by converting the nested comments into <1!-- comment --1>. The text then becomes:

<!--This is a<1!-- comment --1> text.-->

This string could then of course be uncommented again as well. I'm not sure if this affects languages other than markdown.

If you think this is something that nvim-comment should know how to do, you might also want to take a look at this issue; apparently the way tpope solved it leads to some problems (though this has never affected me).

Make dot repeatable

Hi, do you think commenting, uncommenting or toggling could be made . repeatable?

line_mapping and operator_mapping with the same key mapping

I tried to assign the same mapping to line_mapping and operator_mapping, like with vim-commentary, but unfortunately this doesn't work:

require('nvim_comment').setup({
    -- Should key mappings be created
    create_mappings = true,
    -- Normal mode mapping left hand side
    line_mapping = '<leader>c',
    -- Visual/Operator mapping left hand side
    operator_mapping = '<leader>c'
})

Am I missing something or is this (currently) not possible with nvim-comment out of the box?

Maintain indents over range

Visually select and :CommentToggle over the following python test case:

def edgar(x):
    print("Once upon a midnight dreary")

Actual:

    # def edgar(x):
    # print("Once upon a midnight dreary")

Expected:

# def edgar(x):
#     print("Once upon a midnight dreary")

Can't toggle comment after format Go source

NVIM v0.5.0
Build type: Release
LuaJIT 2.1.0-beta3
File Type: Go

Before I run format source(go fmt), everything is OK. But as soon as the source is formatted, the toggling doesn't work for range operation, but works for a single line.
The go fmt will change the source format.

Screen.Recording.2021-07-20.at.4.31.10.PM.mov

Option to insert comment characters at level of indentation

Would it be possible to add an option to allow inserting comment characters at the level of indentation?

I'm moving from tpope's vim-commentary plugin and this behavior is actually default, but he offers an option to make it work like nvim-comment does now:

Assign b:commentary_startofline to insert comment characters at column 1 regardless of indentation.

gcc can not effect, :commentToggle can work.

Need other configs?

  require('nvim_comment').setup({
  -- Linters prefer comment and line to have a space in between markers
  marker_padding = true,
  -- should comment out empty or whitespace only lines
  comment_empty = true,
  -- trim empty comment whitespace
  comment_empty_trim_whitespace = true,
  -- Should key mappings be created
  create_mappings = true,
  -- Normal mode mapping left hand side
  line_mapping = "gcc",
  -- Visual/Operator mapping left hand side
  operator_mapping = "gc",
  -- text object mapping, comment chunk,,
  comment_chunk_text_object = "ic",
  -- Hook function to call before commenting takes place
  hook = nil
})

Return cursor to previous location after commenting paragraph

After toggling comments for a paragraph (or in any visual mode), I'd like to have some way of returning my cursor to the previous location. Currently, executing a comment toggle with either gcip or vip:CommentToggle<cr> appears to place the cursor at the beginning of the commented block and erase all marks within the commented block.

Here's how I can recreate this.

In my init.vim, I have the following lines.

" ff: toggle comment for current line
nnoremap <silent> ff :CommentToggle<cr>

I can place my cursor on the first "n" in "nnoremap" and create a mark by running mt. I can check that my mark exists my running :marks. I see something like so.

:marks
mark line  col file/text
mark line  col file/text
 '    321    0 " ff: toggle comment for current line.
 l    321    0 " ff: toggle comment for current line.
 p    328    0 -invalid-
 t    322   10 nnoremap <silent> ff :CommentToggle<cr>
 y    325   10 nnoremap <silent> fp mtvip:CommentToggle<cr>`t

I can then comment these two lines by running gcip. I can then run :marks again, and see that the t mark is no longer present.

:marks
mark line  col file/text
 p    328    0 -invalid-
 y    325   10 nnoremap <silent> fp mtvip:CommentToggle<cr>`t

Note that undoing the comment also recreates the mark.

So finding a way to preserve marks after block commenting would do the trick, because then I could do something like

mtvip:CommentToggle<cr>`t

to comment a paragraph and go back to my t mark.

Thanks.

cannot change cpp comment format

Hi,

I want to change the comment format of cpp file from "/*...*/" to "//...". According to README, I wrote following codes in my config file (.lua file):

vim.cmd([[
augroup usergroup
autocmd!
autocmd FileType cpp :lua vim.api.nvim_buf_set_option(0, "commentstring", "// %s")
augroup END
]])

But it didn't work at all. The comment format is still "/*...*/"

Also I don't want to do

augroup set-commentstring-ag
autocmd!
autocmd BufEnter *.cpp,*.h :lua vim.api.nvim_buf_set_option(0, "commentstring", "// %s")
" when you've changed the name of a file opened in a buffer, the file type may have changed
autocmd BufFilePost *.cpp,*.h :lua vim.api.nvim_buf_set_option(0, "commentstring", "// %s")
augroup END

as is shown in README file because cpp files can have many extensions, such as .cxx .cc .cpp or .h .hpp .hh etc.
So I would like to set commentstring based on filetype instead of file extension.

Inconsistent commenting

Thanks for this nice plugin. It surely can replace tcomment which I am currently using.

While using this plugin, I found a weird behavior while commenting. So, If some block of code has an empty line then the commenting doesn't exclude the tab width. The behavior is clearly shown in the video below.

nvim-comment.mp4

As you can see, the function below has some empty lines thus the weird commenting is happening. But the above function doesn't have empty lines, so the commenting is as expected. I also checked this behavior in typescript and this issue is also there.

Padding on right

For instance, for comments in Markdown,

<!-- actual-->
<!-- expected -->

(actual is missing a space to the right.)

Lua comments automatically duplicated to new line on Enter

When I have cursor in commented line (lua script), after pressing enter - the comment is automatically duplicated to new line like so:
obraz
Does not happen for python. Did not test with other languages.
If it could be made consistent between nanguages, and option to disable it pernamently (if it is not bug)

Allow commenting single empty lines

I thought comment_empty would enable this behaviour but it doesn't seem to do so.

In the below example, highlighting all 3 lines and running :CommentToggle has the expected result of commenting each line. If you put your cursor on line 2 (empty), however, and run :CommentToggle, no comment is created.

1  local pitaya = 'fruit'
2  
3  local carrot = 'veggie'

It would be lovely if we were able to comment a single empty line, eg. for starting a new comment instead of commenting existing text šŸ„°

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.