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.

1 Answer 1

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")
3
  • Thanks! I will read the :help documentation first in the future. May 25, 2020 at 13:01
  • 1
    @KevinPowell I can't stress enough how useful it is to read the help, it answers 95% of the questions you can have about vim. If you are not familiar with the help you definitely want to read this question to get the basic in 5 minutes :)
    – statox
    May 25, 2020 at 13:17
  • 1
    I'm missing the basic of using help. Thanks a lot for the link! May 25, 2020 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.