Indentation issue

47 views
Skip to first unread message

Steve

unread,
Jun 17, 2013, 11:24:36 AM6/17/13
to vim
Hi,

While writing a mail in French, I would like that each first line of a
paragraph is indented, like this:

ksjdk ksjdkjsddsj kjsdksjd kjsdksdj
kjhkasjhd kajshdkajsdk, kajshd kjahsd
akshd kajsh kahsd hdkask.

kjsdkf ksjdhfsdf kjdshf klsdjhksd
khsdj ksdjf ksdjhf ksdjh ksdhf, lslsl,
lslsosk sljs ls lllss llksd llksddlskd
lsdklsd.

I would like it to be automatic. For the time being, if I manually indent with
two spaces, next lines will be automatically indented by two spaces, I guess
it's the 'set autoindent' setting that does that, which is ok for writing code
but not emails (at least in French).


How could I do this?

Thank you,
steve

Guyzmo

unread,
Jun 17, 2013, 11:52:01 AM6/17/13
to vim
Hi,
I have written a plugin that does exactly that for mails. It's still
not perfect (I have a few bugs to tweak), but as you can see with this
mail it works. It's called yaposting, it's on my github and on
vimscript:

* http://www.vim.org/scripts/script.php?script_id=957
* https://github.com/guyzmo/vim-yaposting/

Basically, you write your paragraph without caring about the
indentation, and when you finish that paragraph, you just have to
execute <Leader>mr. When you want to use a '�' or a ':', you just need
to use a non-secable space '�' before/after the character, so you don't
take any chance displaying it wrongly.

It supports having an alinea at the begining of your paragraphs (you
can set up how many spaces you want), setting a left/right margin,
and even reformat quoted text. You can also tell it to justify your
text, left align or right align your text.

Sadly, there are two bugs I have to take care of (that is getting
dust in my TODO list :-s):

* <Leader>mr does not work as it should, but vip<Leader>mr does.
* if you don't add a space at the end of the previous line or a
space at the begining of the current line, last word of previous
line and first word of current line gets joined.

BTW, I also wrote a python library that takes care of all
formatting, that supports perfectly unicode text!

HTH

--
Guyzmo

 Dhénin Jean-Jacques

unread,
Jun 17, 2013, 11:33:06 AM6/17/13
to vim...@googlegroups.com


2013/6/17 Steve <dl...@bluewin.ch>
Par is similar but superiour to the fmt(1) command included in the
    base system.

    Par is a filter that copies its input to its output, changing all
    white characters (except newlines) to spaces, and reformatting
    each paragraph.  Paragraphs are separated by protected, blank, and
    bodiless lines (see the Terminology section for definitions), and
    optionally delimited by indentation (see the d option in the Options
    section).

    Each output paragraph is generated from the corresponding input
    paragraph as follows:

     1) An optional prefix and/or suffix is removed from each input line.
     2) The remainder is divided into words (separated by spaces).
     3) The words are joined into lines to make an eye-pleasing paragraph.
     4) The prefixes and suffixes are reattached.

     If there are suffixes, spaces are inserted before them so that they
     all end in the same column.

WWW: http://www.nicemice.net/par/
 
Hope this help
---------------------------------------------------------
(°>   Dhénin Jean-Jacques
/ )     48, rue de la Justice 78300 Poissy
^^   dhe...@gmail.com
---------------------------------------------------------

Ben Fritz

unread,
Jun 17, 2013, 1:02:19 PM6/17/13
to vim...@googlegroups.com, dl...@bluewin.ch

set fo+=2

and maybe

set fo+=a

You must still manually add two spaces indent to the first line, but after that the rest of the paragraph aligns as you want.

You could probably make some mappings to automatically enter the two spaces. Maybe:

inoremap <CR><CR> <CR><CR><Space><Space>

or

inoremap <CR><CR> <CR><CR><C-T>

And similar for pressing 'o' in normal mode. Consider buffer-local mappings so it only happens for plaintext files.

Guyzmo

unread,
Jun 18, 2013, 7:59:41 AM6/18/13
to vim
Hello,

On Mon, Jun 17, 2013 at 05:52:01PM +0200, Guyzmo wrote:
> Sadly, there are two bugs I have to take care of (that is getting
> dust in my TODO list :-s):
> * <Leader>mr does not work as it should, but vip<Leader>mr does.
> * if you don't add a space at the end of the previous line or a
> space at the begining of the current line, last word of previous
> line and first word of current line gets joined.
well I have hoovered my todo list, and now these bugs are fixed!

--
Guyzmo

Steve

unread,
Jun 21, 2013, 10:12:08 AM6/21/13
to vim...@googlegroups.com
Hi,


Le 17-06-2013, à 10:02:19 -0700, Ben Fritz a écrit :

> On Monday, June 17, 2013 10:24:36 AM UTC-5, Steve wrote:
> > Hi,
> > While writing a mail in French, I would like that each first line of a
> > paragraph is indented, like this:
> >
> > ksjdk ksjdkjsddsj kjsdksjd kjsdksdj
> > kjhkasjhd kajshdkajsdk, kajshd kjahsd
> > akshd kajsh kahsd hdkask.
> > kjsdkf ksjdhfsdf kjdshf klsdjhksd
> > khsdj ksdjf ksdjhf ksdjh ksdhf, lslsl,
> > lslsosk sljs ls lllss llksd llksddlskd
> > lsdklsd.
> >
> > I would like it to be automatic. For the time being, if I manually indent
> > with two spaces, next lines will be automatically indented by two spaces, I
> > guess it's the 'set autoindent' setting that does that, which is ok for
> > writing code but not emails (at least in French).
> >
>
> set fo+=2

Thanks, that's exactly what I was looking for.

> and maybe
>
> set fo+=a

Not required but very useful.

> You must still manually add two spaces indent to the first line, but after
> that the rest of the paragraph aligns as you want.

Yes and the same for the next paragraphs.

> You could probably make some mappings to automatically enter the two spaces.
> Maybe:
>
> inoremap <CR><CR> <CR><CR><Space><Space>
>
> or
>
> inoremap <CR><CR> <CR><CR><C-T>

Very nice, thank you.

> And similar for pressing 'o' in normal mode. Consider buffer-local mappings
> so it only happens for plaintext files.


Thank you for your answer, it helped me a lot looking at the right place in the
help.

Regards,
steve

Steve

unread,
Jun 21, 2013, 10:16:58 AM6/21/13
to vim
Hi Guyzmo,

I tried your plugin, but for an unknown reason I didn't manage to make it work.
So I concentrated on Ben's suggestion because I'm still learning vim's basics
and I thought it would be better for me to understand those than a plugin full
of code :)

But thanks a lot for your answer, and once I'm a bit more comfortable with vim,
I'll try your plugin.

Regards,
Steve

Steve

unread,
Jun 25, 2013, 5:22:18 AM6/25/13
to vim...@googlegroups.com

Hi,

Just for the record, maybe someone will need this one day. For the
fo+=2 option to work well, one needs to turn autoindenting off. I tried
putting 'set noautoindent' in several files but it didn't work
(something somewhere just activated it back on). So I finally found how
to do it properly. Create a file called ~/.vim/indent/mail.vim (if you
don't want this for writing emails, for html, it would be html.vim for
ex.) with this one line:

let b:did_indent = 1

and you're done. The reason it works is given here:

http://vim.wikia.com/wiki/How_to_stop_auto_indenting

Have a nice day,
steve

Reply all
Reply to author
Forward
0 new messages