[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
examples of m4 with vim
From: |
Marc Chantreux |
Subject: |
examples of m4 with vim |
Date: |
Mon, 17 Aug 2020 11:34:44 +0200 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
hi,
On Sun, Aug 16, 2020 at 05:51:50PM -0700, M.R.P. zensky wrote:
> Hello I am wondering if m4 can be used with the text editor vim?
as vim is a text editor and m4 is a text processor, the anwser is yes.
> How would this be implemented?
i guess the question is 'how to use m4 from vi(m)?'.
vi provides the ability to use pipes (noted !) to write, read and filter
(read :help !). So imagine you have a `startmemo' file in your M4PATH
with this code:
ifdef(`TL',,`define(`TL',`my title here')')dnl
.`T'L TL
.AST résumé
.AS
.AE
from vi, you can type this command:
:r !m4 -DTL="my humble contrib" startmemo
to get this in your buffer
.TL my humble contrib
.AST résumé
.AS
.AE
so if you have a file memohelpers with
define(`memo',`.TL $1
.AST résumé
.AS
.AE')dnl
then you can write into your vim buffer
memo(`the power of small things')
then filter it with
:.!m4 memohelpers -
to get
hello
.TL the power of small things
.AST résumé
.AS
.AE
you can also write in a pipe to print some informations:
this command shows basic stats on your file (the buffer remains
untouched).
%w !awk '/^[^.]/ {words+=NF} END {print words" words, "NR" lines"}'
HTH
regards,
marc