You can use the gq or gw operators combined with a motion command. By default, it uses the fmt program (in Linux) to format the given text. However, to the best of my knowledge, it does not justify the lines so you will get ragged right margins.
The way I use it is to gwip (normal mode) with the cursor on a paragraph. This will format the current paragraph ...
I am the author of the plugin
I've spent quite a lot of time building & improving this, especially with
community feedback and it caters exactly to this use case.
A short quickstart: You enter 'table mode' with the :TableModeEnable command,
you can then simply type:
| MOVIE | QUOTE|
| Blade Runner | Like tears in the rain |
You can use:
From :help 'display':
lastline When included, as much as possible of the last line
in a window will be displayed. When not included, a
last line that doesn't fit is replaced with "@" lines.
There is a great VimCast on this topic.
Basically, you need to install par:
$ brew install par
$ sudo apt-get install par
And then, since you want columns to be wrapped in 80 columns:
:set formatprg=par\ -w80
Now you can use the gq operator, like in other answers (e.g. gqip), and it will use ...
Autocommands to the rescue!
Put these lines in your vimrc:
autocmd FileType qf setlocal wrap
There's also this slightly cleaner method:
and put this line in it:
The first method adds yet another autocommand to the possibly large pile of autocommands already ...
In the past I had similar problem with function signatures. Here is solution adapted to your problem. Add to .vimrc:
au CursorMovedI *.md call ModifyTextWidth() " Use only within *.md files
if getline(".")=~'^.*\[.*\](.*)$' " If the line ends with Markdown link - set big value for textwidth
Since you don't have wrapping for comments enabled, the workaround in this Stack Overflow post can be used:
This adds # as a comment marker (allowing nesting, so that ##, ###, etc. also count).
I'd suggest leaving a space after # and using nb:# - some Markdown parsers require a space after #. The CommonMark spec also supports ...
You can indeed use an autocommand:
autocmd FileType qf setlocal wrap
This will affect the quickfix window, too, but I presume that would be desirable.
You can find a sort of oblique reference to this in the documentation by opening :help location-list and then searching for filetype.
Even better, use Vim's after ...
One way to do it employs the ie (inside-environment) custom text object, available in a number of places: e.g. in the plugin vimtex, or with vim-textobj-latex (and there are others). With this functionality, then the rewrap command becomes:
(to maintain cursor position).
If you only want to reformat text from current text position (I see ...
If you can use sed and column, a command-line solution that comes close would be:
!sed 's/[- ]*\([+|]\)/'$'\x01''\1/g' | column -ts $'\x01' | sed '/^[-+ ]*$/s/ /-/g'
You could combine this with visual selection and '<,'> or with line numbers.
Uses sed and column. Vim is incidental.
The sed commands can probably be changed to vim :substitute ...
From one of my previous answers, you can get this to work if:
You have nb:> in your comments setting.
And you have q in your formatoptions setting.
After doing these, I get the expected wrapping:
> Tempus. Vivamus. Dis natoque vitae erat. Consectetuer adipiscing
> nullam nec gravida non, at posuere ...
While nano's help call the ^J command "Justify" it actually doesn't justify the text, it reformat the text breaking the lines before the right margin of the screen (or at some configurable column, I guess).
You can do the same thing in VIM by setting the variable textwidth, from :help 'textwidth':
Maximum width of text that is being inserted. A longer ...
If you don't want to install any plugins and you want to edit tables keeping the alignment:
-- use the built in VREPLACE mode, activated by gR.
(Make sure you has vim latest version, and check if it's compiled with +vreplace feature, typing vim --version on the terminal)
(my statusline is set to show REPLACE for both REPLACE and VREPLACE modes)
If you ...
From :help popt-option:
formfeed:y When a form feed character is encountered, continue
printing of the current line at the beginning of the
first line on a new page.
add the line below to your vimrc:
insert a form feed where you want your page break to occur with <C-l> in insert mode,
I think, you can use an BufEnter autocommand, that checks, whether the file is modifiable. Something like this should work (untested):
au BufEnter * if (!&modifiable || &ro) | setl wrap | endif
If you're willing to change the way you write your Markdown slightly, you could fix this simply by introducing an extra blank line between your headings and the following text:
# this is a h1
this is the text of the file i want
This is how I personally format my atx-style Markdown headers, anyway: I think it looks better and is easier to read.
Soft wrapping per line is not possible. All you can really do is manually wrap the line with gql and undo it after you're done looking.
It might not be the exact answer that you're looking for, but you can make horizontal scrolling more ergonomic.
nnoremap <left> 5zh
nnoremap <right> 5zl
xnoremap <left> 5zh
xnoremap <right> 5zl
I was thinking about this more. You can't wrap just the current line in the current window, but you can open the buffer in a new window and enable wrapping there without affecting your current window.
Use a new window
split | setlocal wrap
After you're done, close the window that has wrapping enabled.
Use a new tab
If your horizontal space is limited ...
You're looking for g0 and g$ which are the equivalent of 0 and $ for wrapped lines. See :h g0, :h g$ and even :h g^.
To quote the doc about g$:
When lines wrap ('wrap' on): To the last character of
the screen line and [count - 1] screen lines downward
|inclusive|. Differs from "$" when a line is wider
than the screen.
When lines don't wrap ('...
You're looking for :h 'wrap':
This option changes how text is displayed. It doesn't change the text
in the buffer, see 'textwidth' for that.
When on, lines longer than the width of the window will wrap and
displaying continues on the next line. When off lines will not wrap
and only part of long lines will be displayed. When the cursor is
You can do this by setting textwidth, and removing t from formatoptions.
You also need to have the q option enabled in your formatoptions to use gq. It seems to always be on for me, but you might want to add a set formatoptions+=q to be on the safe side.
Shouldn't be a problem with your current usecase, but the c ...
I've created the command-line tool tablign for this purpose; it works from within vim as well. Simply install with
[sudo -H] pip3 install tablign
mark the table in vim and call
(vim fills in the first few characters for you if you've marked the table.)
It can't do fixed column widths yet, but that could be added if need arises.
Try turning off automatic formatting:
If this works, you're going to want to try to track down how it's having an effect. There are two possibilities. Either you have 'wrapmargin' set (which causes Vim to insert newlines when you get within a certain distance of the edge of the window), or something is setting 'textwidth' after your ....
You can use a custom format expression/program to achieve what you want. Check out :help 'formatexpr' and :help 'formatprg' for info on exactly how to do this.
Note that as mentioned in the comments above, there was a bug in vim where the format expression was being called on every key inserted rather than only when the text is supposed to wrap. This has ...
Here are two easy options:
with a block of text selected, type !fmt
with your cursor at the start of a block, type !}fmt
Both of these send a block of text to unix fmt, see man fmt for options. You can pass option arguments from vim. For example, to format a block a 50 characters wide, type !}fmt -w 50.
Here is a solution which is not perfect but not that bad:
First add these lines to your .vimrc:
function! ReJoinTags() range
let initialLine = line(".")
if initialLine != line(".")
Put your cursor on the ...
Unfortunately, this is not possible. There are many many ways to configure how a wrap should occur, such as with textwidth and wrapmargin, but these are only for hardwraps, not softwraps. The only way to change a softwrap is by changing your window size.
There are some plugins that sort of do what you want, where the wrap occurs in an area smaller than your ...
One non-Ideal solution is open another window and then set the vertical res to 80. The command would be:
:vnew | wincmd p | vertical res 80
I know this isn't quite what you had in mind, but it's better than nothing.