How to set comment character as double dash in front of formatted text?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to set comment character as double dash in front of formatted text?

Igor Forca
Hi,
1. I have some text in my code like:
# Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ornare vehicula ornare. Proin bibendum convallis vulputate. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nullam a convallis nisi. Praesent mollis mauris at molestie molestie.

Note: Above line starts with "#" as comment and whole text is in one line.

2. Now I set text width to 50 chars
:set textwidth=50

3. I move cursor to line of "Lorem ipsum" and execute: gqq
to format a text into multiple lines.

4. Bellow appears:
# Lorem ipsum dolor sit amet, consectetur
# adipiscing elit. Duis ornare vehicula ornare.
# Proin bibendum convallis vulputate. Pellentesque
# habitant morbi tristique senectus et netus et
# malesuada fames ac turpis egestas. Nullam a
# convallis nisi. Praesent mollis mauris at
# molestie molestie.

Notice "#" comment character is automatically
added at front of text, but text has been
reformatted into multiple lines.

5. In third row delete whole sentence, so from "Proin" to
the dot (but leave # comment in front of text).

6. Reformat whole paragraph: gqap
and bellow appears:
# Lorem ipsum dolor sit amet, consectetur
# adipiscing elit. Duis ornare vehicula ornare.
# Pellentesque habitant morbi tristique senectus
# et netus et malesuada fames ac turpis egestas.
# Nullam a convallis nisi. Praesent mollis mauris
# at molestie molestie.

Note: whole paragraph is reformatted, but #
character is automatically added as first char
in line. I can do several similar edits and
reformat and "#" comment char stays at the beginning
of row.

NOW TO THE PROBLEM:
In my coding language comment is not # but instead
double dash: --

I should probably set some setting for formatting
to tell which character is comment or similar.

Is it possible to set double dash is a comment for formatting?
Regards

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to set comment character as double dash in front of formatted text?

Tobias Klausmann
Hi!

On Tue, 10 Oct 2017, Igor Forca wrote:
> NOW TO THE PROBLEM:
> In my coding language comment is not # but instead
> double dash: --
>
> I should probably set some setting for formatting
> to tell which character is comment or similar.
>
> Is it possible to set double dash is a comment for formatting?

My suspicion is that you're editing Lua. If I do so (with
ft=lua), what you describe just works. E.g. having this:

-- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

And using gq} will result in this:

-- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
-- tempor incididunt ut labore et dolore magna aliqua.

So my suspicion is that your vim doesn't recognize what you're
editing as being Lua. What does ":set ft" return?

Regards,
Tobias


--
Sent from aboard the Culture ship
        Gravitas... Gravitas... No, Don't Help Me, I'll Get It In A Moment...

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to set comment character as double dash in front of formatted text?

Tony Mechelynck
In reply to this post by Igor Forca
On Tue, Oct 10, 2017 at 12:43 PM, Igor Forca <[hidden email]> wrote:
[...]
> NOW TO THE PROBLEM:
> In my coding language comment is not # but instead
> double dash: --
>
> I should probably set some setting for formatting
> to tell which character is comment or similar.
>
> Is it possible to set double dash is a comment for formatting?
> Regards

see :help 'comments'
see also :help filetype-plugin

Best regards,
Tony.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to set comment character as double dash in front of formatted text?

Igor Forca
@Thobias, thanks for tips, but not working in my case. Set ft returns "sql", I
am editing relational database SQL file. Manually setting it to lua (for test), and execute format command does not solve my problem.

@Tony, thanks for providing help. I have managed to solve a problem with setting:
:setlocal comments=:--
and executing format paragraph command.

But because I don't want to mess other file types (I sometimes need # as
comment when editing some bash files), I set autocommand to fire up only
for .sql file types. Final command I have written in my .vimrc is now:
:autocmd BufEnter *.sql :setlocal comments=:--

Problem solved. Thanks a lot to both of you.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to set comment character as double dash in front of formatted text?

Tony Mechelynck
On Tue, Oct 10, 2017 at 2:03 PM, Igor Forca <[hidden email]> wrote:

> @Thobias, thanks for tips, but not working in my case. Set ft returns "sql", I
> am editing relational database SQL file. Manually setting it to lua (for test), and execute format command does not solve my problem.
>
> @Tony, thanks for providing help. I have managed to solve a problem with setting:
> :setlocal comments=:--
> and executing format paragraph command.
>
> But because I don't want to mess other file types (I sometimes need # as
> comment when editing some bash files), I set autocommand to fire up only
> for .sql file types. Final command I have written in my .vimrc is now:
> :autocmd BufEnter *.sql :setlocal comments=:--
>
> Problem solved. Thanks a lot to both of you.

To avoid messing other filetypes, you could also create a filetype-plugin, named

(Unix) ~/.vim/after/ftplugin/sql.vim
(Windows) $HOME/vimfiles/after/ftplugin/sql.vim

and containing the line

setlocal comments:--

But maybe there is an already known sql dialect using this kind of
comment leader, see
    :help ft-sql.txt
    :help sql-dialects


Best regards,
Tony.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to set comment character as double dash in front of formatted text?

Christian Brabandt
In reply to this post by Igor Forca

On Di, 10 Okt 2017, Igor Forca wrote:

> @Thobias, thanks for tips, but not working in my case. Set ft returns "sql", I
> am editing relational database SQL file. Manually setting it to lua (for test), and execute format command does not solve my problem.
>
> @Tony, thanks for providing help. I have managed to solve a problem with setting:
> :setlocal comments=:--
> and executing format paragraph command.
>
> But because I don't want to mess other file types (I sometimes need # as
> comment when editing some bash files), I set autocommand to fire up only
> for .sql file types. Final command I have written in my .vimrc is now:
> :autocmd BufEnter *.sql :setlocal comments=:--
>
> Problem solved. Thanks a lot to both of you.

What vim version is this? Because I believe, if you enable filetype
plugins, setting this option is already done. Check
$VIMRUNTIME/ftplugin/sql.vim

Christian
--
Lieber zweifelhaft als pinselhaft.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.