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?
pg-recreate-view? If it is using Vim somehow, you might want to use the-Nesoptions with it. – muru Feb 13 '17 at 04:46psqlcall. – magnus Feb 13 '17 at 04:52CREATE OR REPLACE VIEWstatement with the following keystrokes in vim:" - First sentence right after the second big preformatted block. – 8bittree Feb 13 '17 at 16:47a=$(psql ... | vim -s ... -)) then echoing that value causes the screen to flash. I think I must be doing something wrong. – magnus Feb 13 '17 at 21:51exmode. It is possible to start vim inexmode, and it is possible to switch to it after opening a file (:ex). (:viwill switch back to visual mode). I've never used ex mode, but it might be what you're looking for. Maybe replacingvimin your command withexwould be enough? – jpaugh Jul 17 '17 at 20:02