Gvim line wrap should end the current line and start a new one on the next line

I have the following line in my .gvimrc file for automatically wrapping a string of 80 characters.

set textwidth=80 

I also have the following lines to control the deviation of C ++ code.

 set smartindent set cindent 

This works well most of the time, but has a limitation when typing long lines. Spaces or tabs added by auto-indexing become part of the line. For example, currently wrapping a string:

 puts("I have put `set textwidth=80` in my `.gvimrc` file to make gvim automatically wrap long strings like this one."); 

whereas I would like to do the following:

 puts("I have put `set textwidth=80` in my `.gvimrc` file to make gvim " "automatically wrap long strings like this one."); 

This will ensure that there are no false promising spaces in the output, while maintaining a constant indentation of the code.

Is there any way to configure gvim for this? I searched the Internet and StackOverflow but couldn't figure out how to do this.

+4
source share
2 answers

There is no built-in parameter 'formatoptions' for this (for now), I'm afraid. However, formatting with gq and text splitting outside of 'textwidth' can be customized using the custom 'formatexpr' , although I have seen it is rarely used so far.

If you do not want to try to implement such an implementation, a simple workaround is to install 'colorcolumn' ; that visual help will help you remember closing the line and press Enter until the text width is reached.

+1
source

Check it out .

You can use the formatoption command to solve your problem somewhat.

-1
source

Source: https://habr.com/ru/post/1446907/


All Articles