Last active
April 16, 2024 05:19
-
-
Save Konfekt/52efaf7d9ee84d7f87f95fc6748e170b to your computer and use it in GitHub Desktop.
Add evaluation of selected code as comment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" From https://old.reddit.com/r/neovim/comments/1c3gf93/commentreplnvim_run_code_from_your_buffer_and/ | |
" | |
" Add the following lines to `ftplugin/{python,sh,zsh,lua,perl, ...}.vim | |
" and call :EvaluateAsComment to add the evaluation of the selected lines as a comment: | |
" | |
" print(1+2) | |
" | |
" becomes | |
" | |
" # 3 | |
" print(1+2) | |
" | |
" Alternatively, https://github.com/gpanders/vim-medieval evaluates code in a (markdown) code block | |
let b:evaluator = &filetype | |
command! -buffer -range -bar EvaluateAsComment | |
\ silent <line1>,<line2>copy<line2> | | |
\ exe "<line1>,<line2>!"..b:evaluator.." | sed 's/^.*$/"..printf(escape(&commentstring, '\/.*^$[]#'), '\0').."/'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment