Vsvim: gq doesn't format text

Created on 3 Nov 2010  ·  29Comments  ·  Source: VsVim/VsVim

If you select a set of rows and press 'gq' the text isn't formatted into properly sized lines. In vim the width for the command is based on the 'textwidth' variable.

feature request

Most helpful comment

This feature would be very helpful.

All 29 comments

yeah, missed that feature, too :/

I miss it too...but love VsVim overall. :)

<voteup/> This is the number 1 feature I miss from regular vim.

(one reason I bring this up now is that vsvim has gotten so good that I frequently block-select text and type 'gq' expecting it to do something, forgetting that vsvim doesn't do it yet :))

I'll look at getting that added. Getting gq to work as a command seems relatively straight forward. Getting it to work as a consequence of inserting text will be a bit more tricky.

I was looking at this tonight and I'm questioning whether or not I have the entire story with gq. The behavior seems odd to me and I'm worried i'm missing a key part of the feature. For my experiment I set :set textwidth=2 then I ran gqq on the following text. All - below represent spaces


the result was

chases
cat

Is this the behavior you were looking for with gq. The lack of indenting seems wrong but digging through the documentation on textwidth and gq I couldn't find a way that it would be added back in.

I guess the whole story would need to include 'autoindent' and 'cindent'/'smartindent'. Here are a few different behaviour (where - denotes leading spaces):

Using gq with set ai tw=2 over --dog chases cat results in:

--chases
--cat

Or as the documentation puts it:

    When autoindent is on, formatting (with the "gq" command or when you
    reach 'textwidth' in Insert mode) uses the indentation of the first
    line.

Using gq with set cin tw=2 ft=c over --int main() { const char* test="a test"; if (test == NULL) { return 1; } return 0; } results in:

--main()
{
----const
--------char*
--------test="a
--------test";
----if
--------(test
---------==
---------NULL)
--------{
------------return
----------------1;
--------}
----return
--------0;
}

Man I must have been asleep last night. I thought I had ai on when I was testing that out but clearly I didn't. Thanks for the info!

Hey @jaredpar. Really like VsVim; it's allowing me to enjoy using Visual Studio.

Just curious; any progress on this issue?

No recent progress. I lost track of this issue trying to get the 1.4.0 release out the door (should be released later this week). This high on the list for the next release after that though

+1. Formatting documentation comments without this feature is just a plain PITA.

:+1: +1 for gq functionality!

:+1:

@jaredpar I've had a refreshed hankering for this functionality; I would particularly like to get gqq implemented. Similar to the question that I had about implementing functions, though, I feel like there enough here that there is probably need for some sort of formatter module. What do you think? Do you have any ideas here in terms of design? Honestly it sounds like a complex but fun problem to me. I am nervous about learning how to do it with Visual Studio's text objects a bit, but on the other hand, I'm drawn to the problem. (On a totally unrelated note, was this issue my first-ever appearance on VsVim's GitHub page?)

I do think something this big would need a full module. I've thought about
implementing this a few times but I quickly get lost in the details (seems
like i'd need an advanced C lexer to do it properly which usually puts me
off)

On Thu, Oct 30, 2014 at 5:44 PM, Kazark [email protected] wrote:

@jaredpar https://github.com/jaredpar I've had a refreshed hankering
for this functionality; I would particularly like to get gqq implemented.
Similar to the question that I had about implementing functions, though, I
feel like there enough here that there is probably need for some sort of
formatter module. What do you think? Do you have any ideas here in terms of
design? Honestly it sounds like a complex but fun problem to me. I am
nervous about learning how to do it with Visual Studio's text objects a
bit, but on the other hand, I'm drawn to the problem. (On a totally
unrelated note, was this issue my first-ever appearance on VsVim's GitHub
page?)


Reply to this email directly or view it on GitHub
https://github.com/jaredpar/VsVim/issues/333#issuecomment-61196315.

Jared Parsons
http://blog.paranoidcoding.com/
http://twitter.com/jaredpar

Okay, now that's really interesting, because I _never_ use this to format code, only comments or blocks of text in a plain text or Markdown file. Is it intended to be for formatting code? I don't think I even realized that! Or am I misunderstanding...? Why would you need a C lexer? Also I see you talking about set tw=2. Is that a real use-case? Honestly I'm having trouble imagining anyone setting a value between set tw=0 and set tw=60! It may be an edge case that you don't have to worry about. What do you think?

@Kazark i'm confusing it with another feature (not sure which one off hand). This particular one gets difficult around the use of formatoptions but it doesn't require anything as crazy as a C lexer

Okay, gotcha. Yep, fo starts to make it a little crazy, that is for sure. That's the part that scares me about it. I wonder if we could do an initial pass ignoring formatoptions just to get something out there and then go from there—you know, get a sense of what people use it for, so what parts of fo are important to work first. I know for me, the only way I (try to and fail to) use it in VsVim is to format comments in C# or F# files. Do you still think it deserves its own module?

I think it's fine to start by simplifying the feature and expanding out
later on.

My instinct would be to put this into a separate module / type. At the
very least it will require a tokenizer which needs a separate type.

On Fri, Oct 31, 2014 at 10:41 AM, Kazark [email protected] wrote:

Okay, gotcha. Yep, fo starts to make it a little crazy, that is for sure.
That's the part that scares me about it. I wonder if we could do an initial
pass ignoring formatoptions just to get something out there and then go
from there—you know, get a sense of what people use it for, so what parts
of fo are important to work first. I know for me, the only way I (try to
and fail to) use it in VsVim is to format comments in C# or F# files. Do
you still think it deserves its own module?


Reply to this email directly or view it on GitHub
https://github.com/jaredpar/VsVim/issues/333#issuecomment-61298899.

Jared Parsons
http://blog.paranoidcoding.com/
http://twitter.com/jaredpar

Oh, okay! I was assuming there would already be some stuff built out for normal commands like w and b and e and whatnot which must already be chunking up the text in an appropriate way. However, I haven't looked at the code. I should probably do that before pontificating further...

@jaredpar I have started playing around with this as a kata, but am trying to build it in a way that it could be ingrafted into VsVim if it gets to a useful point (i.e. writing my tests in C# with XUnit, trying to follow your conventions, etc).

@jaredpar Okay, I have the meat of what I consider the core cases implemented in the kata mentioned above. Care to take a look?

Sure, do you have a branch I can look at?

On Fri, Dec 12, 2014 at 10:03 AM, Kazark [email protected] wrote:

@jaredpar https://github.com/jaredpar Okay, I have the meat of what I
consider the core cases implemented in the kata mentioned above. Care to
take a look?


Reply to this email directly or view it on GitHub
https://github.com/jaredpar/VsVim/issues/333#issuecomment-66809905.

Jared Parsons
http://blog.paranoidcoding.com/
http://twitter.com/jaredpar

Sorry, no, not yet; only in this repository... so far I have just built the code standalone from VsVim and would like some hints from you about how to start integrating it, if you have any tips.

This feature would be very helpful.

Is it too simplistic to just map gq to :vsc Edit.FormatSelection and have Visual Studio worry about the formatting? Can VsVim simply forward the value of tw to the matching Visual Studio formatting option for the current document?

:noremap gq :vsc Edit.FormatSelection<CR>

@mqudsi That kind of formatting (code formatting) is already support using =. This kind of formatting (wrapping and indenting text and comments) is not yet implemented.

I have a preliminary version of this working. I'll submit a PR when it is finished.

@ricksladkey you are the :bomb:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ArnisL picture ArnisL  ·  5Comments

thelamb picture thelamb  ·  5Comments

iamkarlson picture iamkarlson  ·  7Comments

elrob picture elrob  ·  6Comments

myopicmage picture myopicmage  ·  5Comments