How can I show open folds in vim? (i.e., folds that are currently open)
e.g., show the open folds within the text somehow, like marking the lines;
or perhaps show them as a list (e.g., like the :jumps command that shows a list of jumps)
I don't know that folds can be listed, but marking of lines is possible using the foldcolumn option. (:help 'foldcolumn'). Try
set foldcolumn=12
Caveat: per the documentation, if nofoldenable is set, open folds will not be shown in the foldcolumn.
[foldenable] can be toggled with the *zi* command. The 'foldcolumn' will remain blank when 'foldenable' is off. [:help foldenable]
Related
I'm trying out code folding in vim but noticed it doesn't seem to mirror across pane splits when using scrollbind to achieve a "2-up" view of a long text/code file with relatively narrow lines (set up as per this guidance).
Is it possible to ensure a fold created in one pane is also created on the other?
I'm just getting familiar with the commands, but it'd probably be z+c (close a fold at the cursor, i.e. 'fold up') and z+o (open a fold at the cursor, i.e. 'unfold')
It strikes me that one use of code folding would be to let one of the split views be an "outline view" (fully folded up, and just used to give an indication of how far through the file the other pane is), but it'd be nice if I could get them fully synced for scrollbind.
nnoremap <Space> za<C-W><C-W>za<C-W><C-W>
in .vimrc allows you to toggle a folding simultaneously in two splits by pressing the space bar.
Whenever I create a vertical split in VIM using the :vs command, the newly created panel is a duplicate of the first, and it updates both panels in real-time as I type.
How can I turn this behaviour off and make it revert to opening a second independent panel?
That's exactly what's supposed to happen. If you don't want what a command does, use another command that does what you want.
From :help :vsplit:
Like :split, but split vertically.
From :help :split:
Split current window in two. The result is two viewports on the same file.
If you scroll down a bit you can find :help :vnew:
Like :new, but split vertically.
Which leads you to :help :new:
Create a new window and start editing an empty file in it.
So… what you want is :vnew.
I was doing a DIFF in VIM, and after trying to change the color scheme, I got this annoying column, it only appears in one file, no matter if I restart VIM, now I don't know how to get rid of it.
I think it doesn't have nothing to do with GitGutter, but now I'm not sure.
I think it's the fold column, which displays indicators for open and closed folds. Its width is controlled by a window-local option called 'foldcolumn' (see :h 'fdc).
By default, its value is 0 (disabled). If it's present in one of your window, some file must have changed its value. To find which one, you could execute:
:verbose setlocal foldcolumn
In C++ files that I edit with Gvim I have noticed that code lines which are in inside blocks
(curly braces {})
although are being shown on the screen with the correct amount of tabs in Gvim
(i.e. plus one tab from the code which is outside of this code block)
when I open the same files with an another editor
like sublime text
that extra tab that must exist in every line inside the code block does not exist.
So after opening these files with a hex editor I noticed that Gvim does not write those extra tabs in the code blocks?
Why does this happen?
Is it because of cindent?
Also how can I fix this rather than auto-reformat every time?
I am pretty sure that vim will faithfully save all the characters that are in the buffer. Various options affect how tabs are displayed, and whether actual tab characters or spaces are used for indenting. You can check their values, and see where they were set (default, in your vimrc file, or by some plugin) with
:verbose set ts? sts? et? sw? sta? ci? pi?
(These and more related options are grouped together if you open an options window with :options and look at Section 15.) If you want to visually check where you have tab characters rather than spaces, you can :set hls and then search for tab characters (or :match Search '\t') or you can :set list.
If you try all that and you still think that vim is not saving what is in the buffer, then there are odd things to check, like whether you have any BufWrite or related autocommands.
I'm trying to configure Vim so that it always wraps at x-number of columns automatically, at all times such as in this other editor that I provided a screenshot of-
Use :set wrap and :set textwidth=N . For permanent effect add the wrap settings to the vim start-up file .vimrc
set wrap
set textwidth=X
To apply the wrapping to an existing file, move to the start of the file (you can use gg to do this). Then type gqG to apply the re-formatting to the entire file.
Also setting a margin may be useful:
set wrapmargin=0
If you want hard wrapping, i.e. real reformatting of the text by inserting newline characters, the 'textwidth' setting (as outlined in suspectus's answer) is the key. You need to reformat existing text, e.g. via the gq command.
For soft wrapping, i.e. where long lines just appear to be broken in the editor window, :set wrap will always fill the entire available window space; you cannot restrict that to take less. Either resize the Vim window, or add a padding buffer to the right that restricts the available space to the current window. For the latter, my LimitWindowSize plugin may be helpful.
Judging from the second screenshot, you seemed to want soft-wrap. This answer suggests a way to achieve a soft-wrap effect .
I'm generalizing the solution a bit compared to the one I referred to, but basically
use :set nuw to see how many columns the line numbers are occupying, let's call this nuw.
then use :set columns=x where x = (the number of columns you want + nuw).
Note that the columns is automatically reset to window width once you resize the window, so this manual setting is not persistent.