All Projects → lukas-reineke → format.nvim

lukas-reineke / format.nvim

Licence: other
Neovim lua plugin to format the current buffer with external executables

Programming Languages

lua
6591 projects
Vim Script
2826 projects

Projects that are alternatives of or similar to format.nvim

Nvim Treesitter Context
Show code context
Stars: ✭ 113 (-40.21%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
cmp-under-comparator
nvim-cmp comparator function for completion items that start with one or more underlines
Stars: ✭ 77 (-59.26%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Vim Clap
👏 Modern performant fuzzy picker for Vim and NeoVim
Stars: ✭ 1,802 (+853.44%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Todoist.nvim
A todoist extension for neovim
Stars: ✭ 84 (-55.56%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Visual Split.vim
Vim plugin to control splits with visual selections or text objects
Stars: ✭ 190 (+0.53%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Asyncrun.vim
🚀 Run Async Shell Commands in Vim 8.0 / NeoVim and Output to the Quickfix Window !!
Stars: ✭ 1,332 (+604.76%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Targets.vim
Vim plugin that provides additional text objects
Stars: ✭ 2,114 (+1018.52%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Alchemist.vim
Elixir Integration Into Vim
Stars: ✭ 632 (+234.39%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Animate.vim
A Vim Window Animation Library
Stars: ✭ 173 (-8.47%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Neotex
latex live preview - plugin for neovim and vim 8
Stars: ✭ 170 (-10.05%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
virt-column.nvim
Display a character as the colorcolumn
Stars: ✭ 64 (-66.14%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Vim Vsnip
Snippet plugin for vim/nvim that supports LSP/VSCode's snippet format.
Stars: ✭ 224 (+18.52%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Crease.vim
Easy foldtext customization for [neo]vim.
Stars: ✭ 19 (-89.95%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Neovim Fuzzy
Fuzzy file finding for neovim
Stars: ✭ 103 (-45.5%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Context.vim
Vim plugin that shows the context of the currently visible buffer contents
Stars: ✭ 688 (+264.02%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Vem Tabline
A lightweight Vim/Neovim plugin to display buffers and tabs in the tabline
Stars: ✭ 129 (-31.75%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Tmux Complete.vim
Vim plugin for insert mode completion of words in adjacent tmux panes
Stars: ✭ 447 (+136.51%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Vim Markdown Composer
An asynchronous markdown preview plugin for Vim and Neovim.
Stars: ✭ 501 (+165.08%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Vim Dadbod Completion
Database autocompletion powered by https://github.com/tpope/vim-dadbod
Stars: ✭ 163 (-13.76%)
Mutual labels:  neovim, vim-plugin, neovim-plugin
Indent Blankline.nvim
Indent guides for Neovim
Stars: ✭ 203 (+7.41%)
Mutual labels:  neovim, vim-plugin, neovim-plugin

Format.nvim

format.nvim applies formatting to the current buffer.

Main goals

  1. fast
  2. async
  3. no magic

Deprecated

I am no longer actively maintaining this plugin.
Instead I recommend to use native LSP formatting with mattn/efm-langserver or jose-elias-alvarez/null-ls.nvim.

Or for a non-LSP solution, mhartington/formatter.nvim (for which I am also a maintainer)

Details

format.nvim is a lua plugin and only works in Neovim.

It writes the buffer content into a temporary file, runs user defined commands on that file, then writes the content back into the buffer.

Everything happens asynchronously.

There is no hidden configuration to resolve executables. The commands are run as is. If you need a specific executable, define the path in the command.

By default unsaved changes will not be overwritten, so Format and FormatWrite are safe to call anytime.

Embedded syntax blocks.

format.nvim supports formatting embedded blocks of code with different command than the current filetype. For example lua << EOF blocks in vimscript, or code blocks in markdown. Just specify a start and end-pattern.

Format on save

There is no format on save functionality build in, the plugin only provides the Format and FormatWrite commands. To format on save, you can put this in your vimrc

augroup Format
    autocmd!
    autocmd BufWritePost * FormatWrite
augroup END

Example configuration

Please see :help format.txt for more information on configuration.

require "format".setup {
    ["*"] = {
        {cmd = {"sed -i 's/[ \t]*$//'"}} -- remove trailing whitespace
    },
    vim = {
        {
            cmd = {"luafmt -w replace"},
            start_pattern = "^lua << EOF$",
            end_pattern = "^EOF$"
        }
    },
    vimwiki = {
        {
            cmd = {"prettier -w --parser babel"},
            start_pattern = "^{{{javascript$",
            end_pattern = "^}}}$"
        }
    },
    lua = {
        {
            cmd = {
                function(file)
                    return string.format("luafmt -l %s -w replace %s", vim.bo.textwidth, file)
                end
            }
        }
    },
    go = {
        {
            cmd = {"gofmt -w", "goimports -w"},
            tempfile_postfix = ".tmp"
        }
    },
    javascript = {
        {cmd = {"prettier -w", "./node_modules/.bin/eslint --fix"}}
    },
    markdown = {
        {cmd = {"prettier -w"}},
        {
            cmd = {"black"},
            start_pattern = "^```python$",
            end_pattern = "^```$",
            target = "current"
        }
    }
}

Mentions

At first this was supposed to be a PR to mhartington/formatter.nvim but I ended up rewriting everything.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].