When I am editing a LaTeX file using Vim-LaTeX and want to reformat a section of text that is in a \caption{} I get overhangs or underhangs - I am not sure what to call them. I first select the text in the caption then use "gq" to reformat it. After reformatting the caption looks like:
\caption{The problem is that when I reformat the text
in a caption the text on each successive line
begins further and further to the left until it begins
at the first space of the line.}
what I would hope the result would look like would be something like:
\caption{The problem is that when I reformat the text
in a caption the text on each successive line
begins further and further to the left until it
begins at the first space of the line.}
I hope the formatting in this post remains true to what I typed in, but I tried to describe the problem in the first example caption. The second should be left justified.
Does anyone know what I need to do to fix this? I am assuming that there is a setting that I need to change, but I have not been able to figure out what it is.
The gq command formats based on 'formatexpr' or 'formatprg'. You can start by checking the values of these options with :se fex? and :se fp?.
From looking through the vim-latex plugin it never sets these options, so this is likely set by your other plugins or vimrc. You can find out exactly where an option is set by using :verbose.
Related
I want to be able to hide all code around the specific section of code that I am working with. Now I am wondering if this is possible in Vim somehow. I have experimented with it a bit already and have been successful at hiding lines above and below my selection by using highlight group Igore. This enables me to only see the lines that I want to focus on but the problem is when I begin to edit the code and add or remove lines. When I add a line or remove a line the already set highlight group Ignore is still maintaining the set line numbers so I either get to see some of the hidden code or some of the code that I want to see gets long and extends into the hidden line numbers. So I am wondering if there is some way to fix this or any other way to accomplish what I want in Vim?
Appreciate any suggestions!
Hiding or shading parts of the buffer is not the Vim way. Folding is the built-in feature that comes closest. With :set foldmethod=manual, you can then use zf or :fold to hide the parts above and below.
For a plugin solution, have a look at NrrwRgn - A Narrow Region Plugin. It allows you to edit parts of a buffer in a separate scratch buffer, with automatic syncing back.
To hide a range of lines (let's say from 1 to 10 and 20 to end, you can type :1,10fo|20,$fo
From there, you can create a function based on the current cursor position -10/+10
Note you have first to :set foldmethod=manual to make this works.
EDIT: a simple solution : :1,.-10fo|.+10,$fo
value(val_1)
value(val_100)
value(val_10)
I want to select text between parentheses and do it for multiline, for one line I can use f(va( but I don't know how to select for 2 remaining lines.
EDIT (SOLUTIONS)
What I want to is to change text inside parentheses with unique text every line, firstly, I was thinking to select the text, delete it then change the text manually, #rosipov tell there is a plugin to do the selection part and it's great, but #romainl gave me another direction that works too.
f(ci(foo<Esc>jci(bar<Esc>jci(baz<Esc>
Do you want to select this:
value([val_1])
value([val_100])
value([val_10])
or to select that:
value([val_1)]
[value(val_100)]
[value(val_10])
The first is unfortunately not doable. But depending on what you want to do with the selected text, change it for example, a reasonable approximation would be:
f(l<C-v>jj$cnew value)<Esc>
However I'm sure a lot of Vimmers would probably approach the problem with a substitution:
:,+2s/(.*/(new value)
The second is done simply with:
f(lv3/)h
or
f(ljjt)
You will probably be interested in EasyMotion plugin in this case: https://github.com/Lokaltog/vim-easymotion
With plugin it will be: f(vLeaderLeaderf)c
Or: LeaderLeaderf(avLeaderLeaderf)c
Where c is letter representing 3rd closing parentheses, a represents first opening p.
EDIT: Without plugin it is possible to do it by line number.
Assuming that you work with lines 1-3: f(v3Gf)
Where 3G stands for "go to line number 3", works in both visual and normal modes.
Is there a way to totally hide certain lines? I do not want folding, I one them to not be visible at all.
Example: I program with php; functions and class variables have phpdocs, and I hate how much vertical space lines with nothing but /** and */ can take. Thus I would like to not show them (and most likely some other things). Though I have doubts that that is possible...
Note: I know about global commands and they don't do what I want. You can one of printing of what I want. But I want lines hidden in the editing area.
You can make comments invisible:
:hi! Comment guifg=bg ctermfg=white
Or
:hi! link Comment Ignore
I know this isn't really what you're asking for, but have you tried using folding with a blank foldtext? That way the lines a folded region appears like an empty line. To do this, set
set foldmethod=marker
set foldmarker=\/**,*\/
set foldtext='\ '
I prefer a foldtext which indicates that there's something there, possibly by making is look like a single commented line. In this case, replacing the first folded line with a single comment string // at the current indent level:
set foldtext=substitute(getline(v:foldstart),'\\/\\*\\*.*','\\/\\/','g'
I find this unobtrusive, while still reminding me that there is some hidden text.
Hope this helps.
I may have a unique situation here. I want gVim (gui version, in Linux) to keep concealed characters concealed no matter what, even when the cursor is on that line or that character gets selected. (It should be as close to if the characters never existed as possible.) Currently the concealed characters show themselves when the cursor enters that line, which causes text to jump around when scrolling and when selecting text.
We are using gView (read-only gVim) to view logs, so as to take advantage of its robust syntax highlighting. Problem is, these logs contain lots of escape characters and TTY color codes, that make reading difficult. (^[33mSomeText^[0m)
I'm using this line to hide them:
syntax match Ignore /\%o33\[[0-9]\{0,5}m/ conceal
Since the files are viewed by non-vim-experts, it looks glitchy and broken when the text un-conceals itself. (And also looks glitchy and broken if the color codes are present, and also looks glitchy and broken if the color codes are blacked-out to become invisible, but still show when selected and appear after copy/paste.)
This should be fine because these files are opened read-only in gview, with an extra set nomodifiable making it even more difficult to save the file. While it's possible to edit and attempt to save the logs, doing so is considered both an invalid thing to do, and a harmless thing to do, and requires enough Vim skills that if someone manages to edit a file they know what they're doing. The problem with being able to edit a line with concealed text does not apply.
If 'conceal' can't be configured to keep hidden text hidden no matter what, an acceptable alternative would be to replace the TTY color codes with whitespace when the file gets opened. But, this has to be done in read-only mode, and we can't have gview throwing up a save dialog on closing the window because the file has been modified by its .vimrc.
Note: I am in full control of the .vim script file sourced when these are read, but cannot control the existence of the TTY color codes or the code that opens the log files in gview. (i.e. I can't pass it through sed or anything like that.) The ideal solution is anything that can transparently nuke the color codes from within a .vimrc, but I'll hear any suggestions. The 'conceal' feature is just my most promising lead.
So, any ideas how to permanently get rid of these on file view without dialogs popping up on close?
:help conceal
When the "conceal" argument is given, the item is marked as concealable.
Whether or not it is actually concealed depends on the value of the
'conceallevel' option. The 'concealcursor' option is used to decide whether
concealable items in the current line are displayed unconcealed to be able to
edit the line.
:help concealcursor
Sets the modes in which text in the cursor line can also be concealed.
When the current mode is listed then concealing happens just like in
other lines.
n Normal mode
v Visual mode
i Insert mode
c Command line editing, for 'incsearch'
'v' applies to all lines in the Visual area, not only the cursor.
A useful value is "nc". This is used in help files. So long as you
are moving around text is concealed, but when starting to insert text
or selecting a Visual area the concealed text is displayed, so that
you can see what you are doing.
Keep in mind that the cursor position is not always where it's
displayed. E.g., when moving vertically it may change column.
Also, :help conceallevel
Determine how text with the "conceal" syntax attribute |:syn-conceal|
is shown:
Value Effect ~
0 Text is shown normally
1 Each block of concealed text is replaced with one
character. If the syntax item does not have a custom
replacement character defined (see |:syn-cchar|) the
character defined in 'listchars' is used (default is a
space).
It is highlighted with the "Conceal" highlight group.
2 Concealed text is completely hidden unless it has a
custom replacement character defined (see
|:syn-cchar|).
3 Concealed text is completely hidden.
Only one command is needed: set concealcursor=n
I might have a better idea—you can pass it through sed (using %!sed) or really do a bunch of other :substitute commands—whatever edits you need to get rid of the color codes.
When you’re done, make sure to set nomodified—this forces vim to think there haven’t been any changes!
When I am typing a long code comment in VIM, I manually judge when each comment line reaches 80 characters, then manually typically press < enter >< tab >//< space > and continue on. Likewise it is awkward editing comments, adding or removing text.
// The comments I have to use
// look like this
Ideally, I'd like some kind of comment mode, where you type text, and the 80 line character limit and the // symbols are sorted out automatically. Does anything like this exist?
You can turn on formatting options with set formatoptions=tcq (with tcq each representing an option, there are others as well). Use h formatoptions to see what the various flags are.
In this case you probably want to use set fo+=a.
Personally though, I prefer to just type my comments normally, then when I'm done run gqip. gq is the formatting command, ip for in paragraph. Make sure the comment block is not next to code though or it will suck that up when reformatting your comment.
I use :set textwidth=80 to set the formatting width (actually, 80 is the default).
Then I move the cursor to the first line of the comment and in command mode press gq} to format the comment. It also works for other comment types from other programming languages such as # and /* ... */
A variant on #Alex's suggestion is to select the lines in visual mode and then press gq. This allows you to avoid the problem of gqip reformatting code as well.
Pressing capital V selects an entire line, then you can just move up or down to highlight all the comments and press gq.