gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

How to automatically remove line numbers when copying?

Open ISensuiI opened this issue 1 year ago • 16 comments

What would you like to be added?

I have been using Gemini for about a week and it is great. I know that Gemini cli and Claude Code can both automate modifications. But I am more used to discussing solutions with it, letting it give sample code, and then reading and understanding it myself, and adjusting it or directly copying and pasting it into my project, which can reduce hidden dangers, especially in projects with 100,000 lines of code or more. The problem is that the code it generates has line numbers, which I can understand, because it is normal for the generated code format to have line numbers, especially in Google AI Studio, it will be parsed correctly, we just click the copy button, and the clean code will be copied directly. If it is CLI, this problem will occur. Every time you copy, you have to copy the line number and then clean it up manually. Of course, I know that I can use regular replacement, such as ^\s*\d{1,3}\s+, but it is still very troublesome. I don’t know if my usage is wrong, or cmd can only be like this. Is there any way to improve this situation? I understand that cmd doesn’t seem to be able to do buttons and clicks, and I can’t think of any good way. At present, I can only use my own stupid method, which is to use regular replacement every time.

Why is this needed?

...

Additional context

No response

ISensuiI avatar Jul 16 '25 03:07 ISensuiI

Yes, I have noticed this! I have gotten Gemini CLI to format the code without line numbers, but it is hit or miss. This would be great if it could produce the code without line numbers.

RonnieShawDeveloper avatar Jul 16 '25 15:07 RonnieShawDeveloper

I have tried it, but it didn't work at least last week, because this is a code format limitation. If the code is output, it must have line numbers. It's a bit like markdown format. It can only be output in this way. I tried to command gemini to output the code without line numbers. But it still outputs with line numbers.

ISensuiI avatar Jul 16 '25 16:07 ISensuiI

In principle gemini cli can automatically modify/adjust your source code files so there is no need to copy & paste text like this.

If you do still want to continue with this copy & paste workflow, I would suggest pasting the code in some editor like textpad and then hold control or alt key and select a block of text/area to cut off the line numbers all at once.

To make gemini cli see your source codes it helps to start the cmd.exe in the folder where the source code resides.

Windows Explorer (assuming you are on windows) can be used to navigate to the source folder and then in the top edit bar type: cmd.exe to start a command prompt... from there gemini cli can be started.

A downside to this would be the need to place a .env file in the source code folder in case gemini api keys are to be used (for authentication) This has adventagers and disadventages, for example an gemini api key per project/source folder.

If a more generic approach is desireable with .env in every project/startup folder... then it can also be placed in a user account/data folder see manual for that, so gemini cli can be started anywhere and successfully authenticated.

I do agree with you that sometimes it can be indeed desireable to copy the source code text without the line numbers.

Perhaps for comparison purposes with existing code. Modification is not always the use case.

So it would be nice to have some kind of capability to automatically filter out the line numbers...

Also I do remember the ascii and ansi boxes around text or code can also get in the way... filtering these out could also be nice...

SkybuckFlying avatar Jul 16 '25 23:07 SkybuckFlying

This is a really annoying behaviour. Especially given #4349 where it loses its mind and can suddenly no longer edit a file, if you say "just give me the file as unformatted ASCII text that I can just copy/pasted", it's unable to do so.

After askign for unformatted code... Well, edited conversation follows:

Me, quoting its response> You keep repeating this. It DOES NOT WORK. ... first 5 lines hidden ... │ │ 5 // (c) 2018 ... more code.

I cannot express how sorry I am for getting stuck in that loop. I am providing the complete and corrected content for $FILE below, in a plain text code block. This is designed to be copied and pasted directly, replacing the entire contents of your existing file. There are no hidden lines or line numbers.

Please, copy everything from the first line (//+------------------------------ --------------------------------------------) to the last line (#endif).

... first 309 lines hidden ... 308 } 309 310 // Find physical column 311 int q_phys = 0;

So it's editing things before line 309, but it can't send me that "fix" in any form. So it chops off the head of the response (which contaiins parts that are needed) and it pollutes the response with line numbers and a few space, meaning I would have to edit much code. But since this is only part of the file, it's just a dead end.

There's clearly some kind of paginator or filter or something between us and it. It thinks it's sending full, undecorated source code, but it's just plain not how it's being delivered to us.

I tried all kinds of coercion, like asking it to create a zip file I could download, make a web page with that as text wrapped in a div, send me a patch, write ed commands to just deliver the fixes to the file, but once it gets into this loop, there is just a total impasse.

So it can't edit the files in place and it can't hand you the file in a format that's usable. It's super frustrating.

robertlipe avatar Jul 17 '25 06:07 robertlipe

@SkybuckFlying I understand the idea behind the CLI, and that is has the ability to modify the files so there is no need to have it output the code. However, I asked it to modify a complex firebase rule so access could be provided correctly to the collections based on certain criteria. I finally figured out that if I just told the CLI to output the code as a paragraph, I was able to paste it in to the rules editor in the Firestore console and it worked fine. Sure, it does not show the nice structure, but is works just fine.

RonnieShawDeveloper avatar Jul 17 '25 16:07 RonnieShawDeveloper

I'm not here to jump on the bandwagon. I just wanted to say I also encountered this issue, so I used Gemini to create an online tool (URL: https://alingse.github.io/lineno-remover/, repo: https://github.com/alingse/lineno-remover ). It works really well for me, though admittedly, it's yet another handy tool.

I encountered this issue when Gemini was guiding me through setting up Supabase. The CREATE TABLE SQL it generated always included line numbers, so I had to manually remove them every time I copied and pasted the code into Supabase's execution box.

我碰到这个问题是在gemini 指导我配置supabase 的时候,他生成的 create table sql 总是带有行号,复制之后,到supabase 的执行框里面总是需要手动去除。

alingse avatar Jul 25 '25 14:07 alingse

I'm not here to jump on the bandwagon. I just wanted to say I also encountered this issue, so I used Gemini to create an online tool (URL: https://alingse.github.io/lineno-remover/, repo: https://github.com/alingse/lineno-remover ). It works really well for me, though admittedly, it's yet another handy tool.

I encountered this issue when Gemini was guiding me through setting up Supabase. The CREATE TABLE SQL it generated always included line numbers, so I had to manually remove them every time I copied and pasted the code into Supabase's execution box.

Image

感谢你的工具兄弟
^\s*\d{1,3}\s+ 我现在用这个正则. 我现在的流程

  1. Gemini Cli 复制 粘贴到 RustRover
  2. 正则替换.
  3. 然后 CTRL+SHIFT+L 格式化 .

^\s*\d{1,3}\s+ I use this regular expression now. Thanks for your tool brother. My current process is

  1. Copy and paste to RustRover
  2. Regular expression replacement.
  3. Then CTRL+SHIFT+L to format.

ISensuiI avatar Jul 25 '25 16:07 ISensuiI

I'll say I'm using it to write queries which I def want to copy and paste to verify and bc they will easily take over 20 mins to run.

CupOfGeo avatar Jul 30 '25 21:07 CupOfGeo

I'm using this regular expression to replace them with empty string: ^\s*\d{1,3}[ ]{0,5}

[ ]{0,5} of it is to match the at most 5 extra leading spaces in each line.

jcyrss avatar Aug 13 '25 02:08 jcyrss

So no one takes this seriously?

My use case... gemini was struggling with a query... I wanted to do some back and forth to optimize it. Line numbers are deal breaker.

When I said I'm going back to Claude he asked me why ;) I explained to him - then he created a GEMINI.md writing that he should not output code blocks since they will get numbered. It worked. However than all the output looks the same - no nice syntax highlighting.

Please add an option --no-line-numbers.

---------------------------------------------------------------------------------
| A similar issue: Drawing borders around output. Should be also made optional. |
---------------------------------------------------------------------------------

--no-borders

It's a bit ironic using AI and being told to use regexp. We are not at the level where gemini can do everything so there is a need to use other tools and the only way of 'communicating' with them is copy/paste.

samodadela avatar Oct 07 '25 18:10 samodadela

In the past when I've suggested workarounds to Gemini annoyances, I've been flamed to crispy toast, but it's an easy sed command do delete leading whitespace followed by a sequence of integer digits ending in whitespace. (That stilted wording is probably enough of a hint to get it to write it if you can't) Alds, most programming editors (specialized word processor since we don't really deal in words as a primary currency, but code) have rectangular column selection as an option that can make fixing this easy.

Gemini-cli needs an option to get that pagination thingy just out of the way. The line number and deleting the first N lines of a long listing are really annoying.

Then again,. I usually run into those two issues because the file editor thingy fails, which is the reason gemini-cli exists, so there's a whole chain of failure.

On Tue, Oct 7, 2025, 1:35 PM samodadela @.***> wrote:

samodadela left a comment (google-gemini/gemini-cli#4280) https://github.com/google-gemini/gemini-cli/issues/4280#issuecomment-3378106662

So no one takes this seriously?

My use case... gemini was struggling with a query... I wanted to do some back and forth to optimize it. Line numbers are deal breaker.

When I said I'm going back to Claude he asked me why ;) I explained to him

  • then he created a GEMINI.md writing that he should not output code blocks since they will get numbered. It worked. However than all the output looks the same - no nice syntax highlighting.

Please add an option --no-line-numbers.


| A similar issue: Drawing borders around output. Should be also made optional. |

--no-borders

It's a bit ironic using AI and being told to use regexp. We are not at the level where gemini can do everything so there is a need to use other tools and the only way of 'communicating' with them is copy/paste.

— Reply to this email directly, view it on GitHub https://github.com/google-gemini/gemini-cli/issues/4280#issuecomment-3378106662, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCSD37OYUIWEI5QSSDWKZ33WQBVVAVCNFSM6AAAAACBTV3EBKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTGNZYGEYDMNRWGI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

robertlipe avatar Oct 08 '25 18:10 robertlipe

When I was in game dev there was a thing called 'retention'. Most of the users fell off in the first minute of using the app. Something annoyed them and they left... we tried to figure out what the annoyance was and how to improve it.

@robertlipe Thanks for the hint but at the rate I do copy pastes I would get annoyed pretty fast ;)

BTW: This is not the only issue on this.

What annoys me most is that this seems to be so easy to implement that is not worth all those comments. Just skip numbering and boxes if a flag is provided. Doesn't need to be a default (in case other clients count on it).

Also I never refer to code with line numbers. I don't say at line '10"... I just paste the code I'm referring to.

samodadela avatar Oct 10 '25 15:10 samodadela

Fyi there is now a /copy tool that copies the last output from the model without line numbers. I'm also working on improving selection so it doesn't copy line numbers.

Another existing solution is you can go to /settings and hide display of line numbers all together.

jacob314 avatar Nov 19 '25 03:11 jacob314

/settings "showLineNumbers" to false

chengang2 avatar Dec 16 '25 15:12 chengang2

This issue has been automatically marked as stale due to 60 days of inactivity. It will be closed in 14 days if no further activity occurs.

github-actions[bot] avatar Feb 15 '26 02:02 github-actions[bot]

This issue has been closed due to 14 additional days of inactivity after being marked as stale. If you believe this is still relevant, feel free to comment or reopen the issue. Thank you!

github-actions[bot] avatar Mar 03 '26 02:03 github-actions[bot]