Automatically add two spaces between sentences

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Automatically add two spaces between sentences

Vim the Best
When we use Vim, what's the best way to add two spaces between sentences automatically rather than manually press the space bar twice? That's prevalent in the source code comment like the following:

/*
 * comment comment.<space><space>more comment.
 */

Additionally by default, when we join two sentences with one on top of the other, there would be two spaces between them after joining. What do we need to do to achieve the similar effect with Vim automatically when we are typing?

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Automatically add two spaces between sentences

Erik Christiansen
On 14.03.17 22:20, Vim the Best wrote:
> When we use Vim, what's the best way to add two spaces between
> sentences automatically rather than manually press the space bar
> twice?

Perhaps you could use an iab, if necessary, using e.g. ".." for ".  ".
It still saves one keystroke, and does not make it impossible to enter
". ", for some other case. (OK, it does clobber a longhand ellipsis, so
maybe some other iab?)

> Additionally by default, when we join two sentences with one on top of
> the other, there would be two spaces between them after joining. What
> do we need to do to achieve the similar effect with Vim automatically
> when we are typing?

:help joinspaces

It is the default, so you should see it, unless you have:

set nojoinspaces

Erik

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
BPJ
Reply | Threaded
Open this post in threaded view
|

Re: Automatically add two spaces between sentences

BPJ
You can make one iabb turning ".<space>" into ".<space><space>" and another, e.g. ".~" for generating ".<space>" when you really want that. You can also have separate iabbs for the most frequent abbreviations expanding to themselves, like Mr. in English.

/bpj



Den 15 mar 2017 10:12 skrev "Erik Christiansen" <[hidden email]>:
On 14.03.17 22:20, Vim the Best wrote:
> When we use Vim, what's the best way to add two spaces between
> sentences automatically rather than manually press the space bar
> twice?

Perhaps you could use an iab, if necessary, using e.g. ".." for ".  ".
It still saves one keystroke, and does not make it impossible to enter
". ", for some other case. (OK, it does clobber a longhand ellipsis, so
maybe some other iab?)

> Additionally by default, when we join two sentences with one on top of
> the other, there would be two spaces between them after joining. What
> do we need to do to achieve the similar effect with Vim automatically
> when we are typing?

:help joinspaces

It is the default, so you should see it, unless you have:

set nojoinspaces

Erik

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
BPJ
Reply | Threaded
Open this post in threaded view
|

Re: Automatically add two spaces between sentences

BPJ
Den 2017-03-16 kl. 15:24, skrev BPJ:
> You can make one iabb turning ".<space>" into ".<space><space>" and
> another, e.g. ".~" for generating ".<space>" when you really want that. You
> can also have separate iabbs for the most frequent abbreviations expanding
> to themselves, like Mr. in English.
>
> /bpj

I came up with a way to do this which actually works: a keymap and
a couple of autocommands.
(See :h mbyte-keymap and :h 'kmp').

Don't use these when writing code! :-)

Put the following in a file ~/.vim/keymap/punctspace_utf-8.vim


     " Vim: set noet ts=20 sts=20 list:

     " short name for keymap
     let b:keymap_name = "pct"
     highlight lCursor guibg=red guifg=NONE
     scriptencoding utf-8

     loadkeymap
     " leave this line blank!

     " Punctuation plus space

     .<Space>            .<char-0xa0><Space>
     !<Space>            !<char-0xa0><Space>
     ?<Space>            ?<char-0xa0><Space>
     ..<Space>           .<char-0xa0>    " dot plus non-breaking space
     ..<Space><Space>    .<Space>        " dot plus ordinary space
     !!<Space>           !<Space>
     ??<Space>           ?<Space>

     " Abbreviations

     " You will want to add more and/or those for your language

     Mr.<Space>          Mr.<char-0xa0>
     Mrs.<Space>         Mrs.<char-0xa0>
     Dr.<Space>          Dr.<char-0xa0>
     e.g.<Space>         e.g.<char-0xa0>
     i.e.<Space>         i.e.<char-0xa0>
     viz.<Space>         viz.<char-0xa0>
     " more...

Then whenever you need elegant handling of punctuation +
whitespace in prose just say

     :setl kmp=punctspace

The point of using a non-breaking space after abbreviations is so
that you won't get linebreaks after abbreviations, which is
considered bad style.

The point of inserting a non-breaking space plus an ordinary space
at the end of a sentence is so that the double space will be
preserved when reformatting, but lines can break at the ordinary
space anyway.  You almost certainly want to define these
autocommands (where `<nbsp>` and `<space>` mean that you should
type `<C-K>NS` (digraph for non-breaking space) and an ordinary
space respectively at those points):

     " Replace dot + nbsp + space with dot + space + space before
writing Markdown files.
     :au BufWritePre *.md %s/\.<npsp><space>/.<space><space>/g

     " Replace dot + nbsp + newline with dot + newline before
writing Markdown files.
     :au BufWritePre *.md %s/\.<npsp>$/./g

     " The reverse actions after writing a Markdown file.
     :au BufWritePost *.md %s/\.<space><space>/.<nbsp><space>/g
     :au BufWritePost *.md %s/\.$/.<nbsp>/g

I use `*.md` in the examples because that fits my use case. You
may want to substitute or add `*.txt` or something else.

Note that the non-breaking spaces after abbreviations are
preserved when writing the file. That is intentional!

" Vim: set et ts=4 sts=4 list:

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.