10
votes
Accepted
How do I configure vim to show a character when a line is too long to be displayed?
You should the this
:set listchars+=precedes:<,extends:>
Ref:
:h wrap
:h 'listchars'
10
votes
Accepted
Automatically breaking lines in comments?
I like this one
augroup comment_textwidth
autocmd!
autocmd TextChanged,TextChangedI * :call AdjustTextWidth()
augroup END
function! AdjustTextWidth()
let syn_element = synIDattr(synID(...
9
votes
How to split a line into multiple lines efficiently?
The easiest way I've found to split lines in Vim is the normal mode command gq (type both letters in quick succession in normal or visual mode).
In visual mode, it will split whatever is selected, in ...
8
votes
Accepted
What is the significance of "Incomplete last line" when opening a file?
The Unix convention is that a line is a sequence of zero or more characters ending with a newline character. A text file is a sequence of such lines. This is just a convention, but adhering to that ...
8
votes
Accepted
What does breakat&vim mean?
It resets the breakat option to the Vim default: ^I!@*-+;:,./?.
Where ^I stands for the tab character.
You get the corresponding help paragraph with the :help :set-default command.
:se[t] {option}&...
7
votes
how to avoid vim breaking line beyond 80 characters in fortran files
'textwidth' is local to the buffer. I imagine Vim's default fortran plugin ($RUNTIME/ftplugin/fortran.vim) is setting 'textwidth'.
To override this default add the following to ~/.vim/after/ftplugin/...
7
votes
Why is a Line Feed converted into a Null character inside the search register and into a Carriage Return on the command line?
First, thank you for this very comprehensive and thoughtful post.
After some testing, I have come to this conclusion:
Control characters are displayed using the caret notation: ^M for <CR> (...
7
votes
Accepted
6
votes
Can I join lines with a comma (or another character)?
Just in case someone doesn't like typing Regex and memorizing more Plugin Ex Commands:
Visual-block Append
Visual-block Append is available in the Visual Block mode (<C-v>) and can do a block ...
6
votes
Accepted
Why does not Vim feed the correct set of newline characters?
There are two problems with your approach.
First is using -b which turns on the 'binary' setting and the binary setting will ignore fileformat. See this snippet of :help 'binary':
Also, '...
5
votes
Accepted
Line formatting (gq) does not correctly indent long list items
As far as I can tell (and from @Antony's comments), autoindent must be turned on for this to work. From the help pages:
When autoindent is on, formatting (with the "gq" command or when you reach '...
5
votes
Accepted
Join multiple lines
I got the macro working:
qqgg5j^V4j$xgg$p9jV4kd
qq starts a macro called q
gg sets the startingpoint to the first line of the file
5j goes down 5 lines (the start of the block below it)
^V4j$ goes ...
5
votes
Accepted
Adding new characters cause splitting line into many lines
Try set textwidth=0 to not break up long lines. See :h tw. Note that if you set the textwidth to 0, then wrapmargin might take effect, see :h wm, so consider also using set wrapmargin=0.
5
votes
Join all non-blank lines
You were almost there:
v/^$/norm vipJ
For each matching line it selects the inner paragraph(without following newline) und joins.This works because, the command is only executed for the first line of ...
4
votes
Still force new line at end, but show it too?
Like so many people, you seem to mix up "new line" and "newline".
When editing a file where the last line doesn't end with a "newline" character, Vim will add that "newline" character on write unless ...
4
votes
How to join lines without producing a space?
Create a macro and reuse it:
qaJxq
Now replay the macro, a by using @a wherever you want to join two lines with no space.
@@ will repeat the previous macro. So you can just hold @ to join multiple ...
4
votes
Accepted
Automatic wrapping to new line?
You could work with wrapmargin:
set textwidth=0
set wrapmargin=1
set formatoptions+=t
set formatoptions-=l
The option wrapmargin defines the number of characters from the right window border where ...
4
votes
Automatic wrapping to new line?
Set
set textwidth=50
The 'textwidth' option can be used to automatically break a line
before it gets too long. Set the 'textwidth' option to the desired
maximum line length. If you then type ...
4
votes
Join all non-blank lines
Normal substitution:
%s/\([^\n]\)\n\([^\n]\)/\1 \2/
Substitution with magic mode, so as to drop escaping ():
%s/\v([^\n])\n([^\n])/\1 \2/
Explanation:
([^\n]) is any character except a newline in ...
3
votes
Accepted
How to make linebreak play along with conceal
No it is not possible. Wrapping occurs on the real characters on the line and not on the concealed characters. Note, that if this would be possible, this would cause kind of "wobbling" effect just by ...
3
votes
How to join lines without producing a space?
To always join with a single space :
nmap J gJi <ESC>ciW <ESC>
To join with no space at all (removes trailing+leading space) :
nmap <C-J> gJi <ESC>diW
3
votes
Join multiple lines
What you do is almost .. graphical, so I'd use the mouse!
(of course you need :set mouse+=a)
Select a block with the mouse, then Ctrl-v y to yank the selection in "control-block" mode (<- that's ...
3
votes
Join multiple lines
Another macro solution:
First go to the beginning of the first paragraph (in your example with 10G)
Then record macro: qqCtrl-Shit-V}$d5k$p0q
Reuse the macro with @q
The detail of the macro:
Ctrl-...
3
votes
'endofline' option stays false after write operation
This behavior is intentional, to keep track of the original [noeol] status of the file when it was first read.
Note that you can control whether to keep the original [noeol] status of a file when ...
3
votes
Join all non-blank lines
Why it doesn't work
The reason your command works that way is that all the lines are marked for action first, then the join is run (aside: you can use :v/.../j to use the ex-command :join instead of :...
3
votes
Accepted
How to insert a blank line above another line
You can make use of the :g command. There are probably already answers here on how to use :g and there is also this famous wiki article on the same topic
In short, you simply run:
:g/^Q/:-put =''
...
3
votes
How to insert a blank line above another line
To follow up on @Christian Brabandt's answer, you can use the O key (see :help O) and do:
:g/^Q/norm O
norm allows to run a key command (O, dd, .....) in a command.
:g can take a range also, so if ...
3
votes
Accepted
Function for recursive linebreak
A solution to review the paragraph you are in is:
gqip
Where:
gq reformat them according to textwidth
ip current paragraph
If you want that to be made for all paragraph while they are edited a ...
3
votes
how to delete every char except newline?
To remove all content of a line, you can use the :substitute command (see :help substitute) like this:
:s/.*//
It will substitute any character (.), repeated 0 or more times (*) with nothing. It will ...
2
votes
Can I join lines with a comma (or another character)?
To get around this limitation we can resolve this problem by splitting it for 2 separate simple problems:
Add separator at the end of each line with one of command:
:%s/$/,/ - :%s search whole file ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
line-breaks × 63wrapping × 13
vimrc × 9
formatting × 8
vimscript × 6
substitute × 4
whitespace × 4
command-line × 3
filetype-markdown × 3
key-bindings × 2
neovim × 2
syntax-highlighting × 2
search × 2
indentation × 2
insert-mode × 2
functions × 2
register × 2
save × 2
multiple-lines × 2
gvim × 1
cursor-motions × 1
folding × 1
macro × 1
terminal-buffer × 1
variables × 1