In Vim 7.4, how can I reformat paragraphs the following way with the gq} command while using the set smartindent option (I need that option)?
Before reformatting:
1 Sed ut perspiciatis, unde omnis iste natus error sit voluptatem
accusantium doloremque laudantium, totam rem aperiam eaque ipsa,
quae ab illo inventore veritatis et quasi architecto beatae vitae
dicta sunt, explicabo.
2 Nemo enim ipsam voluptatem, quia voluptas
sit, aspernatur aut odit aut fugit, sed quia consequuntur magni
dolores eos, qui ratione voluptatem sequi nesciunt, neque porro
quisquam est, qui dolorem ipsum, quia dolor sit, amet,
consectetur, adipisci velit, sed quia non numquam eius modi
tempora incidunt, ut labore et dolore magnam aliquam quaerat
voluptatem.
After reformatting (what I want) — notice the line numbers:
1 Sed ut perspiciatis, unde omnis iste natus error sit voluptatem
2 accusantium doloremque laudantium, totam rem aperiam eaque ipsa,
3 quae ab illo inventore veritatis et quasi architecto beatae vitae
4 dicta sunt, explicabo.
5 Nemo enim ipsam voluptatem, quia voluptas
6 sit, aspernatur aut odit aut fugit, sed quia consequuntur magni
7 dolores eos, qui ratione voluptatem sequi nesciunt, neque porro
8 quisquam est, qui dolorem ipsum, quia dolor sit, amet,
9 consectetur, adipisci velit, sed quia non numquam eius modi
10 tempora incidunt, ut labore et dolore magnam aliquam quaerat
11 voluptatem.
With set formatoptions=qw, I get the desired result (the block ‘After reformatting’). But if I add the option set smartindent, every line of the paragraph becomes indented (what I get):
1 Sed ut perspiciatis, unde omnis iste natus error sit
2 voluptatem accusantium doloremque laudantium, totam rem
3 aperiam eaque ipsa, quae ab illo inventore veritatis et quasi
4 architecto beatae vitae dicta sunt, explicabo.
5 Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut
6 odit aut fugit, sed quia consequuntur magni dolores eos, qui
7 ratione voluptatem sequi nesciunt, neque porro quisquam est,
8 qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci
9 velit, sed quia non numquam eius modi tempora incidunt, ut
10 labore et dolore magnam aliquam quaerat voluptatem.
Turn off smartindent. Don't replace it with autoindent. Both of these options will use the indent of the 1st line for any following lines in your simple (prose) case. smartindent is actually pretty bad anyway and mostly discouraged; it has been replaced with cindent and expression-based indenting (via indentexpr). Mostly you can actually turn on filetype-specific indent rules, but I don't know of any that exist for prose.
If you want automatic indentation in prose, I would suggest using 'autoindent' rather than 'smartindent' (which is not actually very smart). Combine that with a 2 in your 'formatoptions' setting, and you can reformat existing multiline paragraphs and the indent will remain correct on the 2nd line and higher.
But I know of no way to configure Vim so that it will indent the first line and not the other lines. You need to set the indent of either the first or second line manually, then Vim can format the rest of the lines properly.
Related
I am working on text files (copied and pasted from a facebook group) I have stripped out all the strings "Like" "Comment" comment numbers etc with group of sed commands . I am left with lines that look like this:
Jane Doe
Jane Doe Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Donec ac urna ut quam sagittis placerat id vitae justo.
John Doe
John Doe Maecenas id justo tempus, auctor velit in, porta nibh.
John Doe
John Doe Maecenas id justo tempus, auctor velit in, porta nibh.
Fred Crun
Fred Crun Maecenas id justo tempus, auctor velit in, porta nibh. Mauris bibendum et ligula molestie faucibus. Nullam feugiat tristique sapien non fringilla.
Fred Crun
Fred Crun Maecenas id justo tempus, auctor velit in, porta nibh. Mauris bibendum et ligula molestie faucibus. Nullam feugiat tristique sapien non fringilla.
Frank Zappa
Frank Zappa Suspendisse malesuada libero id tortor scelerisque feugiat. Suspendisse vel feugiat est. Vestibulum vel nisl magna. Aenean viverra diam vel vulputate pulvinar. In hac habitasse platea dictumst.
I am looking for a regexp for sed or other Unix utility that would remove the name on the line(s) with no other text following, leaving the lines looking like this:
Jane Doe Lorem ipsum dolor sit amet, consectetur adipiscing elit.
John Doe Maecenas id justo tempus, auctor velit in, porta nibh.
John Doe Maecenas id justo tempus, auctor velit in, porta nibh.
Fred Crun Maecenas id justo tempus, auctor velit in, porta nibh. Mauris bibendum et ligula molestie faucibus. Nullam feugiat tristique sapien non fringilla
Fred Crun Maecenas id justo tempus, auctor velit in, porta nibh. Mauris bibendum et ligula molestie faucibus. Nullam feugiat tristique sapien non fringilla.
Frank Zappa Suspendisse malesuada libero id tortor scelerisque feugiat. Suspendisse vel feugiat est. Vestibulum vel nisl magna. Aenean viverra diam vel vulputate pulvinar. In hac habitasse platea dictumst.
ode here.
. I looked at uniq and several examples of regep in gvim but I could not see a way to achieve my aim . Names may consist of 3 words.
This might work for you (GNU sed):
sed -E 'N;/^(.*)\n\1./!P;D' file
Open a two line window throughout the length of the file.
If the whole of the first line is the same as the start of the second, do not print it.
Delete the first line and repeat.
In Vim you can do the following:
:%s/^\(.*\)\n\1/\1
Which looks for a line, followed by \n and the same line (plus potentially something after, it is not specified) and replaces it with the pattern found, removing the first part.
if your data in d file, tried on gnu sed:
sed -E '/^\w+\s\w+\s*$/{N;s/([^\n]+)\n(\1.+)/\2/;b};d' d
All,
I was wondering if anyone out there was a par guru. I'm mainly wondering if there is a way to get par to see a Fortran comment style that is used in many programs I work with.
For example, if I have:
! 2001Jan01 Jimson Lorem ipsum dolor sit amet, consectetuer adipiscing
! elit. Aenean commodo ligula eget dolor.
! 2002Jan01 Johnny Aenean massa. Cum sociis natoque penatibus et magnis dis parturient
! montes, nascetur ridiculus mus. Donec quam felis, ultricies nec,
! pellentesque eu, pretium quis, sem.
! 2004Feb01 Thompson Nulla consequat massa quis enim. Donec pede justo, fringilla vel,
! aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo.
! Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus.
It would be nice to run par in vim (with :set formatprg=par) and get something like:
! 2001Jan01 Jimson Lorem ipsum dolor sit amet, consectetuer adipiscing
! elit. Aenean commodo ligula eget dolor.
! 2002Jan01 Johnny Aenean massa. Cum sociis natoque penatibus et magnis
! dis parturient montes, nascetur ridiculus mus. Donec
! quam felis, ultricies nec, pellentesque eu, pretium
! quis, sem.
! 2004Feb01 Thompson Nulla consequat massa quis enim. Donec pede justo,
! fringilla vel, aliquet nec, vulputate eget, arcu. In
! enim justo, rhoncus ut, imperdiet a, venenatis vitae,
! justo. Nullam dictum felis eu pede mollis pretium.
! Integer tincidunt. Cras dapibus.
where it sees the hanging spaces, etc. Instead par does:
(524) $ par -w80 < text_for_par
! 2001Jan01 Jimson Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
! Aenean commodo ligula eget dolor. 2002Jan01 Johnny Aenean massa. Cum sociis
! natoque penatibus et magnis dis parturient montes, nascetur ridiculus
! mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem.
! 2004Feb01 Thompson Nulla consequat massa quis enim. Donec pede justo,
! fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus
! ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis
! pretium. Integer tincidunt. Cras dapibus.
which, I do admit, is quite well formatted at 80 characters and keeps the "!<space><space>" at the front.
Unfortunately, par's PARINIT syntax is a bit...mysterious to me. It is entirely possible this is not possible and, if so, okay. But par seems to be powerful in a way like vim is. As long as you know the right confusing character string, it'll do what you want.
I'm not a par expert but if you try something like
cat text_for_par | par 80 -p24 -d1
it should give you what you're looking for. Just look at the man page on par - it tells you how to achieve most things.
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 was wondering if it would be possible to run the vim spell checker while coding with PHP.
I can run it if I disable syntax highlighting, and it highlights almost all methods/function names because they are not English words.
So, my question is this, can I run the spell check on just the strings within PHP files?
For example, just within the ' quotes (and " quotes), ignoring everything else:
$paragraph = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. In est libero, dictum ut suscipit eget, lacinia in justo. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent sit amet sem libero, in pretium enim. Pellentesque tortor ante, imperdiet quis mattis in, tincidunt et ligula. Cras porta velit a ligula venenatis placerat.';
$paragraph2 = "Vestibulum quis eleifend lectus. Vestibulum odio odio, mollis at eleifend a, adipiscing sed quam. Nam quis nisi quis mauris faucibus hendrerit eu a leo. Sed feugiat purus sit amet purus congue quis semper diam malesuada. Vivamus et enim non arcu pretium sollicitudin. Nullam blandit, lorem eu aliquet tincidunt, enim mauris placerat lectus, id faucibus nulla lectus non elit. Sed eget fermentum lacus. Ut tempus pulvinar neque, vel pellentesque purus aliquet quis. Vivamus molestie pretium quam at imperdiet. Maecenas diam turpis, malesuada ut sollicitudin ac, congue eleifend urna. Quisque id ipsum eget ipsum tempus blandit at vel magna. Fusce eu felis metus.";
see the vim help: :help spell-syntax
You can define particular syntax groups as having spell checking.
There's probably a better way to do it (using a ~/.vim/after/syntax/php.vim file?), but a simple hack is to make a personal version of the php syntax file in ~/.vim/syntax (you can do this by doing :e $VIMRUNTIME/syntax/php.vim and the :saveas ~/.vim/syntax/php.vim), and change all instances of the text contains=#phpAddStrings to contains=#Spell,#phpAddStrings. Next time you open a php file, turn on spell checking as normal with :set spell.
For the life of me, I cannot figure out the cause of this: when writing in LaTeX documents, I like to keep my line width to maximum of 80 characters. As such, I will execute the vim command gqap and vim will automatically re-wordwrap the paragraph I am writing.
For example, it will cause a long line to become many shorter ones:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque pharetra nunc eget arcu dapibus pretium. Nulla vel risus quam, ut sollicitudin sem. Vivamus vitae diam in risus pharetra gravida. Donec rutrum mattis nulla, in consectetur lorem luctus varius. Donec augue purus, iaculis eget fringilla nec, vehicula ut sapien. Quisque sit amet dolor mauris. Sed ac est eu ligula aliquam tincidunt. Proin condimentum rutrum lacinia.
becomes:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque pharetra
nunc eget arcu dapibus pretium. Nulla vel risus quam, ut sollicitudin sem.
Vivamus vitae diam in risus pharetra gravida. Donec rutrum mattis nulla, in
consectetur lorem luctus varius. Donec augue purus, iaculis eget fringilla nec,
vehicula ut sapien. Quisque sit amet dolor mauris. Sed ac est eu ligula aliquam
tincidunt. Proin condimentum rutrum lacini
But, for some paragraphs, it will start adding unusual indentions towards the end of the paragraph:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque pharetra
nunc eget arcu dapibus pretium. Nulla vel risus quam, ut sollicitudin sem.
Vivamus vitae diam in risus pharetra gravida. Donec rutrum mattis nulla, in
consectetur lorem luctus varius. Donec augue purus, iaculis eget fringilla,
vehicula ut sapien. Quisque sit amet dolor mauris. Sed ac est eu ligula
tincidunt. Proin condimentum rutrum lacini
Why does vim do this? I have yet to figure out the pattern. How can I make it format paragraphs "the correct way"?
Yes, vim's 'smartindent' is not well named. I had trouble with this for a while before I figured out what was wrong. For others, if you notice strange indenting behavior after lines starting with "if" or "for", unset smartindent. You will come across this a lot if you start using vim as a word processor.
From the vim help file, 'smartindent' will indent after a line starting with a keyword from 'cinwords', which is "if,else,while,do,for,switch", by default.
The problem was that I had "smartindent" enabled. Disabling this for LaTeX documents solved it:
au BufEnter *.tex set nosmartindent