I used to have some simple map
macros that implemented a "pager mode" for vi.
When I was reading through a very long file, I would activate pager mode. This would make two key maps:
<Space>
would be mapped to:^F^G
<Backspace>
would be mapped to:^B^G
Not that weird. Space would go to the next whole screenful, and then display the filename status line (that also includes line number and percent progress through the file). Backspace went to previous screen and displayed the status line.
But I didn't want these active all the time; I wanted to be able to activate and deactivate them. So I bound a pair of key sequences:
]p
would "activate pager mode" (i.e. would make the bindings above)
]P
would "deactivate pager mode" (i.e. would unmap those two keys)
This is tricky because mapping the space bar can be tricky, and because I was trying to write a macro that would run two map
commands.
Way back in the day, I'm pretty sure this used to work:
"this was in .exrc
"note: all "^" sequences were actual control characters
map ]p :map ^V^V^V ^F^G^M:map ^V^V^? ^B^G^M
map ]P :unmap ^V^V^V ^M:unmap ^V^V^?^M
All ^
sequences were actual control characters. ^V
was <Ctrl+V>
and so on.
^V
quotes something, and I think I had to double it to get a single ^V
in the macro that would run.
So, the ]p
macro, when run, would map the two keys, and ]P
would unmap them.
I don't use these every day and I'm not sure when they broke. But at some point I tried them, and they were broken. Recently I decided to invest the time to get these working. I have a kludge working but it's not elegant, and it only flips pages; the part where it should display the status line simply doesn't work. I tried both including ^G
and explicitly saying :file^M
and while I don't have any errors, it also doesn't display anything. It does nothing.
All I ever run these days is Vim so I'm specifically looking for a solution that will work in Vim and I don't care if it's Vim-specific.
Because this is a map
that is supposed to do a map
the quoting issues are tedious, and because we are binding space bar quoting is even trickier. It seems like there ought to be an elegant way to do this by making Vimscript functions that would map or unmap the keys, and then binding ]p
and ]P
to call the functions.
If anyone really wants I'll post my kludge here, but I'm hoping someone with more Vim knowledge can make something better so I'm not posting it now.
In summary:
]p
should map the keys]P
should unmap the keys- When mapped,
<Space>
should do the same thing as:^F^G
- When mapped,
<Backspace>
should do the same thing as:^B^G