Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to display page feed symbols differently in Vim?

Tags:

vim

folding

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.

like image 489
Rook Avatar asked Mar 18 '11 02:03

Rook


2 Answers

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 the foldexpr option, it is possible to increase the fold level of the lines that contain page feed symbol. (Herein, for the sake of efficiency of evaluating foldexpr, I assume that page feed symbols are always the first characters on their lines.) To achieve the desired effect of a 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 means of an autocommand) 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 to the right of the window (see :help fillchars, under the fold: item).

like image 150
ib. Avatar answered Oct 16 '22 20:10

ib.


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.

like image 23
mb14 Avatar answered Oct 16 '22 20:10

mb14