Skip to content

Commit 7e216cf

Browse files
committed
Fix: Don't pollute global namespace with option vars.
Use `get()` since options are only used once. and add abort to functions. Thanks to (u/LucHermitte): https://www.reddit.com/r/vim/comments/j27gi7/just_made_my_first_plugin_vimbettergrep/g746cut/?utm_source=reddit&utm_medium=web2x&context=3
1 parent 93b0394 commit 7e216cf

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

autoload/bettergrep.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ endif
1818

1919
if exists("*jobstart") " NeoVim async method
2020

21-
function! bettergrep#Grep(cmd, ...)
21+
function! bettergrep#Grep(cmd, ...) abort
2222

2323
let s:cmd = a:cmd
2424

@@ -47,7 +47,7 @@ else " regular blocking method
4747
" Thanks to RomainL's gist
4848
" https://gist.github.com/romainl/56f0c28ef953ffc157f36cc495947ab3
4949

50-
function! bettergrep#Grep(cmd, ...)
50+
function! bettergrep#Grep(cmd, ...) abort
5151
execute a:cmd . " " . "system(join([g:bettergrepprg] + [expandcmd(join(a:000, ' '))], ' '))"
5252
endfunction
5353

plugin/bettergrep.vim

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,19 @@ if exists('g:bettergrep_loaded')
88
endif
99
let g:bettergrep_loaded = 1
1010

11-
" Options
12-
if !exists('g:bettergrep_no_mappings')
13-
let g:bettergrep_no_mappings = 0
14-
endif
15-
if !exists('g:bettergrep_no_abbrev')
16-
let g:bettergrep_no_abbrev = 0
17-
endif
18-
1911
" Commands
2012
command! -nargs=+ -complete=file_in_path -bar Grep call bettergrep#Grep('cgetexpr', <f-args>)
2113
command! -nargs=+ -complete=file_in_path -bar LGrep call bettergrep#Grep('lgetexpr', <f-args>)
2214
command! -nargs=+ -complete=file_in_path -bar Grepadd call bettergrep#Grep('caddexpr', <f-args>)
2315
command! -nargs=+ -complete=file_in_path -bar LGrepadd call bettergrep#Grep('laddexpr', <f-args>)
2416

2517
" Mappings
26-
if !g:bettergrep_no_mappings
18+
if !get(g:, 'bettergrep_no_mappings', 0)
2719
nnoremap <C-g> :Grep
2820
endif
2921

3022
" Abbreviations
31-
if !g:bettergrep_no_abbrev
23+
if !get(g:, 'bettergrep_no_abbrev', 0)
3224
cnoreabbrev <expr> gr (getcmdtype() ==# ':' && getcmdline() ==# 'gr') ? 'Grep' : 'gr'
3325
cnoreabbrev <expr> lgr (getcmdtype() ==# ':' && getcmdline() ==# 'lgr') ? 'LGrep' : 'lgr'
3426
cnoreabbrev <expr> gre (getcmdtype() ==# ':' && getcmdline() ==# 'gre') ? 'Grep' : 'gre'

0 commit comments

Comments
 (0)