David Hilbert David Hilbert -4 years ago 94
Python Question

Implement a macro in the config file

With Vim, I'd like to create a permanent, stable macro which would display
#===================================================================
MACRO IPYTHON.EMBED()
#===================================================================
import IPython
IPython.embed()

However, I am not an expert how to do such thing. I know we must implement that into the

.vimrc
file. Could anyone be able to help me doing such thing?

Thanks!

Answer Source

Look into the UltiSnips plugin. After installing this plugin, add the following lines to the python.snippet file:

snippet ipyembed "IPython Embed"
    #===================================================================
    MACRO IPYTHON.EMBED()
    #===================================================================
    import IPython
    IPython.embed()
endsnippet

After that is done, typing out ipyembed into a .py file followed by a <Tab> (while in insert mode) should produce the lines your looking for.

You may need to add the following lines to your vimrc to set <Tab> as the expand trigger, but I believe <Tab> should be the default anyway:

let g:UltiSnipsExpandTrigger="<tab>"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download