Skip to content

Commit 4a38898

Browse files
committed
initial commit
0 parents  commit 4a38898

2 files changed

Lines changed: 135 additions & 0 deletions

File tree

README.md

Whitespace-only changes.

ftplugin/javascript.vim

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
" Vim filetype plugin
2+
" Language: JavaScript
3+
" Maintainer: Kevin Burnett
4+
" Last Change: 2014 March 21
5+
6+
" Only do this when not done yet for this buffer
7+
if exists("b:did_ftplugin")
8+
finish
9+
endif
10+
11+
let s:cpo_save = &cpo
12+
set cpo&vim
13+
14+
15+
let &cpo = s:cpo_save
16+
unlet s:cpo_save
17+
18+
19+
if exists("g:did_vim_angular_ftplugin_functions")
20+
finish
21+
endif
22+
let g:did_vim_angular_ftplugin_functions = 1
23+
24+
function SwitchToAlternateFile()
25+
let l:currentpath = expand('%')
26+
let l:newpath = ""
27+
28+
if l:currentpath =~ "test/unit"
29+
let l:newpath = substitute(l:currentpath, "test/unit", "app/src", "")
30+
elseif l:currentpath =~ "app/src"
31+
let l:newpath = substitute(l:currentpath, "app/src", "test/unit", "")
32+
endif
33+
34+
if l:newpath != "" && filereadable(l:newpath)
35+
execute 'edit ' . l:newpath
36+
endif
37+
endfunction
38+
39+
command -nargs=0 A call SwitchToAlternateFile()
40+
41+
let g:FindIgnore = ['coverage/', 'test/', '.git']
42+
43+
" Find file in current directory and edit it.
44+
function! Find(...)
45+
let path="."
46+
let query=a:1
47+
48+
if a:0 == 2
49+
let cmd=a:2
50+
else
51+
let cmd="open"
52+
endif
53+
54+
55+
if !exists("g:FindIgnore")
56+
let ignore = ""
57+
else
58+
let ignore = " | egrep -v '".join(g:FindIgnore, "|")."'"
59+
endif
60+
61+
let l:command="find ".path." -type f -iname '*".query."*'".ignore
62+
let l:list=system(l:command)
63+
let l:num=strlen(substitute(l:list, "[^\n]", "", "g"))
64+
65+
if l:num < 1
66+
echo "'".query."' not found"
67+
return
68+
endif
69+
70+
if l:num == 1
71+
exe cmd . " " . substitute(l:list, "\n", "", "g")
72+
else
73+
let tmpfile = tempname()
74+
exe "redir! > " . tmpfile
75+
silent echon l:list
76+
redir END
77+
let old_efm = &efm
78+
set efm=%f
79+
80+
if exists(":cgetfile")
81+
execute "silent! cgetfile " . tmpfile
82+
else
83+
execute "silent! cfile " . tmpfile
84+
endif
85+
86+
let &efm = old_efm
87+
88+
" Open the quickfix window below the current window
89+
botright copen
90+
91+
call delete(tmpfile)
92+
endif
93+
"echom l:command
94+
endfunction
95+
96+
command! -nargs=* Find :call Find(<f-args>)
97+
98+
" jacked from abolish.vim (s:snakecase). thank you, tim pope.
99+
function! s:dashcase(word)
100+
let word = substitute(a:word,'::','/','g')
101+
let word = substitute(word,'\(\u\+\)\(\u\l\)','\1_\2','g')
102+
let word = substitute(word,'\(\l\|\d\)\(\u\)','\1_\2','g')
103+
let word = substitute(word,'_','-','g')
104+
let word = tolower(word)
105+
return word
106+
endfunction
107+
108+
109+
function! s:GF(cmd, file) abort
110+
endfunction
111+
112+
function! FindFileBasedOnAngularServiceUnderCursor(cmd)
113+
let l:thingundercursor = expand('<cfile>')
114+
if l:thingundercursor =~ "/"
115+
execute "e<cfile>"
116+
return
117+
endif
118+
let l:dashcased = s:dashcase(l:thingundercursor)
119+
"echo l:dashcased
120+
let l:filethatmayexist = l:dashcased . ".js"
121+
"let l:filethatmayexist = printf("%.js", tolower(l:dashcased))
122+
"echo l:filethatmayexist
123+
execute "Find " . l:filethatmayexist . " " . a:cmd
124+
endfunction
125+
126+
augroup vim_angular_go_to_file
127+
autocmd!
128+
autocmd FileType javascript nnoremap <silent><buffer> gf :<C-U>exe FindFileBasedOnAngularServiceUnderCursor("open")<CR>
129+
autocmd FileType javascript nnoremap <silent><buffer> <C-W>f :<C-U>exe FindFileBasedOnAngularServiceUnderCursor("split")<CR>
130+
autocmd FileType javascript nnoremap <silent><buffer> <C-W><C-F> :<C-U>exe FindFileBasedOnAngularServiceUnderCursor("split")<CR>
131+
autocmd FileType javascript nnoremap <silent><buffer> <C-W>gf :<C-U>exe FindFileBasedOnAngularServiceUnderCursor("tabedit")<CR>
132+
augroup END
133+
134+
" vim:set sw=2:
135+

0 commit comments

Comments
 (0)