I need to insert the line number before each line of text using Vim, and there has to be a space after the line number. For example, if this was TestFile:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Morbi nunc enim, vehicula eget, ultricies vel, nonummy in, turpis.
It should look like this
1 Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
2 Morbi nunc enim, vehicula eget, ultricies vel, nonummy in, turpis.
I have been using the command :%s/^/\line('.')/ with a number of variations, but I cannot figure out how to get the space at the end.
Any ideas?
You were very close!
This substitution will do the job by concatenating the string ' ' to the line number:
%s!^!\=line('.').' '!
This is probably easiest with an external tool:
:%!nl -ba -w1 -s' '
You can use a macro. First make sure you have a 0 before the first line and have your cursor placed on it:
0 Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Morbi nunc enim, vehicula eget, ultricies vel, nonummy in, turpis.
foo
bar
etc...
Then perform this key sequence to store the right macro in register a: qaywjP0<C-A>q.
Now press #a to execute the macro. Use a quantifier to execute it multiple times.
Type :help q to find out more about recording macro's.
Related
I have a .txt file that contains text that is formatted like so:
Neque porro, quisquam est qui
dolorem ipsum quia, dolor (sit amet)
consectetur, adipisci velit,Lorem Ipsum
dolor sit amet, consectetur adipiscing elit
tempor ipsum quia, minim (sit minim)
consectetur, adipisci velit,Lorem Ipsum
There are multiple text items like this. I wish to make it so that they are all one liners each so I can paste them into excel like so
Neque porro, quisquam est qui dolorem ipsum quia, dolor (sit amet) consectetur, adipisci velit, Lorem Ipsum
dolor sit amet, consectetur adipiscing elit tempor ipsum quia, minim (sit minim) consectetur, adipisci velit,Lorem Ipsum
Would there be any way to do this for files with a lot of text that are like this?
If you did want to use Excel (as your question indicates) this formula work if you had all text in a single cell
=SUBSTITUTE(SUBSTITUTE(A1,CHAR(10)&" "," "),char(10),REPT(char(10),2))
st = 'Lorem ipsum dolor sit amet, consectetur adipis.cing elit. Aliquam sem odio...'
n = []
for i in st:
n.append(i)
for i in n:
if i in [',','.']:
n.remove(i)
string = ''
for i in n:
string += i
print(string)
input string :
Lorem ipsum dolor sit amet, consectetur adipis.cing elit. Aliquam sem odio...
output :
Lorem ipsum dolor sit amet consectetur adipiscing elit Aliquam sem odio.
expected output :
Lorem ipsum dolor sit amet consectetur adipiscing elit Aliquam sem odio
There is one dot . at the end of the sentence that is not getting removed.
You can use str.join for the task:
st = "Lorem ipsum dolor sit amet, consectetur adipis.cing elit. Aliquam sem odio..."
print("".join(ch for ch in st if ch not in {*",."}))
Prints:
Lorem ipsum dolor sit amet consectetur adipiscing elit Aliquam sem odio
How about using replace() for both commas and periods?
>>> st.replace(",", "").replace(".", "")
'Lorem ipsum dolor sit amet consectetur adipiscing elit Aliquam sem odio'
Calling some_list.remove(something) while iterating over some_list changes the length of list and introduces the potential to skip elements. The solution is to copy the list first. See this thread.
Also, remove() removes the first occurrence, not the current index, so you may get unusual results using it. Best case scenario, iterating over the list repeatedly from the front is harmful to time complexity. I don't find remove() useful often in practice.
I'd write this using a simple regex:
>>> import re
>>> st = 'Lorem ipsum dolor sit amet, consectetur adipis.cing elit. Aliquam sem odio...'
>>> re.sub(r"[.,]", "", st)
'Lorem ipsum dolor sit amet consectetur adipiscing elit Aliquam sem odio'
Other remarks:
This is Shlemiel the painter's algorithm:
for i in n:
string += i
Better is "".join(n)
n is usually reserved for "number". Prefer lst or L for a generic list.
Allocating a list inside a loop adds unnecessary overhead: if i in [',','.']:.
The code:
n = []
for i in st:
n.append(i)
can be better expressed as list(st).
When writing a long footnote with LilyPond 2.17.25, the text is not breaking into several lines or respecting the margin limits. I would love to have it set to justified alignment as well, if that is possible.
Here is a tiny example:
\version "2.17.25"
{
\footnote #'(-1 . 1)
\markup{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eget ante venenatis mi consectetur ornare. Cras facilisis dictum venenatis. Donec.}
a'4 b' c'' d''
}
Thanks a lot!
The solution is to simply add \justify or \wordwrap to the \markup command, as:
\version "2.17.25"
{
\footnote #'(-1 . 1)
\markup\justify{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eget ante venenatis mi consectetur ornare. Cras facilisis dictum venenatis. Donec.}
a'4 b' c'' d''
}
I use vim to write a lot of text (mostly for research papers), and I recently start to format paragraphs and sentences like this:
Lorem ipsum dolor sit amet, consectetur adipiscing
elit sed diam et arcu scelerisque rutrum eget
vitae sed diam et arcu scelerisque rutrum eget
vitae sed diam et arcu scelerisque rutrum eget
vitae.
Aenean euismod tristique sollicitudin.
Vestibulum sed diam et arcu scelerisque rutrum eget
vitae sapien.
Quisque dui ligula, semper eget iaculis at, eleifend
at ligula.
Sed vestibulum tellus ac libero iaculis sit amet commodo
sapien pellentesque.
Cras quis dignissim neque.
Donec neque mauris, dictum tempus tincidunt in,
pellentesque sit amet dui.
I hope you can guess the pattern.
Now I do this mostly manual what is some kind of akward, especially if you add text in the middle of the sentence. My question would be, how can i do this automagically?
I know that I can use "gq100" to force a linebreak on the next 100 lines, but this does not do exactly what I want. It would be great if this is not really a hard linebreak but only a virtual one, which means when I put the cursor in the line starting with "Lorem ipsum" I can copy and past the whole sentence with y and p as if there wouldn't be any linebreak at all.
Does someone have an idea on this one?
Cheers,
T
Do you mean: If a line starts with 3 spaces, it belong to previous sentence?
You can do this:
:set textwidth=0
:set wrap
:set showbreak=\ \ \
Note: there's a space after every \.
Try to type a very lone line. It'll auto wrap. And the next line starts with 3 spaces.
I guess this is what you are looking for, the breakindent patch for vim:
http://sqizit.bartletts.id.au/2011/01/31/vim-and-breakindent/
I have long section titles in my document like:
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Proin nibh augue, suscipit a, scelerisque sed, lacinia in, mi.
Now I want to place it in page header but it is to long for it. Is there any way to cut text in LaTeX? I want to have it like that:
Lorem ipsum dolor sit amet, consectetur...
Is that possible?
https://tex.stackexchange.com/questions/6862/how-can-i-display-a-short-chapter-name-in-the-header-and-a-long-chapter-name-in-t