Wednesday, December 4, 2013

Using Arduino with Janus Vim (conclusion, who knows how janus/pathogen work, just follow two-year old instructions)

Some time ago I set up my vim config. This is usually a full-day ordeal for some reason I don't remember. I don't recall exactly what I did, but everything works now, and I am very happy with how it functions. My previous experiences have left me very wary of "fixing anything that's not broken" in vim... but enh I want Arduino syntax highlighting in Vim now that there's the sweeeeet
File > Preferences > Use External Editor 
option in Arduino.

I think for the most part I just installed Janus:

and it has really great autosuggest that makes typing repetitive Arduino code 10x faster.

Lower left window: Autosuggest! So great~

Okay, so how to install Arduino syntax highlighting in Vim Janus setup?
There's this way that is pretty straightforward:

Just download file into a directory (in my case, ~/.vim/bundle) and add a line or two to .bashrc

nrw@nrw-PC:$ cd ~/.vim/bundle
nrw@nrw-PC:~/.vim/bundle$ git clone

Edit ~/.vimrc and append two lines:
autocmd! BufNewFile,BufRead *.pde setlocal ft=arduino                         
autocmd! BufNewFile,BufRead *.ino setlocal ft=arduino 

Voila! Done.

Below is a recounting of going down the rabbit-hole, if you ever wonder how I can spend a day on my vim config...
However, I feel like this isn't the cleanest way. So how does Vim/Janus handle syntax highlighting?

I feel like somewhere there is a folder of syntaxes that it handles.
Ah! using "locate .vim" I see that the folder is:

Should I just copy it there? Seems incorrect, I think I have to tell Janus somewhere to look for *.pde files.

Based on the pathogen documentation

It appears that I should git clone my .vim file to

cd ~/.vim/bundle
git clone

Nope! I don't have syntax highlighting after restarting vim (I double-checked with :scriptnames) . Perhaps install in .janus folder instead?
 cp ~/.vim/bundle/Arduino-syntax-file/ ~/.janus -r

Nerp still no syntax highlighting ;__; where do I tell it to look for both .ino and .pde files?

Hmm, it also appears that my Janus distribution is out-of-date based on the documentation (there is no NERDCommenter in my Janus as far as I can tell). But if I try to update
~/.vim\$ rake
/usr/local/bin/rake:9:in `require': no such file to load -- rubygems (LoadError)
    from /usr/local/bin/rake:9

Uh oh. I can feel the rabbit hole widening.

nrw@nrw-PC:~/.vim\$ which -a ruby

nrw@nrw-PC:~/.vim$ sudo update-alternatives --config ruby
There are 2 choices for the alternative ruby (providing /usr/bin/ruby).

  Selection    Path                Priority   Status
* 0            /usr/bin/ruby1.9.1   51        auto mode
  1            /usr/bin/ruby1.8     50        manual mode
  2            /usr/bin/ruby1.9.1   51        manual mode

Yep. Okay, so I need to nuke one of my versions.
 sudo apt-get remove ruby

which -a ruby

Hmm, still two versions. Well. *shrug* Let's just kill one version. Ugh. I bet this is leftovers from all the EdX stuff I did that never worked and I didn't really document because I was so frustrated.
AHHHH this is why I sometimes just NUCLEAR and reinstall my OS. Eheh. ^^;

Nooo nooo bad brain nooo it is 10 pm on a Wednesday night. It is NOT time to reinstall my OS. 

Okay. Screw not messing up my system, it's already screwed up.
1) Add execute pathogen#infect()     to my .vimrc

Error detected while processing /home/nrw/.vimrc:
line  134:
E117: Unknown function: pathogen#infect
E15: Invalid expression: pathogen#infect()

Okay... Maybe I'll just follow directions.
install details
Just put the file in your vimfiles/syntax folder. To automatically use it on PDE files, add the following line to your vimrc file (or e.g filetype.vim to install it for all users) :

autocmd! BufNewFile,BufRead *.pde setlocal ft=arduino
Okay.... I don't have a /syntax folder. What is going on? Uhh.

Well, I just put it into ~/.vim/bundle. And it works. ~__~ ah well. I guess I just have to follow instructions...

Colorize bash prompt

so now my ~/.bashrc just contains: 
if [ "\$color_prompt" = yes ]; then                                            
    PS1='\${debian_chroot:+(\$debian_chroot)}\u@\h:\w\$ '                       

For further reading:

Also, vim things I always forget:
To toggle whitespace,
:set list
:set nolist

To toggle linenumbers,
:set nu
:set nonu

To toggle paste-mode,
:set paste
:set nopaste

Leader key
let mapleader=","

So ",n" will open NerdTree.