IceGuye Blog

Avoid punctuation at the beginning of a line in VIM

Wrapping hard line in VIM is good in most of time. However, sometime it does not work well, especially when type some different languages into VIM.

On the following picture, we type two Latin style paragraphs into VIM, and then, type gq to wrap the lines. As you can see, this method works very well.

VIM does not support to wrap any language which is not separated by space, such as Chinese and Japanese by default. Therefore, we have to add following line to the vim's configuration file "~/.vimrc": set formatoptions+=mB However, is that enough. We don't think so, and let's see the result. On the following picture, we type two Chinese paragraphs in to vim, and then, type gq to wrap the lines. As you can see, we can wrap them, but some punctuations are at the beginning of some lines. This is wrong.

How can we fix it anyway?

The solution is installing a vim plugin named autofmt. We can use following command to setup and configure the autofmt plugin. Make sure that you have installed git on your computer. git clone https://github.com/vim-jp/autofmt mkdir -p ~/.vim cp -r autofmt ~/.vim/ Then we have to add the following line to your ~/.vimrc: set runtimepath+=/home/YOUR-NAME/.vim/autofmt/ set formatexpr=autofmt#uax14#formatexpr()

Let's see the result:

That is very nice, isn't it?

Hope your enjoy your work by using plain text editor to format a good looking article.

Have fun, be free!




Back to Blog's index