1

I'm working a function to rename the visual selected text

function! Rename()
    name = getline("'<")[getpos("'<")[2]-1:getpos("'>")[2]-1]
    let newname = input('rename the selection with: ')
    execute ":%s/\\<".name."\\>/".newname."/g"
endfunction

Is it possible to have the content of name as the the default value of the input() function? To be more specific, I'd like to have the command line become (take name content to be ibasis for example)

rename the selection with: ibasis

when I call this function. I can then use my mapping <C-a> to go to the start of ibasis, delete i and quickly get the desired result of replacing ibasis with basis.

Kevin Powell
  • 147
  • 7

1 Answers1

3

From :h input()

input({prompt} [, {text} [, {completion}]])     *input()*

If the optional {text} argument is present and not empty, this
is used for the default reply, as if the user typed this.
Example: >

     :let color = input("Color? ", "white")
statox
  • 49,782
  • 19
  • 148
  • 225