I use vim-codefmt and want it to only format the lines which were changed on save. Is there a way to grab a list of the lines which were changed?
Related
I have a csv file. Some lines have 7 columns with tab delimited, and others have only one tab. I want to find all lines with only one tab and remove them.
What's the command to do this in VIM? I tried this but it doesn't work:
[^\t]+\t[^\t]+
Assuming you have a single tab or more on every line, this will remove all lines without multiple tabs.
:v/\t.*\t/d
If you have lines with no tabs that you want to retain, this will not work as it will remove them.
Actually I want to copy a selected text from file a in Vim and paste to multiple different parts of file b. But when I paste to file b, it just happened once and then buffer is empty. I want that part of text in buffer always as I have to paste it to some more parts and for this I have to go to file a every time I had to copy and then paste to that file b. Is there any way that I can save that text in buffer always?
You are mixing up vim terminology here. From the Vim Wiki:
A buffer is a file loaded into memory for editing.
What you mean by a buffer is actually a register. The default register gets overwritten by a lot of operations that delete text (e.g. x/c/d) because they store the deleted text in there. But you can yank 100K lines of text into a named registers like this:
"a100000yy
This yanks all these lines into register a.
Now go to file B and lets first delete the 100K lines you want to change. Put your cursor on the first line that needs to change and do:
100000dd
Then we will paste the lines from file A with:
"aP
Notice that that is a capital P.
For more information on the power of register check this link out: https://www.tutorialspoint.com/vim/vim_registers.htm
Case1: Open file1 in vi. Select a few lines(select copy is enabled). Paste in a different place.
Case 2: run the command less file1. From the console, select some lines. Paste in a different place.
In case2, I see that there are new lines introduced at where the line display shifts to new line. So, if the terminal width is 80 characters and my line is 100 characters, then 20 characters will be shown in the new line. If I copy from vim, all 100 characters are copied without any line-break. However, if I copy from "less" command, line-break is introduced after 80th character.
This messes up things like path.
Does "less" introduce line-break dynamically for lines longer than the display width?
less is not designed to handle mouse events. So when you select text while running it, the selection will be handled by the terminal behind, which doesn't give any sense to lines, paragraphs and so on; the text buffer is copied as it is displayed, that's all.
On the opposite, if you use vim with the right configuration, mouse events will be detected and treated by vim itself : the terminal will gracefully let vim handle them, for convenience. Then the line layout will be restored correctly when copying lines of text.
I love vim, but one of my problems with it is that whenever I use x or d to remove text, it copies the deleted text into the buffer/clipboard.
More specifically, it's a problem when I have some text copied, and then I need to delete a second block of text before pasting the first text.
Is there a command that deletes text but does not copy it? If not, is there a custom command for this?
Thanks!
Use black hole register
"_d
Setup your own mapping in vimrc like ,d to save some typing
There are more ways than one to solve the problem. One has already been suggested by Vimsha.
Another way to solve the problem is to copy your important text to a named register. Say you wanted to 5 lines of text to be deleted from one place and copied in a different place.
"a5dd will delete 5 lines of text and save them in the a register.
Do various other operations.
Now move to the location where you want to copy them.
"ap or "aP will copy the 5 lines of text from the a register to the current location.
As explicitly noted in the title, how can I set a specific index, similar to eof in a text file, so that I can edit text from that point on? If I have a text file of which I want to edit some of the last characters, do I necessarily have to save its contents as a string, edit the string, and write it back to the file?
See the AppleScript dictionary for StandardAdditions, where write and eof are defined. I believe you're looking to write starting at a position in a text file. Note that write starting at will overwrite existing text at that position.