I often edit files with overlong lines. Therefore, I would prefer to :set nowrap to visually retain the structure better. But using nowrap, I live in fear of not seeing a part that is essential to whatever I edit (or worse, could change the meaning dramatically).
Is there any way to accentuate non-wrapped overlong lines (I didn't find anything from a look at the help)?
Check the help for listchars:
extends:c Character to show in the last column, when 'wrap' is
off and the line continues beyond the right of the
screen.
Related
I would like vim to scroll horizontally like nano does, by scrolling only the current line, not the whole screen.
I tried playing with nowrap and scrolloff settings, without success.
Here are some screenshots (with the cursor at the end of a long line) to explain myself.
Nano:
Vim (wrap):
Vim (nowrap):
Thanks!
No, Vim cannot do this, and I think it would be hard to implement this in a way that isn't inconsistent or confusing to the user. There would need to be an indicator (like with side scrolling) that only the current line is scrolled. Also in Vim, there are several commands (like j / k and i_CTRL-Y / i_CTRL-E) that refer to the same column in above / below lines. A partially scrolled view state would make it difficult to use those.
That said, you can sort-of achieve this with a hack: The foldtext of folded lines does not scroll horizontally. So if you fold each individual line (other than the current one) via a custom 'foldexpr', set the fold text to be the line's text, and automatically close all surrounding folds, you'll get this. However, as you'll lose syntax highlighting and "normal" folding, this is more for demonstration than an actual solution.
I would like a folded line to display only "-" characters: no text at all.
I have tried defining foldtext per examples here and in help:. I was able to eliminate the first line contents, which were extremely annoying and completely illogical to my thinking, but it still displays
---"3 lines folded"-------
for example.
(For me it is visually distracting and irrelevant...partly defeats the purpose of folding for me, which is to HIDE the collapsed section, not to HIGHLIGHT it, which is what this redundant message does.)
You do not say what you tried that did not work, but with
:set foldtext='---'
I see a line of dashes (full width) in place of the fold. If you want even less distraction than that, try
:set fillchars+=fold:\ foldtext='\ '
(There are two spaces after the first backslash.)
You can use following settings in your .vimrc:
set foldtext=EmptyFoldText()
function! EmptyFoldText()
return '-'
endfunction
Works fine on my vim.
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.
In both Eclipse and Notepad++, I have my text editors configured so a space has a semi-transparent dot in the center, which makes it easy to count whitespace. I prefer to use spaces instead of tabs in my text editing, and this feature is crucial when working with a whitespace-sensitive language like Python.
I have attached a screenshot with some dummy code in case my wording wasn't clear.
At any rate, is there any way to come close to this functionality in Vim (or GVim)? I suppose there is highlighting but that does seem a bit subpar. There's also good old fashioned math by looking at the column number. What are my other options?
Thes lines in your vimrc should give you an approximation but you won't get dots for normal or leading space: only trailing spaces. That's a Vim limitation.
set list
set listchars=
set listchars+=tab:»\
set listchars+=extends:›
set listchars+=precedes:‹
set listchars+=nbsp:·
set listchars+=trail:·
See :help 'list' and :help 'listchars.
I agree with romainl's answer, but would like to add a mention of the indent guides, which can colour indentation based on your current tab size settings.
In vim, I set shiftwidth=2, but all my previous indents are still at the default 8. How can I change the previous indents from 8 to 2?
You can reindent the whole file with gg=G. gg goes to the first line, = indents (taking a movement), G goes to the last line.
If you're using set expandtab (like you should), you can modify the indentation in a file with
:%s/^ */ /
The settings affect how changes are made, but do not themselves make changes to the file.
If your original indents were achieved using hard tabs stops, then one trick you can do is this. Set the hard tab stop to 2:
:set ts=2
Now you have the two-space indentation (but achieved with hard tabs).
Now, do
:retab 8
This means, roughly, change the hard tab size to 8 (as if by :set ts=8) but at the same time edit all the tabbing in the buffer so that the indentation's appearance does not change.
So now the buffer is still indented to two spaces, but now :ts is back to 8.
If you have :expandtab set, then the indentation is now all spaces, otherwise it is a combination of 8-space tabs and spaces.
Even if this doesn't apply to your situation, retab is good to know because it's handy for dealing with sources that use hard tabs and that you'd like to convert to use spaces and a different indentation level at the same time.