Running Vim via Lua

I am writing a small small Lua command-line application that will build a static website. I store my fragments in a sqlite database. Retrieving data from db is simple as it is saved; My question comes from data editing.

Is there an elegant way to transfer data from Lua to vim? Can vim edit the memory buffer and return it? I planned to start the editor through os.execute ('vim'), but only after capturing a temporary file descriptor and unloading the database. I would like this not to apply to the file system, but this is my contingency plan.

+3
source share
3 answers

The only way I know to achieve what you want is to select a temporary file and edit it. In fact, I would not worry about touching the file system: if your data is small, you can hope that the operating system saves it in the memory cache and writes bits to the disk only during the rest of the idle cycles.

Some systems offer parts of the file system that are guaranteed to be stored in RAM, but this is very unsportsmanlike.

+2
source

You can pass text to vim using stdin (for example, echo 'Hello, world!' | vim -), but I'm not sure how to submit edited results to stdout. So, the first part of the solution in lua:

local vim = io.popen('vim -', 'w')
vim:write('Hello, world!')

, , ?

+1

io.tmpfile; os.getenv( EDITOR, vi (m)); , ...

+1

Source: https://habr.com/ru/post/1743243/


All Articles