Like most programmers, I perform a lot of repetitive tasks. In optimising my workflow, I'm taking some of those repetitive tasks, and refactoring them into shell scripts.
One thing that I'm trying to automate is the recreation of PostgreSQL views. I have the following view.
create or replace view person as
select
1 as person_id
, 'John'::text as first_name,
'Doe'::text as last_name;
I can dump this view with psql -c "\\d+ person"
and the output is as follows:
View "public.person"
Column | Type | Modifiers | Storage | Description
------------+---------+-----------+----------+-------------
person_id | integer | | plain |
first_name | text | | extended |
last_name | text | | extended |
View definition:
SELECT 1 AS person_id,
'John'::text AS first_name,
'Doe'::text AS last_name;
I can reformat this text into a CREATE OR REPLACE VIEW
statement with the following keystrokes in vim: gg0df"iCREATE OR REPLACE VIEW <ESC>$cl AS<ESC>j0d/^View definition:<CR>ddG$:wq
(I've reformatted <ESC>
, etc, in the above).
I've got the above working perfectly, except for the screen "flashes" that occur. For example, if at the shell I type a=$(psql -c "\\d+ person" | vim -s <vimscriptfile> -); echo "$a"
then my screen "flashes" before outputting the nicely format SQL.
Is there any way to remove this flash? Or is there a better using-vim-in-a-pipeline approach than what I'm employing?
ex
mode. It is possible to start vim inex
mode, and it is possible to switch to it after opening a file (:ex
). (:vi
will switch back to visual mode). I've never used ex mode, but it might be what you're looking for. Maybe replacingvim
in your command withex
would be enough?