6

HackerRank.com allows to solve their own set of programming problems with an online editor wich supports Emacs, Vim and 'Normal' modes.

The Vim mode can't really replace a customized local vim and after a while is very annoying.

I'm looking for a way to solve HRank problems from my local vim session and somehow submit the code through vim.

Already tried this plugins, with no success:

They don't seem to be active anymore.

I suspect it should be a very common problem. Any working solution around? Or suggestions?

Worst case scenario is to write it myself, but won't be my favourite task and I don't want to reinvent the wheel...

6

Disclaimer

I think the question is on topic for vi.SE because it is about doing something with Vim. I'm not so sure about my answer, however, since it focuses more on what to do outside of Vim, even if the purpose is to enable one to use Vim in the way requested. If the question were about Vimperator I gather it would be off topic, per this discussion, but does that mean that an answer suggesting it is "off topic" or inappropriate for this site? Maybe the mods could indicate whether this kind of answer is OK, and I can make edits accordingly.

Answer

There are browser plugins that allow you to edit text for a text area or field in an external editor. I am not familiar with the website in question, but if you have the option to make your submission by typing text into a HTML text are, then chances are you can use one of these plugins and do the editing in Vim.

I use Firefox with the Vimperator plugin and am typing this answer in Vim (MacVim). In my .vimperatorrc I have the following line, defining my external editor.

set editor="/usr/local/bin/mvim -f"

The -f flag is to prevent forking when running Vim with GUI ('f' is for 'foreground').

To begin editing with an external editor in Vimperator I navigate to the input control on the webpage and hit Ctrl-i. This opens a new MacVim window and I can do my editing. When I am done editing I write and quit the buffer (:wq), and the text is entered into the text area.

On vi.SE and other SE sites, as on many other websites with WYSIWYG editors, the page defines some access keys of its own upon load. Particularly, for SE sites, Ctrl-i is overridden to insert *emphasized text*. In order to get around this I have an additional mapping in my .vimperatorrc

inoremap <Leader>i <C-i>

My <Leader> key is - so I can then use -i to do the above.

Vimperator is a "vimitator" that lets you navigate and to some degree script the browser in a Vimlike fashion and the ability to use an external editor is only a minor feature. There are other plugins which focus particularly on that and if you are not keen on the rest of Vimperator's features you may want to look into one of those. (I believe there is one called "It's all text" that seems popular).

2
  • 2
    Great you solved the annoying *emphasized txt* on StackOverflow edits. It would deserve separate question and aswer as I guess on StackOverflow will be many programmers using vim with vimperator. – Jan Vlcinsky Jan 26 '16 at 21:35
  • 1
    see my question vi.stackexchange.com/questions/6268/…. I would like you to put your answer there to make it easier to find it. – Jan Vlcinsky Jan 26 '16 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.