简体   繁体   中英

Run Prolog code through Vim editor

I have installed SWI-Prolog and an editor. I am currently writing and running the code using them. Lately I started working using the Vim editor, so I would like to ask, how can I run the Prolog code from Vim? Obviously I don't ask how can Vim run the code because it is just an editor not an IDE, I am asking how can I do it like when you run C or Python code from Vim.

Running Prolog code from Vim requires loading your Prolog program and a Prolog query to execute using that program. For example, if your query is a call to the predicate main/0 , then you could add to your ~/.vimrc file something like:

map <F5> <ESC>:w<CR>:exec '!swipl -g "consult(''%''), main, halt"'<CR>

This, with your Prolog program in the current Vim buffer, pressing the function key F5 would save it to disk, consult it with SWI-Prolog, call the goal main , and terminate the Prolog section (due to the call to the halt/0 predicate).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM