We’re rewarding the question askers & reputations are being recalculated! Read more.
37

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 ...


35

I am the author of the plugin vim-table-mode. 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 | | ...


17

You can use: :set display+=lastline 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.


15

There is a great VimCast on this topic. http://vimcasts.org/episodes/formatting-text-with-par/ Basically, you need to install par: $ brew install par # or $ 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 ...


11

From :help usr_25: JUSTIFYING TEXT Vim has no built-in way of justifying text. However, there is a neat macro package that does the job. To use this package, execute the following command: :...


10

Autocommands to the rescue! Put these lines in your vimrc: augroup quickfix autocmd! autocmd FileType qf setlocal wrap augroup END There's also this slightly cleaner method: create ~/.vim/after/ftplugin/qf.vim, and put this line in it: setlocal wrap The first method adds yet another autocommand to the possibly large pile of autocommands already ...


9

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 function! ModifyTextWidth() if getline(".")=~'^.*\[.*\](.*)$' " If the line ends with Markdown link - set big value for textwidth setlocal textwidth=500 ...


8

Since you don't have wrapping for comments enabled, the workaround in this Stack Overflow post can be used: set comments+=n:# set fo+=q 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 ...


8

You can indeed use an autocommand: augroup MyStuff autocmd! autocmd FileType qf setlocal wrap augroup END 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 ...


6

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: gqie or gwie (to maintain cursor position). If you only want to reformat text from current text position (I see ...


6

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. Cons: Uses sed and column. Vim is incidental. The sed commands can probably be changed to vim :substitute ...


6

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. So: setlocal comments+=nb:> setlocal fo+=q After doing these, I get the expected wrapping: > Tempus. Vivamus. Dis natoque vitae erat. Consectetuer adipiscing > nullam nec gravida non, at posuere ...


5

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 ...


5

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 ...


5

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. So… add the line below to your vimrc: set printoptions+=formfeed:y insert a form feed where you want your page break to occur with <C-l> in insert mode, do :...


5

I think, you can use an BufEnter autocommand, that checks, whether the file is modifiable. Something like this should work (untested): augroup ReadOnly au! au BufEnter * if (!&modifiable || &ro) | setl wrap | endif augroup END


4

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 to reformat This is how I personally format my atx-style Markdown headers, anyway: I think it looks better and is easier to read.


4

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 ...


4

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 ...


4

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 ('...


4

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 ...


4

You can do this by setting textwidth, and removing t from formatoptions. set textwidth=29 set formatoptions-=t 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 ...


3

Try this: augroup MyGundo au! au BufWinEnter __Gundo_Preview__ :setl linebreak wrap augroup end


3

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 :'<,'>:!tablign (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.


3

Try turning off automatic formatting: set formatoptions= 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 ....


3

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 ...


3

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.


3

Here is a solution which is not perfect but not that bad: First add these lines to your .vimrc: function! ReJoinTags() range set nowrapscan let @/='<\(\k\+\)>\([^<]\|\n\)\{-}<\/\1>' let initialLine = line(".") normal ngnJ if initialLine != line(".") call ReJoinTags() endif endfunction Put your cursor on the ...


3

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 ...


3

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.


Only top voted, non community-wiki answers of a minimum length are eligible