15

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.

ib.
  • 27,830
  • 11
  • 80
  • 100
Rook
  • 60,248
  • 49
  • 165
  • 242
  • 5
    Why is this being voted offtopic? Vim fits to the extent of my knowledge quite nicely in the "software tools commonly used by programmers" category (see faq). – Rook Mar 18 '11 at 03:38
  • 2
    Vim was already acclaimed to be in home here (see [this](http://meta.stackexchange.com/q/25925/160504)) but from time to time, people unaware of it vote to close once the question appears in first page. – sidyll Aug 09 '11 at 14:07

4 Answers4

8

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).

ib.
  • 27,830
  • 11
  • 80
  • 100
  • @Rook: Let me know if you have any issues with this solution or would like to further customize it. – ib. Aug 10 '11 at 11:32
  • @ib - No, no issues whatsoever. I just didn't see it yesterday. But now that I do (see it), let me just say (a big) thank you - you made my day with this one! :) – Rook Aug 10 '11 at 21:37
1

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.

ib.
  • 27,830
  • 11
  • 80
  • 100
mb14
  • 22,276
  • 7
  • 60
  • 102
0

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 -----------------/
ib.
  • 27,830
  • 11
  • 80
  • 100
wallyk
  • 56,922
  • 16
  • 83
  • 148
  • 3
    That would obviously change the file. I'm afraid Rook wants just to "show" the page feed (like what "set list" does) – Steve Schnepp Mar 18 '11 at 03:00
  • @wallyk - line feeds are a kind of special characters. You can't really search and replace them that way. If you could that would mean they're just "^L" text. – Rook Mar 18 '11 at 03:37
  • ^L is a form feed, and yes, you can search and replace it just like any other character. Newlines and carriage returns get tricky though in some situations. – wallyk Mar 19 '11 at 06:59
  • @wallyk - Okey, well ... I would be more than happy to be proven wrong. In any case the given example does not work. – Rook Mar 20 '11 at 11:57
  • Did you type `Ctrl-L` or (caret) then (ell)? The former is necessary, though the latter looks identical onscreen. – wallyk Mar 20 '11 at 17:33
  • @wallyk - Of course. But that just turns them into "----new...---", I don't have form feeds anymore. – Rook Mar 22 '11 at 17:53
  • @wallyk To type `^L` in vim, and to behave as a line feed, do the following either in insert mode or after a `/` in the prompt: `+v 012` So hold control, and v, then release both keys and press 0 then 1 then 2. – phyatt Aug 17 '16 at 16:57
0

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.

It’s not quite a ---- new page here ----, but it 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…

ib.
  • 27,830
  • 11
  • 80
  • 100
skeletalmonkey
  • 726
  • 1
  • 10
  • 20
  • That's an approach, also. Unfortunatelly, although I belive there already is a highlighting group for it (SpecialKey or NonText, never can tell those apart) the problem is no matter what wild color you put it into, it's still invisible in text, being so small. – Rook Mar 18 '11 at 13:04
  • I thought if you were to set a background color, that you can get it to highlight the whole line, akin to the Statusline – skeletalmonkey Mar 19 '11 at 15:23
  • I haven't been able to do that. Maybe I'm doing something wrong. – Rook Mar 20 '11 at 11:58
  • maybe something similar to this? [link] (http://vim.1045645.n5.nabble.com/Highlight-whole-line-if-keyword-is-not-there-td1184782.html) – skeletalmonkey Mar 21 '11 at 06:08