# Vim plugin to compile/run code using API

DevFeed: [Vim plugin to compile/run code using API](<https://devfeed.tech/articles/vim-plugin-to-compile-run-code-using-api-19976.md>)

Original publisher: [Read original article](<http://engineering.hackerearth.com/2013/03/11/hackerearth-vim-plugin/>)

Published: 2013-03-11T00:00:00Z

Content type: tutorial

Language: en

Sources: [HackerEarth](<https://devfeed.tech/sources/hackerearth.md>)

Topics: [Vim](<https://devfeed.tech/topics/vim.md>), [API](<https://devfeed.tech/topics/api.md>), [Python](<https://devfeed.tech/topics/python.md>), [Code](<https://devfeed.tech/topics/code.md>), [Object-oriented programming (OOP)](<https://devfeed.tech/topics/oop.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [code](<https://devfeed.tech/tags/code.md>), [oop](<https://devfeed.tech/tags/oop.md>), [plugin](<https://devfeed.tech/tags/plugin.md>), [python](<https://devfeed.tech/tags/python.md>), [tutorials](<https://devfeed.tech/tags/tutorials.md>)

## AI overview

This tutorial describes building a Vim plugin that uses the HackerEarth API to compile and run code. It introduces VimL and Python integration, plugin checks for Python support and an API client key, and an object-oriented design with Api, Argument, and VimInterface classes. The article also discusses mapping plugin commands to keyboard shortcuts.

## Source excerpt

tl;dr Check out https://github.com/HackerEarth/hackerearth.vim I love Vim editor. And the idea of a plugin to compile and run code from my favorite code editor sounded exciting. HackerEarth API made it easier. Oh man - this is going to be the coolest thing I have ever built. Whoa, wait a minute. Aren't you forgetting something? You have never written a plugin before. There always comes a time when you have to do something for the first time! ;) Where to begin? Google is the answer :) After exploring and reading some tutorials, I found out that VimL, also know as Vim script is the language used to built vim plugins. Here's the best part. You only need very little knowledge of VimL to be able to write plugins, if you know Python (or Ruby). I chose Python. Why Python? Because using python gives so much flexibility. Think about using urllib/httplib/json/vim for accessing some web service that helps editing in Vim. This is why most of the plugins that work with web services are usually done in VimL+Python. Also, I am learning Python these days so it became a more solid reason to use it. Let's write a vim plugin! Generally vim plugins start with few checks. In this case, it checks for VimL + Python support and also looks for HackerEarth API client key. Obviously, if there is some error, plugin should not be loaded. " check for python if !has('python') echoerr "HackerEarth: Plugin needs to be compiled wuth python support." finish endif " check for client key if exists("g:HackerEarthApiClientKey") let s:client_key = g:HackerEarthApiClientKey else echoerr "You need to set client key in your vimrc file" finish endif As said earlier, Python can easily be integrated with VimL. Python code inside VimFunction starts after python " EOF and ends before EOF. Here is an example on how to do it. function! s:VimFunction() python << EOF # write python code here import os print "Hello World!" EOF endfunction OOPS! I have written most of the plugin code in Python and I love using Object O