@@ -60,6 +60,10 @@ if !exists("g:ag_working_path_mode")
60
60
let g: ag_working_path_mode = ' c'
61
61
endif
62
62
63
+ if ! exists (" g:ag_default_open_style" )
64
+ let g: ag_default_open_style = ' replace'
65
+ endif
66
+
63
67
function ! ag#AgBuffer (cmd, args )
64
68
let l: bufs = filter (range (1 , bufnr (' $' )), ' buflisted(v:val)' )
65
69
let l: files = []
@@ -93,8 +97,20 @@ function! ag#Ag(cmd, args)
93
97
return
94
98
endif
95
99
100
+ " Should Ag open the first result automatically?
101
+ " If not, Ag! assumes the default behavior.
102
+ if g: ag_default_open_style == ? ' noreplace'
103
+ let l: cmd = join (split (a: cmd , ' !' ))
104
+ if a: cmd = ~# ' !$'
105
+ else
106
+ let l: cmd = l: cmd .' !'
107
+ endif
108
+ else
109
+ let l: cmd = a: cmd
110
+ endif
111
+
96
112
" Format, used to manage column jump
97
- if a : cmd = ~# ' -g$'
113
+ if l : cmd = ~# ' -g$'
98
114
let s: ag_format_backup= g: ag_format
99
115
let g: ag_format= " %f"
100
116
elseif exists (" s:ag_format_backup" )
@@ -120,11 +136,11 @@ function! ag#Ag(cmd, args)
120
136
catch
121
137
echom ' Failed to change directory to:' .l: cwd
122
138
finally
123
- silent ! execute a : cmd . " " . escape (l: grepargs , ' |' )
139
+ silent ! execute l : cmd . " " . escape (l: grepargs , ' |' )
124
140
exe " lcd " .l: cwd_back
125
141
endtry
126
142
else " Someone chose an undefined value or 'c' so we revert to the default
127
- silent ! execute a : cmd . " " . escape (l: grepargs , ' |' )
143
+ silent ! execute l : cmd . " " . escape (l: grepargs , ' |' )
128
144
endif
129
145
finally
130
146
let &grepprg = l: grepprg_bak
@@ -133,13 +149,13 @@ function! ag#Ag(cmd, args)
133
149
let &t_te = l: t_te_bak
134
150
endtry
135
151
136
- if a : cmd = ~# ' ^l'
152
+ if l : cmd = ~# ' ^l'
137
153
let l: match_count = len (getloclist (winnr ()))
138
154
else
139
155
let l: match_count = len (getqflist ())
140
156
endif
141
157
142
- if a : cmd = ~# ' ^l' && l: match_count
158
+ if l : cmd = ~# ' ^l' && l: match_count
143
159
exe g: ag_lhandler
144
160
let l: apply_mappings = g: ag_apply_lmappings
145
161
let l: matches_window_prefix = ' l' " we're using the location list
0 commit comments