I've been building an iPhone app, (now) targeting OS5 for several months & yesterday upgraded to Xcode 4.2.1.
After several builds today I've now hit the following error:
error:
/Users/mike_lynch/Documents/SimpleBookKeeping1/../../Library/Application
Support/iPhone
Simulator/5.0/Applications/2F75719F-99D8-432C-9F50-E3FD316FCD97/BK
Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK
Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK
Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK
Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK
Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK
Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK
Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK
Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK
Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK
Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK
Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK
Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK
Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK
Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK Lite.app/BK
Lite.app/BK Lite.app/Mileage.nib' is longer than MAXPATHLEN (1024)
It's like it is appending 'BK Lite.app' to the path every time I build. There is no nest of 'BK Lite.app' directories in finder.
Any help in resolving this would be much appreciated.
Running Product/Clean seems to resolve this issue.
Related
I would like to replace the brackets of the year with commas in the references as it is the standard method in the Journal of Finance.
In the references, I have this structure; Author (2020) Title... but I would like to change it to; Author, 2020, Title...
This would be a sample bibliography:
#article{examplesource,
title={Title of article},
author={LastName1, FirstName1 and LastName2, FirstName2 and LastName3, FirstName3},
journal={Journal of Finance},
volume={40},
number={1},
pages={3--73},
year={2005}}
This is what I have so far:
\documentclass{article}
\usepackage[style=ext-authoryear, backend=biber, giveninits=true, uniquelist = false, uniquename=init, isbn=false, maxcitenames=3, dashed=false, maxbibnames=999, doi=false, url=false]{biblatex}
\addbibresource{biblatex-examples.bib}
%\DeclareDelimFormat{nameyeardelim}{\addcomma\space}
\setlength{\bibhang}{15pt}
\DeclareNameAlias{sortname}{family-given}
\renewcommand*{\labelnamepunct}{\addspace}
\DeclareFieldFormat[article,inbook,incollection,inproceedings,patent,thesis,unpublished]{title}{#1}
\DeclareFieldFormat{titlecase}{\MakeSentenceCase*{#1}}
\renewbibmacro*{in:}
{\ifentrytype{article}
{\setunit{\addcomma\space}}
{\printtext{\bibstring{in}\intitlepunct}}}
\DeclareFieldFormat{journaltitlecase}{#1}
\renewbibmacro*{journal}{
\ifboolexpr{
test {\iffieldundef{journaltitle}}
and
test {\iffieldundef{journalsubtitle}}}
{\printtext[journaltitle]{
\printfield[journaltitlecase]{journaltitle}
\setunit{\subtitlepunct}
\printfield[journaltitlecase]{journalsubtitle}}}}
\renewbibmacro*{volume+number+eid}{
\printfield{volume}
\setunit{\addcomma\space}
\printfield{eid}}
\DeclareFieldFormat[article,periodical]{volume}{{#1}}
\DeclareFieldFormat{pages}{#1}
\UndeclareInnerCiteDelims{parencite}
\DeclareInnerCiteDelims{parencite}{(}{)}
\begin{document}
\textcite{examplesource} lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.\\
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua \parencite{examplesource}.
\printbibliography
\end{document}
Thanks a lot for your help!
Luckily you are using the ext-authoryear style, so you can use
\DeclareFieldFormat{biblabeldate}{#1} to remove the parenthesis
\DeclareDelimFormat[bib]{nameyeardelim}{\addcomma\space} to add a comma before the year
\ExecuteBibliographyOptions{innamebeforetitle=true} \DeclareDelimFormat[bib]{nametitledelim}{\addcomma\space} to add a comma after the year
\documentclass{article}
\usepackage[style=ext-authoryear, backend=biber, giveninits=true, uniquelist = false, uniquename=init, isbn=false, maxcitenames=3, dashed=false, maxbibnames=999, doi=false, url=false]{biblatex}
\addbibresource{biblatex-examples.bib}
%\DeclareDelimFormat{nameyeardelim}{\addcomma\space}
\setlength{\bibhang}{15pt}
\DeclareNameAlias{sortname}{family-given}
\renewcommand*{\labelnamepunct}{\addspace}
\DeclareFieldFormat[article,inbook,incollection,inproceedings,patent,thesis,unpublished]{title}{#1}
\DeclareFieldFormat{titlecase}{\MakeSentenceCase*{#1}}
\renewbibmacro*{in:}
{\ifentrytype{article}
{\setunit{\addcomma\space}}
{\printtext{\bibstring{in}\intitlepunct}}}
\DeclareFieldFormat{journaltitlecase}{#1}
\renewbibmacro*{journal}{
\ifboolexpr{
test {\iffieldundef{journaltitle}}
and
test {\iffieldundef{journalsubtitle}}}
{\printtext[journaltitle]{
\printfield[journaltitlecase]{journaltitle}
\setunit{\subtitlepunct}
\printfield[journaltitlecase]{journalsubtitle}}}}
\renewbibmacro*{volume+number+eid}{
\printfield{volume}
\setunit{\addcomma\space}
\printfield{eid}}
\DeclareFieldFormat[article,periodical]{volume}{{#1}}
\DeclareFieldFormat{pages}{#1}
\UndeclareInnerCiteDelims{parencite}
\DeclareInnerCiteDelims{parencite}{(}{)}
\DeclareFieldFormat{biblabeldate}{#1}
\DeclareDelimFormat[bib]{nameyeardelim}{\addcomma\space}
\ExecuteBibliographyOptions{innamebeforetitle=true} \DeclareDelimFormat[bib]{nametitledelim}{\addcomma\space}
\begin{document}
\textcite{knuth:ct} lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.\\
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua \parencite{knuth:ct}.
\printbibliography
\end{document}
I use \textcite{} and \parencite{} for referencing in a latex file. Using that method, I get as default; Author (Year)... and (Author, Year). But I would like to adjust the \parencite{} reference as (Author (Year)) as the standard method in the Journal of Finance.
This would be a sample bibliography:
#article{examplesource,
title={Title of article},
author={LastName1, FirstName1 and LastName2, FirstName2 and LastName3, FirstName3},
journal={Journal of Finance},
volume={40},
number={1},
pages={3--73},
year={2005}}
And this is what I got so far (https://tex.stackexchange.com/questions/379901/biblatex-how-to-match-the-journal-of-finance-bibliographic-style):
\documentclass{article}
\usepackage[style=authoryear, backend=biber, giveninits=true, uniquelist = false, uniquename=init, isbn=false, maxcitenames=3, dashed=false, maxbibnames=999, doi=false, url=false]{biblatex}
\addbibresource{biblatex-examples.bib}
\DeclareDelimFormat{nameyeardelim}{\addcomma\space}
\setlength{\bibhang}{15pt}
\DeclareNameAlias{sortname}{family-given}
\renewcommand*{\labelnamepunct}{\addspace}
\DeclareFieldFormat[article,inbook,incollection,inproceedings,patent,thesis,unpublished]{title}{#1}
\DeclareFieldFormat{titlecase}{\MakeSentenceCase*{#1}}
\renewbibmacro*{in:}
{\ifentrytype{article}
{\setunit{\addcomma\space}}
{\printtext{\bibstring{in}\intitlepunct}}}
\DeclareFieldFormat{journaltitlecase}{#1}
\renewbibmacro*{journal}{
\ifboolexpr{
test {\iffieldundef{journaltitle}}
and
test {\iffieldundef{journalsubtitle}}}
{\printtext[journaltitle]{
\printfield[journaltitlecase]{journaltitle}
\setunit{\subtitlepunct}
\printfield[journaltitlecase]{journalsubtitle}}}}
\renewbibmacro*{volume+number+eid}{
\printfield{volume}
\setunit{\addcomma\space}
\printfield{eid}}
\DeclareFieldFormat[article,periodical]{volume}{{#1}}
\DeclareFieldFormat{pages}{#1}
\begin{document}
\textcite{examplesource} lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.\\
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua \parencite{examplesource}.
\printbibliography
\end{document}
Thanks a lot!
If you use the ext-authoryear style, you can change the delimiter using \DeclareInnerCiteDelims{parencite}{(}{)}:
\documentclass{article}
\usepackage[style=ext-authoryear, backend=biber, giveninits=true, uniquelist = false, uniquename=init, isbn=false, maxcitenames=3, dashed=false, maxbibnames=999, doi=false, url=false]{biblatex}
\addbibresource{biblatex-examples.bib}
%\DeclareDelimFormat{nameyeardelim}{\addcomma\space}
\setlength{\bibhang}{15pt}
\DeclareNameAlias{sortname}{family-given}
\renewcommand*{\labelnamepunct}{\addspace}
\DeclareFieldFormat[article,inbook,incollection,inproceedings,patent,thesis,unpublished]{title}{#1}
\DeclareFieldFormat{titlecase}{\MakeSentenceCase*{#1}}
\renewbibmacro*{in:}
{\ifentrytype{article}
{\setunit{\addcomma\space}}
{\printtext{\bibstring{in}\intitlepunct}}}
\DeclareFieldFormat{journaltitlecase}{#1}
\renewbibmacro*{journal}{
\ifboolexpr{
test {\iffieldundef{journaltitle}}
and
test {\iffieldundef{journalsubtitle}}}
{\printtext[journaltitle]{
\printfield[journaltitlecase]{journaltitle}
\setunit{\subtitlepunct}
\printfield[journaltitlecase]{journalsubtitle}}}}
\renewbibmacro*{volume+number+eid}{
\printfield{volume}
\setunit{\addcomma\space}
\printfield{eid}}
\DeclareFieldFormat[article,periodical]{volume}{{#1}}
\DeclareFieldFormat{pages}{#1}
\UndeclareInnerCiteDelims{parencite}
\DeclareInnerCiteDelims{parencite}{(}{)}
\begin{document}
\textcite{knuth:ct} lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.\\
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua \parencite{knuth:ct}.
\printbibliography
\end{document}
Im learning kotlin. I followed a tutorial where i should put some random text into the editText box. However whenever i put too many lines of text into the texbox, everything on the layout shrinks into the top left cornor.
I tried to invalid the cache, and also to change to another api but with no luck so far. any ideas ?
This is the error android studio throws at me:
java.lang.ArrayIndexOutOfBoundsException: 16
at android.text.StaticLayout.generate(StaticLayout.java:854)
at android.text.DynamicLayout.reflow(DynamicLayout.java:609)
at android.text.DynamicLayout.generate(DynamicLayout.java:477)
at android.text.DynamicLayout.<init>(DynamicLayout.java:396)
at android.text.DynamicLayout.<init>(DynamicLayout.java:45)
at android.text.DynamicLayout$Builder.build(DynamicLayout.java:278)
at android.widget.TextView.makeSingleLayout(TextView.java:8329)
at android.widget.TextView.makeNewLayout(TextView.java:8204)
at android.widget.TextView.assumeLayout(TextView.java:8104)
at android.widget.TextView.onPreDraw(TextView.java:6742)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
at android.view.AttachInfo_Accessor.dispatchOnPreDraw(AttachInfo_Accessor.java:46)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:404)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:543)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:426)
at com.android.layoutlib.bridge.BridgeRenderSession.render(BridgeRenderSession.java:108)
at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:154)
at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:136)
at com.android.tools.idea.rendering.RenderTask.lambda$renderInner$5(RenderTask.java:671)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
It is because you are using ConstraintLayout.
While using it, you have to add Constraints to each of View in order to arrange them at an appropriate place in Layout.
More info you can Check this ans
I have a similiar issue doing some Kotlin for Android course.
When I add text to Multiline text (editText with textMultiline input type) which is longer than what can be visible in widget, renderer crashes. Here's the stack trace given by Android Studio:
16 View Measure Failed
java.lang.ArrayIndexOutOfBoundsException: 16
at android.text.StaticLayout.generate(StaticLayout.java:854)
at android.text.DynamicLayout.reflow(DynamicLayout.java:609)
at android.text.DynamicLayout.generate(DynamicLayout.java:477)
at android.text.DynamicLayout.<init>(DynamicLayout.java:396)
at android.text.DynamicLayout.<init>(DynamicLayout.java:45)
at android.text.DynamicLayout$Builder.build(DynamicLayout.java:278)
at android.widget.TextView.makeSingleLayout(TextView.java:8329)
at android.widget.TextView.makeNewLayout(TextView.java:8204)
at android.widget.TextView.onMeasure(TextView.java:8586)
at android.view.View.measure_Original(View.java:23169)
at android.view.View_Delegate.measure(View_Delegate.java:80)
at android.view.View.measure(View.java:23133)
at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at android.support.constraint.ConstraintLayout.onMeasure_Original(ConstraintLayout.java:1572)
at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java)
at android.view.View.measure_Original(View.java:23169)
at android.view.View_Delegate.measure(View_Delegate.java:80)
at android.view.View.measure(View.java:23133)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.support.v7.widget.ContentFrameLayout.onMeasure_Original(ContentFrameLayout.java:143)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java)
at android.view.View.measure_Original(View.java:23169)
at android.view.View_Delegate.measure(View_Delegate.java:80)
at android.view.View.measure(View.java:23133)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
at android.support.v7.widget.ActionBarOverlayLayout.onMeasure_Original(ActionBarOverlayLayout.java:401)
at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java)
at android.view.View.measure_Original(View.java:23169)
at android.view.View_Delegate.measure(View_Delegate.java:80)
at android.view.View.measure(View.java:23133)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure_Original(View.java:23169)
at android.view.View_Delegate.measure(View_Delegate.java:80)
at android.view.View.measure(View.java:23133)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:592)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:345)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:386)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:450)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:590)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
and
16 Exception raised during rendering
java.lang.ArrayIndexOutOfBoundsException: 16
at android.text.StaticLayout.generate(StaticLayout.java:854)
at android.text.DynamicLayout.reflow(DynamicLayout.java:609)
at android.text.DynamicLayout.generate(DynamicLayout.java:477)
at android.text.DynamicLayout.<init>(DynamicLayout.java:396)
at android.text.DynamicLayout.<init>(DynamicLayout.java:45)
at android.text.DynamicLayout$Builder.build(DynamicLayout.java:278)
at android.widget.TextView.makeSingleLayout(TextView.java:8329)
at android.widget.TextView.makeNewLayout(TextView.java:8204)
at android.widget.TextView.assumeLayout(TextView.java:8104)
at android.widget.TextView.onPreDraw(TextView.java:6742)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
at android.view.AttachInfo_Accessor.dispatchOnPreDraw(AttachInfo_Accessor.java:46)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:404)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:543)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:426)
at com.android.layoutlib.bridge.BridgeRenderSession.render(BridgeRenderSession.java:108)
at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:154)
at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:136)
at com.android.tools.idea.rendering.RenderTask.lambda$renderInner$5(RenderTask.java:671)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Here is my layout:
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView" android:layout_marginTop="16dp" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="16dp"/>
<Button
android:text="Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="16dp" app:layout_constraintEnd_toEndOf="parent" android:layout_marginBottom="16dp"
android:id="#+id/cancelButton"/>
<Button
android:text="OK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/okButton"
app:layout_constraintEnd_toStartOf="#+id/cancelButton"
android:layout_marginEnd="32dp"
app:layout_constraintBaseline_toBaselineOf="#+id/cancelButton"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/editText2"
android:text='Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum'
app:layout_constraintStart_toEndOf="#+id/textView"
android:layout_marginStart="16dp" android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/textView" android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginBottom="16dp"
app:layout_constraintBottom_toTopOf="#+id/okButton"/>
I'm using Android Studio 3.2.1
In course widget had height greater that screen size which led to overflow of it outside main screen of the designer, in my case it just crashed.
If you paste a multi line text in the attribute editor in Android Studio, the line breaks get removed from the string and the resulting string can be too long to handle.
If you must get a very long hard coded string in the textMultiLine widget, put it in the xml editor and add line breaks along the way.
android:text="line1
line2
line3"
I don't know what the maximum allowed length of a line is, or if this is a bug or a feature - just encountered it and worked around it like this.
I am using a function that I got from Vimcasts to preserve the cursor position when executing a command in Vim:
" A command to preserve last search and cursor position after running another
" command. See: http://vimcasts.org/episodes/tidying-whitespace/
function! Preserve(command)
" Preparation: save last search, and cursor position.
let _s=#/
let l = line(".")
let c = col(".")
" Do the business:
execute a:command
" Clean up: restore previous search history, and cursor position
let #/=_s
call cursor(l, c)
endfunction
" Strip trailing whitespace
nmap <Leader>$ :call Preserve("%s/\\s\\+$//e")<CR>
It works pretty well for the strip trailing whitespace mapping I've shown here, but not when I'm calling an external command like this:
" Reformat a plain text document to use hard wrapping and uniform spacing
" Note: This uses the BSD `fmt` program. The GNU coreutils version takes
" different options.
nmap <Leader>f :call Preserve("%!fmt -s -78")<CR>
vnoremap <Leader>f :call Preserve("'<,'>!fmt -s -78")<CR>
The first mapping works fine, but the second one exhibits a strange looping behavior. For example, if I have a text file like this:
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut laboret dolore magna aliqua. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Sed ut perspiciatis unde omnis iste natus error sit. Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Itaque reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
When I select those lines in visual mode to filter them, the command appears to run five times. Here's what I'm seeing in the output:
5 lines filtered
5 lines filtered
5 lines filtered
5 lines filtered
5 lines filtered
Press ENTER or type command to continue
If the file has 10 lines, then they are filtered 10 times. It still filters the area correctly, but I'm confused as to why it's looping. I think it has something to do with the Preserve function because running the command outside of preserve doesn't exhibit the looping.
Note: I think this is the appropriate place for this question, but the closing of the Vi/Vim proposal leaves me wondering where I should really be posting a question like this. Please let me know if there's a more appropriate forum for it.
When you call a function on a multi-line visual selection, that function is called for each line in the selection. Since your visual selection covers 5 lines the Preserve() function and the command you passed to it are called 5 times.
The solution is simple, add the range argument to the function definition:
function! Preserve() range
With that argument, the function is called only once and you can let it or the underlying command deal with the visual range itself.
See :help func-range.
Another – slightly dirtier – solution could be to modify your mappings to remove the range before calling the function so that it is called only once:
map <key> :<C-u>call Function(args)<CR>
See :help c_ctrl-u.
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.