Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Evaluate Markdown code blocks within Vim (github.com/gpanders)
68 points by pentestercrab 8 months ago | hide | past | favorite | 18 comments


Related: I found out about a vim/neovim plugin called Molten[1] that tries to be a replacement for Jupyter Notebooks in the terminal. It was a little rough around the edges ~5 months ago when I tried it, but looking at the repo it seems its still being actively developed, so maybe that's changed. IIRC it uses an ipynb server to keep track of each cell's outputs. I quite enjoyed using it as someone who doesn't need notebooks very often and loathes leaving my terminal setup.

[1] https://github.com/benlubas/molten-nvim



How can you execute the current buffer line as a vim command? I have this shortcut on one of my machines, but it's really tough to search the Internet for.

It's so useful for one-off report generation, I use it daily on my (last remaining) Windoze machine.

Vomscript isn't that bad! Not any worse than Bash, haha. It turns out that you can get plenty done with only arrays and without a native Map data structure. If you get desperate, use SQLite. *Grin*


Another way:

    yy@"
In other words, execute the " register (what you just copied) as a macro. In the same vein, yy@0 would work as well (the 0 register is the last yank).

Also, what do you mean without a native map structure? Vimscript has Dictionaries just fine.


This should do it (without the spaces):

   : C-r C-l <Enter>
The `C-l` buffer is the line you are currently on in command mode. (Might be in other modes too.)


Bravo!


I like the feature that allows you to put a block's output into another block. I've been toying with the idea of self-modifying/self-introspecting documents for some time, and I think they're a good concept for ad-hoc files in the space between prose, scripts, and databases.


What I really want is a Notebook experience for the terminal, but output is for each command is automatically stored in separate buffers.

Then I can tweak commands, or chain the input from the buffers. (automatically using mkfifo or something)

I want my command to history stored in another buffer, and another buffer that I can quickly move the commands and/or output to a script or a markdown document for documentation.

That way I can quickly debug or build scripts, or perform analysis, and it will automatically have an executable to reproduce all my steps.


Org Babel: “Because the return value of a function written in one language can be passed to a function written in another language, or to an Org table, which is itself programmable, Babel can be used as a meta-functional programming language. With Babel, functions from many languages can work together. You can mix and match languages, using each language for the tasks to which it is best suited.”

https://orgmode.org/worg/org-contrib/babel/intro.html

Jupyter is one of the supported languages.

https://github.com/emacs-jupyter/jupyter?tab=readme-ov-file#...


I created something similar in emacs for markdown [1,2]. The real feature needed is to connect to ipython, so images etc can be embedded into the markdown file as a image link. Don't know how to do this.

[1] https://gist.github.com/abdullahkhalids/83055b1abbd2cdf2416a...

[2] Yes, I know about org-mode and I do use it.


I use comint-mime [0] to show images in IPython buffers started with `M-x run-python`.

[0]: https://github.com/astoff/comint-mime


Thank you. This is very nice. The short code is very readable and tells me how to integrate ipython correctly.


Mdsh also works great in CI-like context[1], but I don't think it can eval per block. Definitely trying out medieval for those odd "I want to run this one thing from a README but I don't wanna leave vim" cases.

[1]: https://github.com/zimbatm/mdsh


I’m going to link to my own comment here: https://news.ycombinator.com/item?id=41945124

This is super easy in kakoune, requires few keystrokes and no customization, and can be done in any kind of buffer.


The “Handy Dandy Notebook” is similar for VS Code, with support for Knuthian literate programming.


Have to install to check if there is a config to execute on every keystroke (thats reasonable, right?)


This is definitely helpful! Thank you for building it : )


looks like a nice tool for evaluating code blocks directly in Vim's Markdown buffers, and the ability to redirect outputs into named blocks is a cool way to keep everything contained in the editor. If you're looking for something similar but more versatile across different environments, check out *Cog*. It embeds executable code in any text file and inserts the output back into the document, which is great for automating documentation outside of Vim, especially in CI pipelines.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: