├── README.markdown ├── doc └── hardy.txt ├── ftdetect └── arduino.vim ├── ftplugin └── arduino.vim ├── indent └── arduino.vim └── syntax └── arduino.vim /README.markdown: -------------------------------------------------------------------------------- 1 | vim-hardy 2 | ========= 3 | 4 | Introduction 5 | ------------ 6 | 7 | vim-hardy adds support for the Arduino language in vim. It covers syntax, 8 | compilation, and verification for Arduino code. I decided to call this plugin 9 | _"vim-hardy"_ because _"Arduino"_ means _"hardy friend"_ in italian. Note that I 10 | did not write the arduino syntax file, it was generated by Johannes Hoff's 11 | script which is available at [bitbucket.org/johannes/arduino-vim-syntax](http://bitbucket.org/johannes/arduino-vim-syntax). 12 | 13 | Requirements 14 | ------------ 15 | 16 | Arduino IDE version 1.5.0 and up is required for the compilation and uploading 17 | of Arduino code. By default, vim-hardy looks for it in your PATH, but you can 18 | specify an installation directory with `g:hardy_arduino_path`. 19 | 20 | Installation 21 | ------------ 22 | 23 | If you don't have a preferred installation method, I recommend installing 24 | [pathogen.vim](https://github.com/tpope/vim-pathogen), and then simply copy 25 | and paste: 26 | 27 | mkdir -p ~/.vim/bundle 28 | cd ~/.vim/bundle 29 | git clone git://github.com/4Evergreen4/vim-hardy.git 30 | 31 | Any other plugin managers should work as well, such as [vundle](https://github.com/gmarik/Vundle.vim) 32 | or [vim-plug](https://github.com/junegunn/vim-plug). 33 | 34 | Usage 35 | ----- 36 | 37 | To verify an Arduino file, run `:ArduinoVerify`. To compile and upload it, use 38 | `:ArduinoUpload`. 39 | 40 | Credits 41 | ------- 42 | 43 | * Johannes Hoff and contributers to vim-arduino-syntax - Created the arduino syntax file. 44 | 45 | License 46 | ------- 47 | 48 | vim-hardy is distributed under the same license as vim itself. See `:help license`. 49 | 50 | -------------------------------------------------------------------------------- /doc/hardy.txt: -------------------------------------------------------------------------------- 1 | *hardy.txt* Arduino language integration for vim 2 | 3 | Reference Manual ~ 4 | 5 | +----------------------------------------------------------------------------+~ 6 | CONTENTS *HardyContents* 7 | 8 | Introduction...................................|Hardy| 9 | Commands.......................................|HardyCommands| 10 | Options........................................|HardyOptions| 11 | Credits........................................|HardyCredits| 12 | Todo...........................................|HardyTodo| 13 | License........................................|HardyLicense| 14 | 15 | +----------------------------------------------------------------------------+~ 16 | INTRODUCTION *Hardy* 17 | 18 | vim-hardy adds support for the Arduino language in vim. I decided to name 19 | this plugin what it is, because Arduino means "hardy friend" in italian. Note 20 | that I did not write the arduino syntax file, it was generated by Johannes 21 | Hoff's script which is available here: 22 | http://bitbucket.org/johannes/arduino-vim-syntax 23 | 24 | +----------------------------------------------------------------------------+~ 25 | COMMANDS *HardyCommands* 26 | 27 | :ArduinoVerify *Hardy-:ArduinoVerify* 28 | Runs the arduino verifier on the current file. Opens a split which 29 | contains the output of the command once it is done. 30 | 31 | :ArduinoUpload *Hardy-:ArduinoUpload* 32 | Compiles and uploads the current file to an arduino board which is 33 | connected to your computer. The board which the code is uploaded to can 34 | be configured via the Arduino IDE interface, or it can be specifically set 35 | using |'g:hardy_arduino_options'|. 36 | 37 | +----------------------------------------------------------------------------+~ 38 | OPTIONS *HardyOptions* 39 | 40 | This script provides the following options for customizing hardy. These 41 | options should be set in your vimrc. 42 | 43 | #----------------------------------------------------------------------------#~ 44 | *'g:hardy_arduino_path'* 45 | Values: string 46 | Default: arduino 47 | 48 | Sets the path to the arduino IDE executable. By default, it is looked for in 49 | your PATH. 50 | 51 | #----------------------------------------------------------------------------#~ 52 | *'g:hardy_arduino_options'* 53 | Values: string 54 | Default: '' 55 | 56 | Any additional options to be passed to the arduino ide when uploading or 57 | verifying. 58 | 59 | #----------------------------------------------------------------------------#~ 60 | *'g:hardy_window_name'* 61 | Values: string 62 | Default: __Arduino_Info__ 63 | 64 | This option is used to set the name for the split window used to show the 65 | information outputed by the arduino ide. 66 | 67 | #----------------------------------------------------------------------------#~ 68 | *'g:hardy_window_size'* 69 | Values: Any non-negative integer 70 | Default: 15 71 | 72 | Sets the default window height/width used for the information window. If 73 | |'g:hardy_split_direction'| is '0' or '1', it is used for the height of the split. 74 | If the split direction is '2' or '3', it is used for the width. Setting this 75 | to 0 will use whatever the defualt behaviour is to set the split height/width. 76 | 77 | #----------------------------------------------------------------------------#~ 78 | *'g:hardy_split_direction'* 79 | Values: Any integer from 0 to 3 80 | Default: 0 81 | 82 | Sets the split direction used for creating the information window. '0' 83 | splits upwards, '1' splits downwards, '2' splits to the left, and '3' splits 84 | to the right. 85 | 86 | +----------------------------------------------------------------------------+~ 87 | CREDITS *HardyCredits* 88 | 89 | All credit goes to Johannes Hoff and contributers for the arduino syntax file. 90 | 91 | +----------------------------------------------------------------------------+~ 92 | TODO *HardyTodo* 93 | 94 | - Implement a basic serial monitor in vim using pyserial 95 | - Add command for creating new sketches 96 | 97 | +----------------------------------------------------------------------------+~ 98 | LICENSE *HardyLicense* 99 | 100 | Hardy is released under the same license as vim itself. See ':help license'. 101 | 102 | +----------------------------------------------------------------------------+~ 103 | 104 | vim:tw=78:ts=2:sw=2:sts=2:ft=help:norl: 105 | -------------------------------------------------------------------------------- /ftdetect/arduino.vim: -------------------------------------------------------------------------------- 1 | autocmd BufRead,BufNewFile *.pde,*.ino set filetype=arduino 2 | -------------------------------------------------------------------------------- /ftplugin/arduino.vim: -------------------------------------------------------------------------------- 1 | " File: arduino.vim 2 | " Description: Arduino language integration for vim 3 | " Maintainer: Evergreen 4 | " Last Change: July 27th, 2015 5 | " License: Vim License 6 | 7 | " SCRIPT INITIALIZATION {{{ 8 | if exists('b:did_ftplugin') 9 | finish 10 | endif 11 | 12 | let b:did_ftplugin = 1 13 | " }}} 14 | 15 | " SETTINGS {{{ 16 | if has("mac") 17 | let default_bin = "/Applications/Arduino.app/Contents/MacOS/Arduino" 18 | else 19 | let default_bin = "arduino" " In the $PATH 20 | endif 21 | 22 | let g:hardy_arduino_path = get(g:, 'hardy_arduino_path', default_bin) 23 | 24 | let g:hardy_arduino_options = get(g:, 'hardy_arduino_options', '') 25 | 26 | let g:hardy_window_name = get(g:, 'hardy_window_name', '__Arduino_Info__') 27 | 28 | let g:hardy_split_direction = get(g:, 'hardy_split_direction', 0) 29 | 30 | let g:hardy_window_size = get(g:, 'hardy_window_size', 15) 31 | " }}} 32 | 33 | " FUNCTIONS {{{ 34 | " Run arduino executable with a given command. Returns -1 if the DISPLAY 35 | " environment variable is not set. 36 | function! HardyRunArduino(command) 37 | if !exists("$DISPLAY") && !has("mac") 38 | echohl Error 39 | echom "Hardy: A graphical user interface such as X or OS X must be present" 40 | echohl Normal 41 | return -1 42 | endif 43 | 44 | let l:result = system(g:hardy_arduino_path . ' ' . g:hardy_arduino_options . 45 | \ ' ' . a:command) 46 | 47 | return l:result 48 | endfunction 49 | 50 | " Commands for use with each split direction 51 | let s:split_commands = [ 52 | \ 'aboveleft ', 'belowright ', 'vertical aboveleft ', 'vertical belowright '] 53 | 54 | " Show information in arduino window. 55 | function! HardyShowInfo(results) 56 | let l:winexists = bufwinnr(g:hardy_window_name) 57 | 58 | " Figure out whether to create a new window, or switch to an already 59 | " existing window. 60 | if l:winexists == -1 61 | " Create window according to all the user set options 62 | if g:hardy_split_direction < 0 || g:hardy_split_direction > 3 63 | echohl Error 64 | echom printf("Hardy: '%s' is not a valid split direction.", 65 | \ g:hardy_split_direction) 66 | echohl Normal 67 | let g:hardy_split_direction = 0 68 | endif 69 | 70 | if g:hardy_window_size < 0 71 | echohl Error 72 | echom printf("Hardy: '%s' is not a valid window size.", 73 | \ g:hardy_window_size) 74 | echohl Normal 75 | endif 76 | 77 | if g:hardy_window_size > 0 78 | execute s:split_commands[g:hardy_split_direction] . 79 | \ g:hardy_window_size . 'new '. g:hardy_window_name 80 | elseif g:hardy_window_size == 0 81 | execute s:split_commands[g:hardy_split_direction] . 'new ' . 82 | \ g:hardy_window_name 83 | endif 84 | 85 | " Set all the options for the newly created buffer 86 | setlocal filetype=arduinoinfo 87 | setlocal buftype=nofile 88 | else 89 | execute l:winexists . 'wincmd w' 90 | " Delete everything in the buffer 91 | normal! ggdG 92 | endif 93 | 94 | " Insert the resulting information 95 | call append(0, split(a:results, '\v\n')) 96 | endfunction 97 | 98 | " Verify the current file using arduino --verify 99 | function! HardyArduinoVerify() 100 | let l:result = HardyRunArduino('--verify ' . expand("%:p")) 101 | 102 | call HardyShowInfo(l:result) 103 | endfunction 104 | 105 | " Upload the current file using arduino --upload 106 | function! HardyArduinoUpload() 107 | let l:result = HardyRunArduino('--upload ' . expand("%:p")) 108 | 109 | call HardyShowInfo(l:result) 110 | endfunction 111 | " }}} 112 | 113 | " COMMANDS {{{ 114 | command! -buffer -nargs=0 ArduinoUpload call HardyArduinoUpload() 115 | command! -buffer -nargs=0 ArduinoVerify call HardyArduinoVerify() 116 | " }}} 117 | 118 | " vim: set sw=4 sts=4 et fdm=marker: 119 | -------------------------------------------------------------------------------- /indent/arduino.vim: -------------------------------------------------------------------------------- 1 | " File: arduino.vim 2 | " Description: Arduino language integration for vim 3 | " Maintainer: Evergreen 4 | " Last Change: July 16th, 2015 5 | " License: Vim License 6 | 7 | if exists("b:did_indent") 8 | finish 9 | endif 10 | let b:did_indent = 1 11 | 12 | " Arduino is just C with some additions, so C indentation will work fine 13 | setlocal cindent 14 | 15 | let b:undo_indent = "setl cin<" 16 | -------------------------------------------------------------------------------- /syntax/arduino.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: Arduino 3 | " Maintainer: Johannes Hoff 4 | " Last Change: 17 May 2015 5 | " License: VIM license (:help license, replace vim by arduino.vim) 6 | 7 | " Syntax highlighting like in the Arduino IDE 8 | " Automatically generated by the script available at 9 | " https://bitbucket.org/johannes/arduino-vim-syntax 10 | " Using keywords from /build/shared/lib/keywords.txt 11 | " From version: ARDUINO 1.6.4 - 2015.05.06 12 | 13 | " Thanks to Rik, Erik Nomitch, Adam Obeng, Graeme Cross and Niall Parker 14 | " for helpful feedback! 15 | 16 | " For version 5.x: Clear all syntax items 17 | " For version 6.x: Quit when a syntax file was already loaded 18 | if version < 600 19 | syntax clear 20 | elseif exists("b:current_syntax") 21 | finish 22 | endif 23 | 24 | " Read the C syntax to start with 25 | if version < 600 26 | so :p:h/cpp.vim 27 | else 28 | runtime! syntax/cpp.vim 29 | endif 30 | 31 | syn keyword arduinoConstant BIN CHANGE DEC DEFAULT EXTERNAL FALLING HALF_PI HEX 32 | syn keyword arduinoConstant HIGH INPUT INPUT_PULLUP INTERNAL INTERNAL1V1 33 | syn keyword arduinoConstant INTERNAL2V56 LOW LSBFIRST MSBFIRST OCT OUTPUT PI 34 | syn keyword arduinoConstant RISING TWO_PI 35 | 36 | syn keyword arduinoFunc analogRead analogReference analogWrite 37 | syn keyword arduinoFunc attachInterrupt bit bitClear bitRead bitSet 38 | syn keyword arduinoFunc bitWrite delay delayMicroseconds detachInterrupt 39 | syn keyword arduinoFunc digitalRead digitalWrite highByte interrupts 40 | syn keyword arduinoFunc lowByte micros millis noInterrupts noTone pinMode 41 | syn keyword arduinoFunc pulseIn shiftIn shiftOut tone yield 42 | 43 | syn keyword arduinoMethod available availableForWrite begin charAt compareTo 44 | syn keyword arduinoMethod concat end endsWith equals equalsIgnoreCase find 45 | syn keyword arduinoMethod findUntil flush getBytes indexOf lastIndexOf length 46 | syn keyword arduinoMethod loop parseFloat parseInt peek print println read 47 | syn keyword arduinoMethod readBytes readBytesUntil readString readStringUntil 48 | syn keyword arduinoMethod replace setCharAt setTimeout setup startsWith 49 | syn keyword arduinoMethod substring toCharArray toInt toLowerCase toUpperCase 50 | syn keyword arduinoMethod trim word 51 | 52 | syn keyword arduinoModule Keyboard Mouse Serial Serial1 Serial2 Serial3 53 | syn keyword arduinoModule SerialUSB 54 | 55 | syn keyword arduinoStdFunc abs accept acos asin atan atan2 ceil click constrain 56 | syn keyword arduinoStdFunc cos degrees exp floor isPressed log map max min 57 | syn keyword arduinoStdFunc move pow press radians random randomSeed release 58 | syn keyword arduinoStdFunc releaseAll round sin sq sqrt tan 59 | 60 | syn keyword arduinoType boolean byte null String word 61 | 62 | hi def link arduinoType Type 63 | hi def link arduinoConstant Constant 64 | hi def link arduinoStdFunc Function 65 | hi def link arduinoFunc Function 66 | hi def link arduinoMethod Function 67 | hi def link arduinoModule Identifier 68 | --------------------------------------------------------------------------------