├── .gitignore ├── Javacomplete2.makefile ├── Makefile ├── README.md ├── Snipmate.makefile ├── adbLogCat ├── Makefile ├── doc │ └── adblogcat.txt └── plugin │ └── adblogcat.vim ├── android-install.sh └── findAndroidManifest ├── Makefile ├── after └── ftplugin │ └── java.vim ├── doc └── java.txt └── findmanifest.vmb /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | -------------------------------------------------------------------------------- /Javacomplete2.makefile: -------------------------------------------------------------------------------- 1 | SHELL=/bin/bash 2 | 3 | all:dist 4 | 5 | dist: 6 | @rm javacomplete.vmb 2> /dev/null || true 7 | @vim -c 'r! find doc autoload -type f' \ 8 | -c '$$,$$d _' -c '%MkVimball javacomplete . ' -c 'q!' 9 | 10 | clean: 11 | @rm -R build 2> /dev/null || true 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL=/bin/bash 2 | 3 | all: dist 4 | 5 | dist: javacomplete2/Makefile snipmate/Makefile 6 | @$(MAKE) -C supertab 7 | @$(MAKE) -C findAndroidManifest 8 | @$(MAKE) -C javacomplete2 9 | @$(MAKE) -C snipmate 10 | @$(MAKE) -C adbLogCat 11 | 12 | javacomplete2/Makefile: Javacomplete2.makefile 13 | @cp $< $@ 14 | 15 | snipmate/Makefile: Snipmate.makefile 16 | @cp $< $@ 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-android 2 | Develop for Android using vim. 3 | 4 | ## Overview 5 | There are three vim scripts that are included in this setup. Those scripts are: 6 | 1. SuperTab 7 | - [GitHub](https://github.com/ervandew/supertab.git) 8 | - [Vim.org](http://www.vim.org/scripts/script.php?script_id=1643) 9 | 10 | SuperTab allows us to autocomplete with the tab key. 11 | 2. snipMate 12 | - [GitHub](https://github.com/garbas/vim-snipmate.git) 13 | - [Vim.org](http://www.vim.org/scripts/script.php?script_id=2540) 14 | 15 | snipMate gives us the ability to add some abilities of the text editor TextMate. 16 | 17 | 3. javacomplete2 18 | - [GitHub](https://github.com/artur-shaik/vim-javacomplete2.git) 19 | - [Vim.org](http://www.vim.org/scripts/script.php?script_id=5181) 20 | 21 | Javacomplete does the omnicompletion for the java and android classes/functions. 22 | 23 | ## How it works 24 | findAndroidManifest is a custom vim script that uses python to do the heavy lifting. 25 | This script will try and find an AndroidManifest.xml file in the current directory. If 26 | the file is not found in the current directory. It will serach up the directory tree 27 | until it finds one or it hits the root directory. Everytime vim is started up and a 28 | java file is detected, the script is ran to find the AndroidManifest.xml. If the 29 | manifest file is found, it will detect the version of android that you are targeting. 30 | It then adds the jar file for the target version of android to the classpath. This 31 | way javacomplete can omnicomplete android classes/functions. The way omnicompletion 32 | works is by pressing either the tab key or `[Ctrl + X]` and `[Ctrl + U]`. 33 | 34 | adblogcat is another custom vim script that uses some python. The current binding 35 | to use this script is . Pressing loads up a preview window with the output 36 | of `adb logcat`. The output of `adb logcat` is piped out to a file in the /tmp directory. 37 | The exact file is /tmp/adb-logcat-output.adb. The preview window is loaded up with this 38 | file. The preview window will be updated every second. As of right now, while the preview 39 | window is opened, you cannot edit the file you are working on. Before the preview window 40 | is updated, it jumps back to preview buffer and then updates. To turn this off and stop 41 | `adb logcat` hit again. 42 | 43 | ## Requirements 44 | - ctags 45 | - Vim with Python bindings 46 | - Python 47 | - Android SDK 48 | - make 49 | - git 50 | 51 | ## Installation 52 | First-time installation: 53 | ```bash 54 | chmod +x android-install.sh 55 | ./android-install.sh 56 | ``` 57 | 58 | The installer for this setup generates a ctags file that is placed in your ~/.vim folder. 59 | This is only ran once. Anytime that the Android SDK is updated you should run the following command: 60 | 61 | ```bash 62 | ctags --recurse --langmap=Java:.java --languages=Java --verbose -f ~/.vim/tags $ANDROID_SDK/sources 63 | ``` 64 | 65 | This is what javacomplete uses for the android omnicompletion. 66 | 67 | 68 | -------------------------------------------------------------------------------- /Snipmate.makefile: -------------------------------------------------------------------------------- 1 | SHELL=/bin/bash 2 | 3 | all:dist 4 | 5 | dist: 6 | @rm snipmate.vmb 2> /dev/null || true 7 | @vim -c 'r! find after autoload doc ftplugin plugin snippets syntax -type f' \ 8 | -c '$$,$$d _' -c '%MkVimball snipmate . ' -c 'q!' 9 | 10 | clean: 11 | @rm -R build 2> /dev/null || true 12 | -------------------------------------------------------------------------------- /adbLogCat/Makefile: -------------------------------------------------------------------------------- 1 | SHELL=/bin/bash 2 | 3 | all:dist 4 | 5 | dist: 6 | @rm adblogcat.vmb 2> /dev/null || true 7 | @vim -c 'r! find doc plugin -type f' \ 8 | -c '$$,$$d _' -c '%MkVimball adblogcat . ' -c 'q!' 9 | 10 | clean: 11 | @rm -R build 2> /dev/null || true 12 | -------------------------------------------------------------------------------- /adbLogCat/doc/adblogcat.txt: -------------------------------------------------------------------------------- 1 | Description: 2 | This plugin will start adb with the logcat option and pipe the output to 3 | /tmp/adb-logcat-output.adb by default. That file then is loaded into a preview 4 | window. The preview window will reload the contents of 5 | /tmp/adb-logcat-output.adb and scroll to the last line of the buffer 6 | automatically. To start and turn off this process press in normal mode. 7 | 8 | 1. Requirements: 9 | 1. Vim 7.0+ 10 | 2. Python 11 | 3. Vim with python bindings 12 | 13 | 2. Install: 14 | vim /path/to/adblogcat.vim -c "so %" -c "q!" 15 | -------------------------------------------------------------------------------- /adbLogCat/plugin/adblogcat.vim: -------------------------------------------------------------------------------- 1 | if exists('g:AdbLogCat_Loaded') 2 | finish 3 | endif 4 | let g:AdbLogCat_Loaded = 1 5 | 6 | if !exists('s:AdbLogCat_IsRunning') 7 | let s:AdbLogCat_IsRunning = 0 8 | endif 9 | 10 | if !exists('s:AdbLogCat_PrevWinHeight') 11 | let s:AdbLogCat_PrevWinHeight = 15 12 | endif 13 | 14 | if !exists('s:AdbLogCat_LogFileLoc') 15 | let s:AdbLogCat_LogFileLoc = '/tmp/adb-logcat-output.adb' 16 | endif 17 | 18 | python << endpython 19 | import vim 20 | import threading 21 | from threading import Thread 22 | from time import sleep 23 | 24 | class UpdatePrevWin(Thread): 25 | def __init__(self): 26 | self.cont = True 27 | Thread.__init__(self) 28 | 29 | def run(self): 30 | while self.cont: 31 | vim.command("silent! wincmd P") 32 | vim.command("silent execute 'pedit!'") 33 | vim.command("normal G") 34 | sleep(1) 35 | 36 | def stop(self): 37 | self.cont = False 38 | 39 | def restart(self): 40 | self.cont = True 41 | 42 | update = UpdatePrevWin() 43 | endpython 44 | 45 | nmap :call ToggleAdbLogCat() 46 | 47 | function! ToggleAdbLogCat() 48 | if s:AdbLogCat_IsRunning == 0 "Not running 49 | call AdbLogCat() 50 | call TailFile() 51 | else "Is running 52 | call TailFile_Stop() 53 | endif 54 | endfunction 55 | 56 | function! AdbLogCat() 57 | silent execute ':!adb logcat > ' . s:AdbLogCat_LogFileLoc . '&' 58 | endfunction 59 | 60 | function! TailFile() 61 | if !filereadable(s:AdbLogCat_LogFileLoc) 62 | echohl ErrorMsg | echo "Cannot open file for readins: " . s:AdbLogCat_LogFileLoc | echohl None 63 | return 64 | endif 65 | 66 | pclose "close prevwin if one is already opened. 67 | if bufexists(bufnr(s:AdbLogCat_LogFileLoc)) 68 | execute ':' . bufnr(s:AdbLogCat_LogFileLoc) . 'bwipeout' 69 | endif 70 | 71 | augroup TailFile 72 | execute "autocmd BufWinEnter " . s:AdbLogCat_LogFileLoc . " call TailFile_Setup()" 73 | augroup END 74 | 75 | silent execute s:AdbLogCat_PrevWinHeight . "new " . s:AdbLogCat_LogFileLoc 76 | call TailFile_Start() 77 | endfunction 78 | 79 | function! TailFile_Setup() 80 | setlocal noswapfile 81 | setlocal noshowcmd 82 | setlocal bufhidden=delete 83 | setlocal nobuflisted 84 | setlocal nomodifiable 85 | setlocal nowrap 86 | setlocal nonumber 87 | setlocal previewwindow 88 | 89 | wincmd P 90 | normal G 91 | endfunction 92 | 93 | function! TailFile_Start() 94 | let s:AdbLogCat_IsRunning = 1 95 | python << endpython 96 | update.start() 97 | endpython 98 | endfunction 99 | 100 | function! TailFile_Stop() 101 | python << endpython 102 | update.stop() 103 | endpython 104 | let s:AdbLogCat_IsRunning = 0 105 | silent execute "!ps aux | grep 'adb logcat' | grep -v 'grep' | awk '{print $2}' | xargs kill" 106 | redraw! 107 | endfunction 108 | 109 | function! TailFile_Restart() 110 | call AdbLogCat() 111 | call TailFile() 112 | python << endpython 113 | update.restart() 114 | update.run() 115 | endpython 116 | let s:AdbLogCat_IsRunning = 1 117 | endfunction 118 | -------------------------------------------------------------------------------- /android-install.sh: -------------------------------------------------------------------------------- 1 | #/usr/bin/env sh 2 | 3 | echo "[INFO] Checking for ctags." 4 | command -v ctags > /dev/null 2>&1 || { echo >&2 "[ERR] ctags not found. Please install ctags.\nhttp://ctags.sourceforge.net/"; exit 1; } 5 | 6 | echo "[INFO] Checking for ANDROID_SDK env variable." 7 | if [ ! "$ANDROID_SDK" = "" ]; then 8 | if [ ! -d "$ANDROID_SDK" ]; then 9 | echo "[ERR] "$ANDROID_SDK" does not exist." 10 | else 11 | echo "[INFO] ANDROID_SDK set to "$ANDROID_SDK"" 12 | fi 13 | else 14 | echo "[ERR] ANDROID_SDK not set." 15 | fi 16 | 17 | echo "[BUILDING] Creating tags file for android." 18 | if ! ctags --recurse --langmap=Java:.java --languages=Java --verbose -f ~/.vim/tags $ANDROID_SDK/sources 19 | then 20 | echo "[ERR] ctags failed. Trying again with ctags-exuberant" 21 | if ! ctags-exuberant --recurse --langmap=Java:.java --languages=Java --verbose -f ~/.vim/tags $ANDROID_SDK/sources 22 | then 23 | echo "[ERR] ctags-exuberant failed. Now exiting..." 24 | exit 1 25 | fi 26 | fi 27 | 28 | echo "[VIM] Adding things to ~/.vimrc" 29 | echo "\"Added by android-vim:" >> ~/.vimrc 30 | echo "set tags+=`echo ~`/.vim/tags" >> ~/.vimrc 31 | echo "autocmd Filetype java setlocal omnifunc=javacomplete#Complete" >> ~/.vimrc 32 | echo "let g:SuperTabDefaultCompletionType = 'context'" >> ~/.vimrc 33 | 34 | echo "[INFO] Cloning Supertab" 35 | git clone git://github.com/ervandew/supertab.git supertab 36 | echo "[INFO] Cloning snipMate" 37 | git clone git://github.com/garbas/vim-snipmate.git snipmate 38 | echo "[INFO] Cloning javacomplete2" 39 | git clone git://github.com/artur-shaik/vim-javacomplete2.git javacomplete2 40 | 41 | echo "[BUILDING] Creating vimballs" 42 | make 43 | 44 | echo "[INSTALLING] Installing Supertab, snipMate, javacomplete2, and findAndroidManifest" 45 | vim findAndroidManifest/findmanifest.vmb -c 'so %' -c 'q!' 46 | vim supertab/supertab.vmb -c 'so %' -c 'q!' 47 | vim javacomplete2/javacomplete.vmb -c 'so %' -c 'q!' 48 | vim snipmate/snipmate.vmb -c 'so %' -c 'q!' 49 | vim adbLogCat/adbLogCat.vmb -c 'so %' -c 'q!' 50 | -------------------------------------------------------------------------------- /findAndroidManifest/Makefile: -------------------------------------------------------------------------------- 1 | SHELL=/bin/bash 2 | 3 | all:dist 4 | 5 | dist: 6 | @rm findmanifest.vmb 2> /dev/null || true 7 | @vim -c 'r! find doc after -type f' \ 8 | -c '$$,$$d _' -c '%MkVimball findmanifest . ' -c 'q!' 9 | 10 | clean: 11 | @rm -R build 2> /dev/null || true 12 | -------------------------------------------------------------------------------- /findAndroidManifest/after/ftplugin/java.vim: -------------------------------------------------------------------------------- 1 | function! FindManifestFile() 2 | python << endpython 3 | 4 | import vim 5 | import os 6 | 7 | def find_manifest(path): 8 | found = False 9 | 10 | dirs = os.listdir(path) 11 | for d in dirs: 12 | if d=='AndroidManifest.xml': 13 | found = True 14 | 15 | return found 16 | 17 | found = False 18 | old_dir = pwd = os.getcwd() 19 | 20 | found = find_manifest(pwd) 21 | 22 | while not found: 23 | if pwd=='/': 24 | break 25 | os.chdir(pwd+'/..') 26 | pwd = os.getcwd() 27 | found = find_manifest(pwd) 28 | 29 | if found: 30 | ANDROID_SDK = os.environ['ANDROID_SDK'] 31 | if ANDROID_SDK=='': 32 | exit(1) 33 | 34 | cmd = "let s:androidSdkPath = '" + ANDROID_SDK + "'" 35 | vim.command(cmd) 36 | cmd = "vimgrep /target=/j " + pwd + "/project.properties" 37 | vim.command(cmd) 38 | vim.command("let s:androidTargetPlatform = split(getqflist()[0].text, '=')[1]") 39 | vim.command("let s:targetAndroidJar = s:androidSdkPath . '/platforms/' . s:androidTargetPlatform . '/android.jar'") 40 | target = vim.eval("s:targetAndroidJar") 41 | cmd = "let $CLASSPATH = '" + target + "'" 42 | vim.command(cmd) 43 | 44 | os.chdir(old_dir) 45 | endpython 46 | endfunction 47 | 48 | call FindManifestFile() 49 | -------------------------------------------------------------------------------- /findAndroidManifest/doc/java.txt: -------------------------------------------------------------------------------- 1 | Description: 2 | When a java file is detected, try and find an AndroidManifest.xml file. If the 3 | file is not found in the current directory, it will search in the directory 4 | above until it hits the root directory. If the file is found, read the 5 | project.properties file to find the target version of android. The class path 6 | is set to the target version of the Android SDK. 7 | 8 | 1. Requirements: 9 | 1. Vim 7.0+ 10 | 2. Python 11 | 3. Vim with python bindings 12 | 13 | 2. Install: 14 | vim /path/to/java.vim -c "so %" -c "q!" 15 | -------------------------------------------------------------------------------- /findAndroidManifest/findmanifest.vmb: -------------------------------------------------------------------------------- 1 | " Vimball Archiver by Charles E. Campbell, Jr., Ph.D. 2 | UseVimball 3 | finish 4 | after/ftplugin/java.vim [[[1 5 | 46 6 | function! FindManifestFile() 7 | python << endpython 8 | 9 | import vim 10 | import os 11 | 12 | def find_manifest(path): 13 | found = False 14 | 15 | dirs = os.listdir(path) 16 | for d in dirs: 17 | if d=='AndroidManifest.xml': 18 | found = True 19 | 20 | return found 21 | 22 | found = False 23 | pwd = os.getcwd() 24 | 25 | found = find_manifest(pwd) 26 | 27 | while not found: 28 | if pwd=='/': 29 | break 30 | os.chdir(pwd+'/..') 31 | pwd = os.getcwd() 32 | found = find_manifest(pwd) 33 | 34 | if found: 35 | ANDROID_SDK = os.environ['ANDROID_SDK'] 36 | if ANDROID_SDK=='': 37 | exit(1) 38 | 39 | cmd = "let s:androidSdkPath = '" + ANDROID_SDK + "'" 40 | vim.command(cmd) 41 | cmd = "vimgrep /target=/j " + pwd + "/project.properties" 42 | vim.command(cmd) 43 | vim.command("let s:androidTargetPlatform = split(getqflist()[0].text, '=')[1]") 44 | vim.command("let s:targetAndroidJar = s:androidSdkPath . '/platforms/' . s:androidTargetPlatform . '/android.jar'") 45 | target = vim.eval("s:targetAndroidJar") 46 | cmd = "let $CLASSPATH = '" + target + "'" 47 | vim.command(cmd) 48 | endpython 49 | endfunction 50 | 51 | call FindManifestFile() 52 | --------------------------------------------------------------------------------