Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim hard line breaks and non-breaking spaces with pandoc

Tags:

vim

pandoc

I'm using vim with pandoc and need to use non-breaking spaces fairly regularly, which is achieved in pandoc by backslash-escaping a regular space (i.e., "\ "). I would prefer to use hard line breaks in vim, but when I do so and a non-breaking space occurs at the end of a line, the space character is deleted and the backslash remains at the end of the line -- and this signals the end of the paragraph to pandoc.

Is there a way I can tell vim to treat "\ " as a printed character when it reformats paragraphs with hard line breaks?

As an example, if I write the following:

This line contains a non-breaking space\ because I don't want a break after space.

What I want vim to do is this:

This line contains a non-breaking
space\ because I don't want a break after
space.

But what it does is this:

This line contains a non-breaking space\
because I don't want a break after space.

My workaround for the moment is to stick to soft line breaks, and I've remapped h to gh etc. to make that easier to deal with. I'm also trying to figure out whether there is an alternative way to specify a non-breaking space to pandoc that will be less confusing to vim.

like image 310
alanhr Avatar asked Jul 22 '15 13:07

alanhr


1 Answers

Use the proper UTF-8 character for a non-breaking space (U+00A0) instead of \. In Vim, you can insert it with Ctrl-v x a 0.

In your ~/.vimrc file add the following to highlight non-breaking spaces:

set list
set listchars=nbsp:.
like image 179
mb21 Avatar answered Oct 19 '22 11:10

mb21