Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gq doesn't format text #333

Closed
loosche opened this issue Nov 3, 2010 · 32 comments
Closed

gq doesn't format text #333

loosche opened this issue Nov 3, 2010 · 32 comments

Comments

@loosche
Copy link

loosche commented Nov 3, 2010

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.

@coraxnero
Copy link

yeah, missed that feature, too :/

@frizzr
Copy link

frizzr commented May 29, 2012

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

@jazzdelightsme
Copy link

<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 :))

@jaredpar
Copy link
Collaborator

jaredpar commented Jan 7, 2013

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.

@jaredpar
Copy link
Collaborator

jaredpar commented Jan 8, 2013

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

--dog-chases-cat

the result was

--dog
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.

@fpicalausa
Copy link
Contributor

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:

--dog
--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:

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

@jaredpar
Copy link
Collaborator

jaredpar commented Jan 8, 2013

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!

@Kazark
Copy link
Contributor

Kazark commented May 8, 2013

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

Just curious; any progress on this issue?

@jaredpar
Copy link
Collaborator

jaredpar commented May 8, 2013

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

@wildmichael
Copy link

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

@andmatand
Copy link

👍 +1 for gq functionality!

@t-nelis
Copy link

t-nelis commented Jul 3, 2014

👍

@aVolpe
Copy link

aVolpe commented Sep 4, 2014

@Kazark
Copy link
Contributor

Kazark commented Oct 31, 2014

@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?)

@jaredpar
Copy link
Collaborator

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 notifications@github.com 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
#333 (comment).

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

@Kazark
Copy link
Contributor

Kazark commented Oct 31, 2014

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?

@jaredpar
Copy link
Collaborator

@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

@Kazark
Copy link
Contributor

Kazark commented Oct 31, 2014

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?

@jaredpar
Copy link
Collaborator

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 notifications@github.com 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
#333 (comment).

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

@Kazark
Copy link
Contributor

Kazark commented Oct 31, 2014

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...

Kazark added a commit to Kazark/fsharp-katas that referenced this issue Dec 11, 2014
This is being designed in such a way that it can hopefully be
incorporated into VsVim in the future.

VsVim/VsVim#333
@Kazark
Copy link
Contributor

Kazark commented Dec 11, 2014

@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).

@Kazark
Copy link
Contributor

Kazark commented Dec 12, 2014

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

@jaredpar
Copy link
Collaborator

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

On Fri, Dec 12, 2014 at 10:03 AM, Kazark notifications@github.com 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
#333 (comment).

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

@Kazark
Copy link
Contributor

Kazark commented Dec 15, 2014

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.

@jaredpar jaredpar modified the milestones: 1.8.1, 2.1.0 Jul 20, 2015
@squk
Copy link

squk commented Jul 27, 2017

This feature would be very helpful.

@mqudsi
Copy link

mqudsi commented Nov 9, 2017

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>

@jaredpar jaredpar modified the milestones: 2.5.1, 2.5.0 release, 2.6.0, vNext Candidate Jan 1, 2018
@ricksladkey
Copy link
Collaborator

@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.

@ricksladkey
Copy link
Collaborator

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

@Kazark
Copy link
Contributor

Kazark commented Jul 23, 2018

@ricksladkey you are the 💣

@martin-braun
Copy link

Instead of fixing it so it's not a deal for new users anymore, one just closes this issue, because you can hack your way out. It just makes poor quality when this is a case for a dozen of things with this extension. I'm a Neovim user who needs to use Visual Studio code. I only pick VsVim, because it's the best I can have, it's not fulfilling on a wider scale, because of little things like this.

@mqudsi
Copy link

mqudsi commented May 22, 2023

@martin-braun did you read #2274? gq is implemented (in a limited capacity).

@martin-braun
Copy link

martin-braun commented May 23, 2023

@mqudsi Missed that, but not working for me. I simply mapped Edit.FormatDocument or so on Visual Studio. Sorry about that comment, though. Assumed the issue was ignored, which was not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests