Page feed symbol display in Vim

2019-03-18 11:07发布

问题:

One of the nice things about Vim is that one can insert a page feed symbol (Ctrl-L in Insert mode), which delegates the printer to start printing the following on a new page. It shows as ^L in text.

Is it possible to make this symbol show as something else, for example as

----------------- new page here -----------------  

so it is somewhat more visible while scrolling through pages of text?

That is, without rebuilding Vim from source.

回答1:

If you do not use folding extensively when editing those files containing page feed symbols, you can use one-line folds to mark them out. Using foldexpr option it is possible to increase fold level of the lines that contain page feed symbol (below, for speed of evaluating foldexpr, I assume that page feed symbols are always the first characters of their lines). To achieve the desired effect of screen-wide separator these folds can be made auto-closable.

The following function configures folding according to the idea described above. Call it (manually or by an auto-command) to enable page feed symbol folding in the current buffer.

function! FoldPageFeed()
    setl foldmethod=expr
    setl foldexpr=getline(v:lnum)[0]==\"\\<c-l>\"
    setl foldminlines=0
    setl foldtext='---\ new\ page\ '
    setl foldlevel=0
    set foldclose=all
endfunction

Resulting separators appear as the text --- new page followed by a continuing string of filling characters (see :help fillchars, item fold:) to the right of the window.



回答2:

If it could, I would be uncomfortable knowing that vim my heavily trusted tool and friend, could misrepresent a text file.

Of course, you could always execute this command (perhaps as a macro) to do the same thing:

:%s/^L/----------------- new page here -----------------/


回答3:

If you defined your own highlight group in vim to be just the ^L symbol, then you could have a custom highlighted background for all lines that contain that character.

Its not quite a "-----------new page here------------" but would make page breaks easily visible when scrolling through large amounts of text.

I don't know enough vim to actually tell you how to set the highlight group though...



回答4:

I don't think you can. There is a Non-text highlight group which could help. Another way (a bit ugly) would be to write some autocommand to expand ^L to ---- new page ---- and vice versa when on InsertLeave, BufRead and BufSave.

Anyway , the answer of your question is : NO if you just want to change the display, and probably yes with a nasty plugin.



标签: vim folding