JuliaEditorSupport / julia-vim

Vim support for Julia.
http://julialang.org/
Other
753 stars 94 forks source link

comments and multiline comments #198

Closed MarkusLohmayer closed 4 years ago

MarkusLohmayer commented 4 years ago

Hi everyone, I have a short question regarding comments in Julia files. Usually I use https://github.com/tpope/vim-commentary for (un)commenting. For some reason, julia-vim is configured in a way that it will insert #= ... =# on every line. IHMO this is not ideal and feels too heavy.

Thanks to some helpful tips I received in #vim channel on the Julia Slack, I could change the behavior. The following two solutions were presented:

  1. Putting let b:commentary_format = '# %s' in ftplugin/julia.vim
  2. Putting autocmd FileType julia setlocal commentstring=#\ %s in the vimrc.

So for me the problem is basically solved as I now just get the # ... at the beginning.

But some questions remain:

  1. Shouldn't this be the default behavior, so others also get the comment syntax they presumably expect?
  2. What was the reason to specify the multi-line comment syntax for comments in julia-vim in the first place?

Thank you very much! Markus

kdheepak commented 4 years ago

Thanks for opening the issue. I also agree that the default should be just a single # before every line.

I think this is the only line that needs to be changed.

https://github.com/JuliaEditorSupport/julia-vim/blob/2d0b6e4018d6cc01b96ab326ff6495876200866d/ftplugin/julia.vim#L17

carlobaldassi commented 4 years ago

Answers:

Shouldn't this be the default behavior, so others also get the comment syntax they presumably expect?

It's hard to predict what people would expect...

What was the reason to specify the multi-line comment syntax for comments in julia-vim in the first place?

Well, the reason is that they exist, in a sense. Also, another reason is that although it's possible in principle to specify different types of comments in comments, in practice it doesn't work well at all. So as a sort of fallback the two kind of comments are specified in those two different variables.

As for commenter plugins. vim-commentary is quite limited, I would say. But then again its README tells you exactly what you ought to do to use it with your favourite file type. Other commenting plugins such as tcomment work well because it uses comments. I'm using a small plugin that I wrote myself a long time ago (this one) which uses both comments and commentstring, and it can use the #=%s=# form with visual selections, in case you want to comment out a piece of a line, for example (but I still have to force b:smartcomment_force_linemode=1 in my vimrc).

So I don't think changing commentstring is correct.

I guess the best solution is just to add some plugin-specific tweaks in ftplugin/julia.vim.

MarkusLohmayer commented 4 years ago

Thank you very much!