Skip to content

Commit

Permalink
Support for VIM autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
gjalves committed Dec 17, 2017
1 parent b85aa43 commit 9f38495
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Embed seamlessly with vim

## Download

[Fedora 27 RPM Package](https://github.com/gjalves/pgscope/releases/download/0.0.1/pgscope-0.0.1-1.fc27.x86_64.rpm)
[Fedora 27 RPM Package](https://github.com/gjalves/pgscope/releases/download/0.0.2/pgscope-0.0.2-1.fc27.x86_64.rpm)

## Installation from source

Expand All @@ -17,12 +17,15 @@ cd libpg_query
make
cd -
make
mkdir ~/.vim/after/ftplugin/
cp sql.vim .vim/after/ftplugin/sql.vim
```

## Using

Type pgscope to index all .sql files in current and descending directories. After that, open your .sql file with vim and put cursor under any external function. Call it using <kbd>CTRL</kbd>+<kbd>]</kbd>. If you wish to came back to calling function, use <kbd>CTRL</kbd>+<kbd>O</kbd>
Type pgscope to index all .sql files in current and descending directories. After that, open your .sql file with vim and put cursor under any external function. Call it using <kbd>CTRL</kbd>+<kbd>]</kbd>. If you wish to came back to calling function, use <kbd>CTRL</kbd>+<kbd>o</kbd>

You can autocomplete functions using <kbd>CTRL</kbd>+<kbd>x</kbd> and <kbd>CTRL</kbd>+<kbd>o</kbd>
If you need to reindex, use `:!pgscope` in vim.

If you wish to reindex automatically after save, type in vim command mode:
Expand Down
7 changes: 6 additions & 1 deletion pgscope.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Name: pgscope
Vendor: Gustavo Junior Alves
Version: 0.0.1
Version: 0.0.2
Release: 1%{?dist}
Summary: PL/pgSQL source code tree search and browse tool

Expand All @@ -16,11 +16,15 @@ BuildRequires: coreutils

%changelog

* Sun Dec 16 2017 Gustavo Junior Alves <gjalves@gjalves.com.br> 0.0.2
- Autocomplete VIM script file

* Sun Dec 10 2017 Gustavo Junior Alves <gjalves@gjalves.com.br> 0.0.1
- Initial release

%install
install -D pgscope ${RPM_BUILD_ROOT}/usr/bin/pgscope
install -D sql.vim ${RPM_BUILD_ROOT}/usr/share/pgscope/sql.vim

%description
PL/pgSQL source code tree search and browse tool
Expand All @@ -35,6 +39,7 @@ rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
/usr/bin/pgscope
/usr/share/pgscope/sql.vim

%post

Expand Down
31 changes: 31 additions & 0 deletions sql.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
" Vim completion script
" Language: PL/pgSQL
" Maintainer: Gustavo Junior Alves <gjalves@gjalves.com.br>
" Last Change: 2017 Dec 16

au! BufNewFile,BufRead *.sql call s:FTbtm()
function! s:FTbtm()
if exists("g:dosbatch_syntax_for_btm") && g:dosbatch_syntax_for_btm
setf dosbatch
else
setf btm
endif
endfunction

fun! Pgscope_complete(findstart, base)
if(a:findstart == 1) && (a:base == '')
return 0
endif

for line in readfile("tags", '', 10)
if (strcharpart(line, 0, 1) != '!')
let parts = split(line)
if(stridx(parts[0], a:base) == 0)
call complete_add(parts[0])
endif
endif
endfor
call complete_check()
endfun

set omnifunc=Pgscope_complete

0 comments on commit 9f38495

Please sign in to comment.