Can we capture a screenshot of vim window using Terminal? Let's say I have a file called hello.py.

# File: ~/hello.py
print('Hello')
print('Stack Exchange')


I would like to get a screencapture of hello.py when opened in vim editor as the ~/hello.png.

Need
Needed is a script called highlighter.sh which can do this. 

bash highlighter.sh hello.py # should give hello.png with 
                             # syntax highlight
# For example when we open hello.py in vim
# It gives syntax-highlighted code, I need
# screencapture of this tab or window.
# In the end of command these tab or window should be closed.


Usage

We will have syntax highlighted png files for all the scripts which we can quickview in Mac.

Updates so far

Open the terminal # or, cd ~
vi hello.py
cmd t # opens new tab
screencapture -l$(osascript -e 'tell app "Terminal" to id of window 1') hello1.png  # this captures this command, not the screen of vim tab.


Related links:
https://github.com/thismachinechills/pyscreencapture
https://github.com/vorgos/QuickGrab
https://github.com/smokris/GetWindowID
Take a screenshot of the top-most window
By combining the built-in screencapture with osascript -e you should be able to perform the following:

screencapture -l$(osascript -e 'tell app "Terminal" to id of window 1') hello1.png

If you have more than one Terminal window currently open you'll need to adjust the windowID value.