Skip to content

Commit

Permalink
Add an option to insert function names in insert mode
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
BrotifyPacha committed Jun 30, 2024
1 parent 3d188ed commit 8861e19
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 6 additions & 0 deletions doc/surround.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ function name inside the parentheses.
If s is used, a leading but not trailing space is added. This is useful for
removing parentheses from a function call with csbs.

If you prefer entering function name inside the buffer (possibly with a help
from lsp completion). You can enable this behaviour with an option.
>
let g:surround_insert_func_name_interactivly = "1"
<

CUSTOMIZING *surround-customizing*

The following adds a potential replacement on "-" (ASCII 45) in PHP files.
Expand Down
18 changes: 14 additions & 4 deletions plugin/surround.vim
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,25 @@ function! s:wrap(string,char,type,removed,special)
let after = '\end'.matchstr(env,'[^}]*').'}'
endif
elseif newchar ==# 'f' || newchar ==# 'F'
let fnc = input('function: ')
if fnc != ""
let s:input = fnc."\<CR>"
let before = substitute(fnc,'($','','').'('
if !exists("g:surround_insert_func_name_interactivly")
let fnc = input('function: ')
if fnc != ""
let s:input = fnc."\<CR>"
let before = substitute(fnc,'($','','').'('
let after = ')'
if newchar ==# 'F'
let before .= ' '
let after = ' ' . after
endif
endif
else
let before = '('
let after = ')'
if newchar ==# 'F'
let before .= ' '
let after = ' ' . after
endif
startinsert
endif
elseif newchar ==# "\<C-F>"
let fnc = input('function: ')
Expand Down

0 comments on commit 8861e19

Please sign in to comment.