45

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


40

You can use the gq or gw operators combined with a motion command. By default, formatting of applicable text is done by Vim and to the best of my knowledge it does not justify the lines (you will get ragged right margins). Alternatively, an external program (e.g. the fmt command on Linux) can be used to do the formatting by specifying it with the formatprg ...


19

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


18

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.


14

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


11

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


10

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


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

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


8

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


7

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


7

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


6

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


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


6

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


6

You can use the gj and gk commands to move the cursor to the character in the next or previous display lines, even when lines wrap. See :help gj and :help gk for details. If you would like to navigate those display lines using j and k, you can remap them in your .vimrc: nnoremap j gj nnoremap k gk Beware that these remappings have side effects, for ...


5

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


5

As per Kenny Evitt's answer, you can find where textwidth is being set using verbose: :verbose set tw? textwidth=78 Last set from c:\Program Files (x86)\Vim\vim74\vimrc_example.vim If you are happy editing that file, do so. If you would prefer not to edit whichever file (or cannot), then you can override it in your own .vimrc (or _vimrc) file. If ...


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

In my case, Vitor's comment suggested I run the following: :verbose set tw? Doing so gave me the following output: textwidth=78 Last set from C:\Program Files (x86)\Vim\vim74\vimrc_example.vim In vimrc_example.vim, I found the relevant lines: " Only do this part when compiled with support for autocommands. if has("autocmd") ... " For all ...


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

Maybe it sounds too simplistic, but why not %!fmt -9999


4

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 each paragraph. From the vim help about the global command: The global commands work by first scanning through the lines and marking each line where a match ...


3

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


3

This is not possible without some serious hackery. In fact, I can't really think of a hack short of modifying the Vim source code. I also doubt that you really want this. The definition of a "line" is 0 or more characters ended by a newline, if you change that definition, you change a lot in Vim. For example, what would you expect a command like :s/A/B/ to ...


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