Getting a line to wrap/reformatting paragraphs

35 views
Skip to first unread message

Eric Weir

unread,
Feb 23, 2012, 11:26:17 AM2/23/12
to vimorg...@googlegroups.com

It appears that vimorganizer causes lines to wrap by inserting a character of some kind--LF, CR, or combination, or something else altogether. If I edit a several line paragraph, I end up with a paragraph with lines that are short of the right margin and/or lines that extend beyond the right margin.

Is there a command for reformatting paragraphs that have been edited? Is there a simple way of exporting text without the hard returns, whatever they are?  

Thanks,
------------------------------------------------------------------------------------------
Eric Weir

"Uncertainty is an uncomfortable position, 
but certainty is an absurd one."
 
- Voltaire

Herbert Sitz

unread,
Feb 23, 2012, 12:37:55 PM2/23/12
to vimorg...@googlegroups.com
On Thu, Feb 23, 2012 at 8:26 AM, Eric Weir <eew...@bellsouth.net> wrote:
>
> It appears that vimorganizer causes lines to wrap by inserting a character
> of some kind--LF, CR, or combination, or something else altogether. If I
> edit a several line paragraph, I end up with a paragraph with lines that are
> short of the right margin and/or lines that extend beyond the right margin.
>

Yes, it does insert <cr>'s. There are lots of different ways/settings
of having linewrap work in Vim and this is the one I've found best.
One place where settings can be changed is with 'formatoptions'
option. See ':h formatoptions' and ':h fo-table'. The default
formatoptions flags in org buffers are: qtcwn

You can get automatic reformatting as you type by adding the 'a' flag:
:set formatoptions+=a

I don't use that auto option, though, and I'm not sure how it may
interact with some of the other settings, esp. the 'w'.


> Is there a command for reformatting paragraphs that have been edited? Is
> there a simple way of exporting text without the hard returns, whatever they
> are?
>

Typically the 'gq' command is used to reformat a section of text. See
':h gq'. With the 'w' setting in formatoptions this will only
reformat lines that end with a <non-space><cr>, not lines that end
with <space><cr>. This ends up pretty natural, I think.

Single linebreaks between text lines are generally ignored when doing
any of the Emacs/Orgmode exports, unless text is in literal sections
like code blocks or uses character codes like =text between equals is
literal "code"=. In exports paragraph breaks are deemed to occur
whenever there is a blank line, the preceding block/lines will be
combined into single paragraph. You can get more info on that in
Orgmode documentation, start here:
http://orgmode.org/manual/Structural-markup-elements.html#Structural-markup-elements

Answer to previous question is: different tabs in same Vim window are
not different instance. A separate Vim window on your desktop will be
a completely independent and separate "instance" of Vim.

Hope that helps,

Herb

Herbert Sitz

unread,
Feb 23, 2012, 12:41:24 PM2/23/12
to vimorg...@googlegroups.com
On Thu, Feb 23, 2012 at 9:37 AM, Herbert Sitz <hes...@gmail.com> wrote:
>> Is there a command for reformatting paragraphs that have been edited? Is
>> there a simple way of exporting text without the hard returns, whatever they
>> are?
>>
>
> Typically the 'gq' command is used to reformat a section of text.  See
> ':h gq'.  With the 'w' setting in formatoptions this will only
> reformat lines that end with a <non-space><cr>, not lines that end
> with <space><cr>.  This ends up pretty natural, I think.
>

Also, with 'w' setting the autoformatting with 'a' flag will also only
reformat lines that end with <space><cr>.

Not sure whether your VimOrganizer is set up to highlight the end of
line characters or spaces at end of line. If not, it's helpful to get
some nonobtrusive highlight so you can see which lines end with
<space><cr> and which end with <non-space><cr>.

Herbert Sitz

unread,
Feb 23, 2012, 12:57:18 PM2/23/12
to vimorg...@googlegroups.com
On Thu, Feb 23, 2012 at 9:37 AM, Herbert Sitz <hes...@gmail.com> wrote:
>
>> Is there a command for reformatting paragraphs that have been edited? Is
>> there a simple way of exporting text without the hard returns, whatever they
>> are?
>>
>
> [ . . ]

> With the 'w' setting in formatoptions this will only
> reformat lines that end with a <non-space><cr>, not lines that end
> with <space><cr>.  This ends up pretty natural, I think.

Sorry, I said that backwards. With 'a' flag only lines that get
reformatted are ones that end with <space><cr>. You can think of
lines that end <space><cr> as "soft break" lines and lines that end
<non-space><cr> as "hard break" lines.

Eric Weir

unread,
Feb 23, 2012, 1:42:33 PM2/23/12
to vimorg...@googlegroups.com

On Feb 23, 2012, at 12:37 PM, Herbert Sitz wrote:

> Yes, it does insert <cr>'s. There are lots of different ways/settings
> of having linewrap work in Vim and this is the one I've found best.
> One place where settings can be changed is with 'formatoptions'
> option. See ':h formatoptions' and ':h fo-table'. The default
> formatoptions flags in org buffers are: qtcwn
>
> You can get automatic reformatting as you type by adding the 'a' flag:
> :set formatoptions+=a

Thanks, Herb. Lots to learn about vim. At this point the defaults look like what I would want.

Should I take it that the + in command for setting the 'a' flag means that it is added to the defaults, that it doesn't override them?

> Typically the 'gq' command is used to reformat a section of text. See
> ':h gq'. With the 'w' setting in formatoptions this will only
> reformat lines that end with a <non-space><cr>, not lines that end
> with <space><cr>. This ends up pretty natural, I think.

I've tried 'gq' on a selection. That'll be my solution for the time being, till I have a better understanding of the options.

> Single linebreaks between text lines are generally ignored when doing
> any of the Emacs/Orgmode exports, unless text is in literal sections
> like code blocks or uses character codes like =text between equals is
> literal "code"=. In exports paragraph breaks are deemed to occur
> whenever there is a blank line, the preceding block/lines will be
> combined into single paragraph. You can get more info on that in
> Orgmode documentation, start here:
> http://orgmode.org/manual/Structural-markup-elements.html#Structural-markup-elements

May change with more experience, but at the moment I'm going with the 'no white space' paragraph marker. Assuming I continue, would it be possible to substitute that for blank lines?

Do you know if emacs/orgmode can process markdown or multimarkdown?

Thanks,
------------------------------------------------------------------------------------------
Eric Weir
eew...@bellsouth.net

"Human coexistence and social life constitute the good common to us all
from which and thanks to which all cultural and social goods derive."

- Zygmunt Bauman

Eric Weir

unread,
Feb 23, 2012, 1:49:38 PM2/23/12
to vimorg...@googlegroups.com

On Feb 23, 2012, at 12:41 PM, Herbert Sitz wrote:

> On Thu, Feb 23, 2012 at 9:37 AM, Herbert Sitz <hes...@gmail.com> wrote:
>
>> Typically the 'gq' command is used to reformat a section of text. See
>> ':h gq'. With the 'w' setting in formatoptions this will only
>> reformat lines that end with a <non-space><cr>, not lines that end
>> with <space><cr>. This ends up pretty natural, I think.
>
> Also, with 'w' setting the autoformatting with 'a' flag will also only
> reformat lines that end with <space><cr>.

With, as I understand it, <non-space><cr> as the paragraph delineator that strikes me as more natural. If I wanted to go with the 'a' option should I put that in my .vimrc? Right now I think I would want it to apply only to 'org' files.

> Not sure whether your VimOrganizer is set up to highlight the end of
> line characters or spaces at end of line. If not, it's helpful to get
> some nonobtrusive highlight so you can see which lines end with
> <space><cr> and which end with <non-space><cr>.

It is not. That would be helpful--if it was nonobtrusive. Is that addressed in the documentation?

Eric Weir

unread,
Feb 23, 2012, 1:51:12 PM2/23/12
to vimorg...@googlegroups.com

Got it. Thanks.

------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA
eew...@bellsouth.net

"A man should be in the world as though he were not in it
so that it will be no worse because of his life."

- Wendell Berry

Herbert Sitz

unread,
Feb 24, 2012, 5:27:19 PM2/24/12
to vimorg...@googlegroups.com
On Thu, Feb 23, 2012 at 10:49 AM, Eric Weir <eew...@bellsouth.net> wrote:
>
>
> With, as I understand it, <non-space><cr> as the paragraph delineator that strikes me as more natural. If I wanted to go with the 'a' option should I put that in my .vimrc? Right now I think I would want it to apply only to 'org' files.

formatoptions are set each time a buffer is set to org filetype, so
setting it once in vimrc won't work. You can edit the line at very
bottom of org.vim in /ftplugin directory, which now says 'set
fo=qtcwn' and add an 'a' to it. Or, I just pushed up a change to
github that lets you set using a variable in your vimrc: let
g:org_formatoptions=qtcwna .

>
>> Not sure whether your VimOrganizer is set up to highlight the end of
>> line characters or spaces at end of line.  If not, it's helpful to get
>> some nonobtrusive highlight so you can see which lines end with
>> <space><cr> and which end with <non-space><cr>.
>
> It is not. That would be helpful--if it was nonobtrusive. Is that addressed in the documentation?
>

Probably not in vimorg docs. There are a couple ways to do it.

First, you can have the ending <cr> marker be displayed on screen:
E.g., put this in vimrc to use a pilcrow sign for eol:

set listchars+=eol:¶
highlight NonText guifg=gray

To enter Pilcrow you must do <c-k><s-p><s-i> in insert mode. See :h
digraph for more.

To have trailing spaces highlighted do this:

set listchars+=trail:- (that's a hyphen in last spot but you
could also put blank space there)
highlight SpecialKey guibg=#330000 (will make trailing spaces dark red)

As always there are various wrinkles, maybe highlighting trailing
characters is only part you want, or vice versa. But that shoudl get
you started.

-- Herb

Eric Weir

unread,
Feb 25, 2012, 7:20:29 AM2/25/12
to vimorg...@googlegroups.com

On Feb 24, 2012, at 5:27 PM, Herbert Sitz wrote:

> First, you can have the ending <cr> marker be displayed on screen:
> E.g., put this in vimrc to use a pilcrow sign for eol:
>
> set listchars+=eol:¶
> highlight NonText guifg=gray

When I put this in my .vimrc, as below, I lose highlighting of vimorganizer syntax in outlines. Folding commands work but highlighting is lost.

"insert end of paragraph marker


"set listchars+=eol:¶
"highlight NonText guifg=gray

------------------------------------------------------------------------------------------

Eric Weir

unread,
Feb 25, 2012, 9:14:08 AM2/25/12
to vimorg...@googlegroups.com

On Feb 25, 2012, at 7:20 AM, Eric Weir wrote:

> When I put this in my .vimrc, as below, I lose highlighting of vimorganizer syntax in outlines. Folding commands work but highlighting is lost.
>
> "insert end of paragraph marker
> "set listchars+=eol:¶
> "highlight NonText guifg=gray

Also, don't get highlighting of the end-of-paragrah character.

------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA
eew...@bellsouth.net

"What does it mean...that the world is so beautiful?"

- Mary Oliver


Herbert Sitz

unread,
Feb 27, 2012, 12:08:48 PM2/27/12
to vimorg...@googlegroups.com
On Sat, Feb 25, 2012 at 6:14 AM, Eric Weir <eew...@bellsouth.net> wrote:
>
> On Feb 25, 2012, at 7:20 AM, Eric Weir wrote:
>
>> When I put this in my .vimrc, as below, I lose highlighting of vimorganizer syntax in outlines. Folding commands work but highlighting is lost.
>>
>> "insert end of paragraph marker
>> "set listchars+=eol:¶
>> "highlight NonText guifg=gray
>
> Also, don't get highlighting of the end-of-paragrah character.
>

Eric -- I don't know how it could have lost all highlighting, but
sorry I was wrong about the 'highlight NonText' command. You need to
put it in a spot where it gets executed every time color is changed in
an org buffer. So put this special function in your vimrc:


function! OrgCustomColors()
highlight NonText guifg=gray
endfunction

***NOTE That function is already in sample vimrc shipped with
VimOrganizer but all lines were "commented out".

Also, I just added support for a new vimrc function (in new version at
github) where non-color/highlight related changes can be made that
will affect org buffers. This would be best place for change to
formatoptions talked about in previous message:

"**** put this in vimrc. . . ******
function! OrgCustomSettings()
set formatoptions+=a
endfunction


-- Herb

Eric Weir

unread,
Feb 28, 2012, 9:06:15 AM2/28/12
to vimorg...@googlegroups.com

A question and a request, Herb: [1] Do I need to edit the code for highlighting the end of paragraph marker after inserting the first funcgtion? [2] I like to document the stuff that goes into my .vimrc. From your description and the code for these two functions I'm not clear what they do, how to describe them. I know what the a switch does in the second one, but that's about all. Could you give me a brief description suitable for a "layperson" for each of them?

Thanks,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA USA
eew...@bellsouth.net


Herbert Sitz

unread,
Feb 28, 2012, 11:42:13 AM2/28/12
to vimorg...@googlegroups.com
On Tue, Feb 28, 2012 at 6:06 AM, Eric Weir <eew...@bellsouth.net> wrote:
>
> A question and a request, Herb: [1] Do I need to edit the code for highlighting the end of paragraph marker after inserting the first funcgtion? [2] I like to document the stuff that goes into my .vimrc. From your description and the code for these two functions I'm not clear what they do, how to describe them. I know what the a switch does in the second one, but that's about all. Could you give me a brief description suitable for a "layperson" for each of them?
>

[1] Eric, I was suggesting that you move the relevant highlight
command _into_ the OrgCustomColors() function in your vimrc. That
function is called every time an org file is opened or a color scheme
is changed and there's some more docs on it in the help. :h
vimorg-customizing-colors.

I suggested moving the highlight command because you said you had
problems with my original suggestion. I'm not sure how problems you
described arose at all, but it's safest to have any custom
highlighting of org buffers in OrgCustomColors().

[2] The OrgCustomSettings() function is analogous to
OrgCustomColors(), but more general. It is run in each buffer when
the buffer is set to an org filetype, and after all default org
settings have been applied. This means you can put commands in
OrgCustomSettings() that override org defaults. I gave an example
with formatoptions, but any changes to default settings could be put
in that function. (Not all changes will coexist peacefully with
other default settings, but at least user has the power to manage them
now.)

-- Herb

Eric Weir

unread,
Feb 28, 2012, 1:24:26 PM2/28/12
to vimorg...@googlegroups.com

On Feb 28, 2012, at 11:42 AM, Herbert Sitz wrote:

> [1] Eric, I was suggesting that you move the relevant highlight
> command _into_ the OrgCustomColors() function in your vimrc. That
> function is called every time an org file is opened or a color scheme
> is changed and there's some more docs on it in the help. :h
> vimorg-customizing-colors.

Like this?:

"Highlight end of paragraph marker
set listchars+=eol:¶


function! OrgCustomColors()
highlight NonText guifg=gray
endfunction

> I suggested moving the highlight command because you said you had


> problems with my original suggestion. I'm not sure how problems you
> described arose at all, but it's safest to have any custom
> highlighting of org buffers in OrgCustomColors().

Could that have anything to do with the fact that I didn't have this in my .vimrc?

au! BufRead,BufWrite,BufWritePost,BufNewFile *.org
au BufEnter *.org call org#SetOrgFileType()

Thanks,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA USA
eew...@bellsouth.net

"Hatred destroys. Love heals."

- Eknath Easwaran

Reply all
Reply to author
Forward
0 new messages