Skip to content

Instantly share code, notes, and snippets.

Created March 29, 2023 09:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
GPT-4 AsyncRun custom handler function for sending output to the buffer rather than the QuickFix window (seems hallucinated). Kind of close to a "custom runner" in but I can't see which ones get data from the process output, so unsure which type of runner to adapt
You can customize the behavior of the AsyncRun plugin to insert the output into the current buffer by using a custom handler function.
Follow these steps to set up the custom handler:
- In your .vimrc, add the following function:
function! MyAsyncHandler(job, data) abort
let l:lines = split(a:data, "\n")
call append(line('$'), l:lines[:-2])
call cursor(line('$'), 0)
This function takes the job ID and data as input, splits the data into lines, appends the lines to the current buffer, and moves the cursor to the last line.
- Configure AsyncRun to use the custom handler by adding the following line to your .vimrc:
let g:asyncrun_handler = function("MyAsyncHandler")
- Open Vim and create a new buffer to receive the streamed data. You can do this by typing :e stream_buffer.txt in normal mode.
- Run the following command in Vim to execute your Python script asynchronously and read the output into the current buffer:
:AsyncRun -mode=term python3 stream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment