set line number to be part of line content in vim - vim

To use command :set number in vim can add numbers at the beginning of the every line.
But the line number is not part of the line contents ,when you copy the contents ,the line number will not be in it ,how can i create the line number ,and make it be the part of the line content ,you can copy and paste the number with every line?

I believe that you are looking for this line:
:%s/^/\=line('.').' '/
this will add line number to each line of text.
note:
the original text would be changed.
the line number won't be automatically fixed if you add new line or remove lines, they are parts of your text (line content), as you wished.
FYI
if you are on linux box, you may consider to use other tool(s) to get line-numbered text output, without changing your original text, like:
nl file
cat -n file
awk '$0=NR" "$0' file
.....

Related

How to saved a text always in buffer in Vim>

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

mouse select copy from "vim" and "less" show different results

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.

Preformatted text in SSRS

How do I achieve the effect of preformated text in SSRS?
For example, this is what I see,
First Line of text
Second line of text
Third line of text
But I would like to see
First Line of text
Second line of text
Third line of text
The problem is obviously the leading spaces that I used in every line to indent the lines themselves. When those lines are rendered in SSRS (which is web based), the consecutive whitespaces are ignored.

Get ranges of edited lines in vim buffer

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?

What's the difference between :insert and :append?

I'm looking for a vim command that pastes the code but disable the auto indent. So I find these commands, I can just use one command and paste, then enter the <Ctrl+C>, very easy.
However, I don't understand what's the difference between :insert and :append.
Do they really have the same behavior?
Behaviour of :insert and :append is not the same.
:insert
Insert text before the cursor
:append
Insert text after the cursor
From :h append
append({lnum}, {expr})
append()
When {expr} is a |List|: Append each item of the |List| as a
text line below line {lnum} in the current buffer.
Otherwise append {expr} as one text line below line {lnum} in
the current buffer.
{lnum} can be zero to insert a line before the first one.

Resources