Skip to content

Commit 9be446d

Browse files
committed
Add an option to insert function names in insert mode
By default Surround prompts for a function name using input(), which interrupts the flow, and lacks lsp completion. This pr adds an option to change this behavior - instead of using prompt(), user enters insert mode, where all buffer completion is available to them.
1 parent 3d188ed commit 9be446d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

doc/surround.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ function name inside the parentheses.
148148
If s is used, a leading but not trailing space is added. This is useful for
149149
removing parentheses from a function call with csbs.
150150

151+
If you prefer entering function name inside the buffer (possibly with a help
152+
from lsp completion). You can enable this behaviour with an option.
153+
154+
let g:surround_insert_func_name_interactivly = "1"
155+
151156
CUSTOMIZING *surround-customizing*
152157

153158
The following adds a potential replacement on "-" (ASCII 45) in PHP files.

plugin/surround.vim

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,25 @@ function! s:wrap(string,char,type,removed,special)
221221
let after = '\end'.matchstr(env,'[^}]*').'}'
222222
endif
223223
elseif newchar ==# 'f' || newchar ==# 'F'
224-
let fnc = input('function: ')
225-
if fnc != ""
226-
let s:input = fnc."\<CR>"
227-
let before = substitute(fnc,'($','','').'('
224+
if !exists("g:surround_insert_func_name_interactivly")
225+
let fnc = input('function: ')
226+
if fnc != ""
227+
let s:input = fnc."\<CR>"
228+
let before = substitute(fnc,'($','','').'('
229+
let after = ')'
230+
if newchar ==# 'F'
231+
let before .= ' '
232+
let after = ' ' . after
233+
endif
234+
endif
235+
else
236+
let before = '('
228237
let after = ')'
229238
if newchar ==# 'F'
230239
let before .= ' '
231240
let after = ' ' . after
232241
endif
242+
startinsert
233243
endif
234244
elseif newchar ==# "\<C-F>"
235245
let fnc = input('function: ')

0 commit comments

Comments
 (0)