17

Or you can install jq which is faster (written in C) from your package manager or from source and then in vim, type : :%!jq .


7

When vim starts, it runs $VIMRUNTIME/ftdetect.vim to find out what type of file you're editing; then, if you have 'ftplugin' set, it sources $VIMRUNTIME/ftplugin.vim which sources $VIMRUNTIME/ftplugin/&filetype.vim (see :help startup for more detail). You can alter or override $VIMRUNTIME/ftplugin.vim or $VIMRUNTIME/ftplugin/&filetype.vim. Create a ...


5

From :help equalprg: 'equalprg' 'ep' string (default "") global or local to buffer |global-local| External program to use for "=" command. ... From :help =: ={motion} Filter {motion} lines through the external program given with the 'equalprg' option. When the 'equalprg' ...


4

You can use the new line character is your search (\n for linux): :%s/)\s*\n{/){/c Replaces )\s*\n{ into ){ The c flag at the end will ask you to confirm before each replacement. EDIT: Another solution would be to use the join line feature (J) with the g command: :g/function [^{]\+$/join Which will execute the command join on every line matching the ...


2

set fo-=r fo -=o *'formatoptions'* *'fo'* 'formatoptions' 'fo' string (default: "tcqj", Vi default: "vt") local to buffer This is a sequence of letters which describes how automatic formatting is to be done. See |fo-table|. When the 'paste' option is on, no formatting is done (like 'formatoptions' is empty). ...


2

Since lot of us Vim users are suffering from this, I went and investigated this bit more. My solution is to create the $HOME/.vim/after/ftplugin.vim as suggested by @abcq2 just to realize, it won't change anything. Given the list given by :scriptnames, that file is source way too early. However, the second suggestion of creating a $HOME/.vim/after/ftplugin/...


2

Since @LucHermitte alluded to a macro-based solution, I thought I'd provide one. qqqqqciw"<C-R>"",<Esc>w@qq@q qqqqqi]<Esc>I[<Esc><BS>@qq@q First line adds in the quotes and commas, the second line adds the brackets. (N.B. in the above, <C-R> means press Ctrl-R, <Esc> means press Esc, and <BS> means press ...


2

There are so many ways to proceed... the simple 2-steps solution :%s/\s\+/', '/g :%s/.*/['&'],/ or, in one step :%s/.*/\="['".substitute(submatch(0), '\s\+', "', '", 'g')."']," or also :%s/.*/\=string(split(submatch(0), '\s\+')).',' or, my preferred one (in Vim script contexts) :call setline(1, map(getline(1,'$'), 'string(split(v:val, "\\s\\+"))."...


2

Well, it is not that simple. What you can come up with -- use syntax definitions. But this bold text you will create would be temporary, it will not be saved with your file like word processing software does. So to the code. func! RegionMakeBold() hi MyBold gui=bold let l_start = getpos("'<")[1] let l_end = getpos("'>")[1] let c_start = ...


2

Line continuation in Ex commands is done by prepending a backslash to the beginning of the continuation lines themselves, not appending it to the end of the preceding lines. See :help line-continuation: Long lines in a :sourced Ex command script file can be split by inserting a line continuation symbol \ (backslash) at the start of the next line. There ...


2

There are a couple of ways to approach this, however each one has its own drawbacks: There is no really good way to re-format a list of strings programmatically according to a different textwidth value. Your current best chances are basically to set the 'textwidth' option and reformat using gq (this can be done in another window to leave the current option ...


1

You just need to do this: :set fo+=n That'll add a flag to "recognize numbered lists" to 'formatoptions' ('fo' for short). Note the details/limitations: This actually uses the 'formatlistpat' option, thus any kind of list can be used. The indent of the text after the number is used for the next line. The default is to find a number, optionally ...


1

Plain text files do not have formatting options like a word processor does. If you want that WYSIWYG functionality like a traditional word processor, then I recommend a word processor like LibreOffice. However, there are document formats that support common formatting with additional syntax. Markdown is a lightweight syntax that is still readable as a ...


1

This works by checking if there is an opening and closing bracket inside the result of a yip. O does nothing if used at the top of the document. function! CommaInList (eol) " enforce eol? let curLine = getline ('.') let curPos = getpos ('.') if a:eol && (curPos[2] < len(curLine)) norm! a^M return endif " current line must ...


1

Since the OP is dealing directly with manpages, I suggest :runtime plugin/man.vim (Which can be put in startup files), followed by :Man command Also see help MANPAGER


1

It turns out a negative value for wrapmargin helps: setlocal wrapmargin=-1000 As per :help wrapmargin: Number of characters from the right window border where wrapping starts. So it seems that the :help gq docs are not entirely correct, and with textwidth=0, wrapmargin is also considered when picking a column to wrap at.


1

Would the following substitutions help you? :s/\(.\)/'\1', /g :s/, $// The first wraps all the characters with quotes and with comma and space afterwards (in the current line only). The second removes the last comma and space from the line (again, current line only).


1

If PHP is available, add the tool jf as a JSON Formatter by Composer: $ composer global require codegear/json-formatter Then Format current file: :%!jf % Or add a keymap in vimrc: nnoremap <Leader>jf :%!jf %<CR>


1

For the sake of completeness, I'd like to mention the plugin-based option. If you use something like ALE which supports running your buffers through a beautifier on save, you could let Prettier handle rewrapping your code. I accomplished that by putting this in ~/.vim/ftplugin/markdown.vim: let b:ale_fixers = ['prettier', 'remove_trailing_lines', '...


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