Prevent "Press Enter" in Vim Script


I use a Vim session to restore my workspace when I return to work.


Remember that a Vim session is a type of Vim script. So, if I refer to a script below, that information also applies to my problem with a session.


Vim scripts are a series of Vim commands saved in a text file. Each Vim command appears on a separate line. If you use Vim to automatically generate a session file, that file can be edited manually.


I modified my session file to include:


1,4 yank q

This copies lines 1-4 into the "q register.


This solves a problem where I wanted to reuse text by saving it and pasting it later.


The problem I'm having now is that having this command in the Vim script generates the following prompt while loading my session:


Press ENTER or type command to continue

This forces me to press a key each time I load my session.


I would like to eliminate that prompt.


Solution


The solution is to prepend the silent command:


silent 1,4 yank q

This suppresses the "Press Enter" prompt while loading my Vim session.


Note


Typically, the automatic viminfo file would save the contents of the "q register. So, when I start Vim again, the contents of the "q register would still be available.


One way to solve my problem is to set "q and never change it.


After working out how to use the silent command, I decided to remove that line from my session and instead rely on viminfo to solve my problem. Now, when I load my session, the viminfo file restores the contents of "q. And I can paste from those restored contents.


References


Vim Session

viminfo File

:silent

hit-enter


Created: Friday, June 10, 2022

Updated: Friday, June 10, 2022




/gemlog/