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:
https://github.com/carlhuda/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:
https://github.com/vim-scripts/Arduino-syntax-file

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 https://github.com/vim-scripts/Arduino-syntax-file.git

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:
/usr/share/vim/vim73/syntax/

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
https://github.com/tpope/vim-pathogen

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

cd ~/.vim/bundle
git clone https://github.com/vim-scripts/Arduino-syntax-file.git

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.
http://stackoverflow.com/questions/2896485/no-such-file-to-load-rubygems-loaderror

nrw@nrw-PC:~/.vim\$ which -a ruby
/usr/bin/ruby
/home/nrw/.rvm/bin/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
/usr/bin/ruby
/home/nrw/.rvm/bin/ruby

http://learnvimscriptthehardway.stevelosh.com/chapters/43.html

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

NOPE
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
https://help.ubuntu.com/community/CustomizingBashPrompt

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

For further reading:
http://www.reddit.com/r/programming/comments/697cu/bash_users_what_do_you_have_for_your_ps1/

===
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
stackoverflow.com/questions/1764263/what-is-the-leader-in-a-vimrc-file
let mapleader=","

So ",n" will open NerdTree.

No comments:

Post a Comment