Skip to content

Proposal: the string interpolation (the template string) #4491

@aiya000

Description

@aiya000

Instructions: Replace the template text and remove irrelevant text (including this line)


Hi, Bram.
I'm a you and Vim's fan!

Is your feature request related something that is currently hard to do? Please describe.

I want to introduce the string interpolation (the template string) into Vim script.

Now it is introduced onto

I never contributed Vim yet, but this is not so hard in my opinion...

Describe the solution you'd like

A clear and concise description of what you want to happen.

'The string interpolation' ('The template string') embeds any expressions ${x} into a string via Vim function string().

For example.

" Embed literals using back quotations (the template string) and "${" "}"
call assert_equal(`I have ${10}`, 'I have 10')
call assert_equal(`I'm a ${'vim'}`, "I'm a vim")

" Variables
let x = 10
call assert_equal(`I have ${x}`, 'I have 10')

" Others
let x = ch_open('localhost:25252')  " dummy
call assert_equal(`${x}`, string(x))

I'm refering to the JavaScript's format of ${x} for the Vim script's template string.
(${x} ${dict.a} ${10} ${function('function')})

These expressions must be surrounded by "${" and "}".


I'm implementing it now at this branch.
The test can be shown at here 👇

Please see this ☝️ if you can!

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

I'm planning a template string form $"I'm ${name}" (surrounded by $" and ")
if Bram doesn't like a back quoted form I'm ${name}.

Additional context

After it introduced, expression embedding is to be more easier, and I think it is very cool!


Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions