8000 GitHub - wsdjeg/format.nvim: asynchronous code formatting plugin
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

asynchronous code formatting plugin

License

Notifications You must be signed in to change notification settings

wsdjeg/format.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

format.nvim

format.nvim is an asynchronous code formatting plugin for neovim.

GPLv3 License

Install

With nvim-plug

require('plug').add({
  {
    'wsdjeg/format.nvim',
    cmds = { 'Format' },
  },
})

Configuration

require('format').setup({
  custom_formatters = {
    lua = {
      exe = 'stylua',
      args = { '-' },
      stdin = true,
    },
  },
})

Usage

  • :Format: format current buffer

format code block in markdown:

require('plug').add({
  {
    'wsdjeg/format.nvim',
    config = function()
      require('format').setup({
        custom_formatters = {
          lua = {
            exe = 'stylua',
            args = { '-' },
            stdin = true,
          },
        },
      })
    end,
    config_before = function()
      vim.keymap.set('n', '<leader>bf', '<cmd>Format<cr>', { silent = true })
      vim.keymap.set('n', '<leader>lf', function()
        local cf = vim.call('context_filetype#get')
        if vim.o.filetype == 'markdown' and cf.filetype ~= 'markdown' then
          local line1 = cf['range'][1][1]
          local line2 = cf['range'][2][1]
          vim.cmd(string.format('%s,%sFormat! %s', line1, line2, cf.filetype))
        end
      end, { silent = true })
    end,
    cmds = { 'Format' },
    depends = { { 'Shougo/context_filetype.vim' } },
  },
})

Self-Promotion

Like this plugin? Star the repository on GitHub.

Love this plugin? Follow me on GitHub and Twitter.

Feedback

If you encounter any bugs or have suggestions, please file an issue in the issue tracker

0