5

To format in a deterministic way, we need to sort the hash. None of the other answers did that for me, so I created my own: function! FormatJson() python << EOF import vim import json try: buf = vim.current.buffer json_content = '\n'.join(buf[:]) content = json.loads(json_content) sorted_content = json.dumps(content, indent=4, ...


5

You can add the following to your .vimrc 1. function FormatBuffer() 2. if &modified && !empty(findfile('.clang-format', expand('%:p:h') . ';')) 3. let cursor_pos = getpos('.') 4. :%!clang-format 5. call setpos('.', cursor_pos) 6. endif 7. endfunction 8. 9. autocmd BufWritePre *.h,*.hpp,*.c,*.cpp,*.vert,*.frag :call FormatBuffer()...


3

In the absence of a complete solution, I thought I'd just write a quick answer that shows one way you can achieve the first part of your question. Try the following mapping (for F3): nnoremap <F3> :s/%>%/&\r/g<CR>V``j=gv>> How it works Splitting the line First, it breaks the line on the pipes: :s/%>%/&\r/g :s/ #...


3

The script that controls Vim's indentation of Python files is located at $VIMRUNTIME/indent/python.vim. You can see the help file for it with :help ft-python-indent. From that, we learn there are a few global variables that can be used to control the indentation's behaviour: The amount of indent can be set for the following situations. The examples ...


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

If you are using an auto-pairs-style plugin, it is most likely trying to delete the closing "; not finding one, it erroneously deletes further. As mentioned in the comments, these plugins generally cause more headache than they’re worth (YMMV). Snippets provide a more flexible alternative (though the author has very little experience with them).


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

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

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

Not sure if this what you want, but try reading: https://vimways.org/2018/formatting-lists-with-vim/ What I have in my settings regarding list formatting: setlocal formatoptions=tcqln setlocal formatlistpat=^\\s* setlocal formatlistpat+=[ setlocal formatlistpat+=\\[({]\\? setlocal formatlistpat+=\\( setlocal formatlistpat+=[0-9]\\+ setlocal formatlistpat+=\...


1

I use this :Jsonf command. It's can format unicode. command! Jsonf :execute '%!python -c "import json,sys,collections,re; sys.stdout.write(re.sub(r\"\\\u[0-9a-f]{4}\", lambda m:m.group().decode(\"unicode_escape\").encode(\"utf-8\"),json.dumps(json.load(sys.stdin, object_pairs_hook=collections.OrderedDict), indent=2)))"'


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


1

As jecxgo points out, the problem is that the obvious solution of recording a macro that processes a single line and then applying that to the selection of lines with :normal fails because, when the lines are expanded, this messes with the other lines in the range. jecxgo solves this by not expanding the lines within the macro but instead doing so in a ...


1

My answer is very similar to Martin Tournoij (full credit to him). This just makes it in a single-line command. When you run this, it will disable continuation of comment permanently: echo 'au FileType * set fo-=c fo-=r fo-=o' >> ~/.vimrc


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