Add Pasted Code Segment File and Line Numbers In Prompt Message

Feature request for product/service

Cursor IDE

Describe the request

When pasting code into chat, add the literal filename and line numbers in the prompt message where the code was pasted so the prompt can specifically refer to them, instead of the current functionality where pasted code is just added to the context of the entire prompt with no effect of where it was pasted in the prompt message.
By having the filename and line numbers as literal text in the request, it allows giving specific instructions related to each code pasted. Right now it seems to just add the code to the context, and the model does not know how each pasted code segment relates to the message body of the request.
I have to manually type out of the file and line numbers when referring to code segments in context sometimes, which seems a bit redundant.
This already similarly works when you drag an open file/tab into the chat, where it places the file in the chat right at the end, where you are usually typing. This would also make it easy to paste multiple segments of code and in chat form a request tying them all together.

Default Copy/Paste Behavior
This is how it looks now if you paste code segments while typing out a prompt.
If it’s just one pasted code segment in a new chat, this usually causes no issues. But if its multiple or in a chat with lots of historical context, the model can misunderstand how the pasted code relates to the prompt, especially with multiple segments pasted.

Current Workaround
Manually type out the lines of the pasted code segments.

Feature Requested Solution
Pasting the code segments automatically adds the filename and line numbers in the message where your cursor was.


or could show only the file in the context area to reduce clutter

Related Threads:

Operating System (if it applies)

Windows 10/11

1 Like

Makes so much sense, I run into this every single day.

1 Like

Be sure to vote for this feature. It would be great if it was implemented.

It looks like this has been sort of fixed in v2.0.5.

Now there is no context bar at the top of chat. When copying pasting code it adds only the literal code. To add only the reference to the code, have to highlight code and press Ctrl+L or use the inline buttons.

This works great because now the model is able to reference different parts of the code based on where they are presented in the request.

This feature was implemented in v2.0.14 exactly as described in this feature request. Works great. These kinds of improvements are what separates Cursor from the rest. Thanks, Cursor team. @andrewh

Letting you know this feature exists now in v2.0.14 (beta).

1 Like