Giter VIP home page Giter VIP logo

vim-shfmt's Introduction

Vim plugin for shfmt

The Vim shfmt plugin runs shfmt to auto format the current buffer by a command :Shfmt. If instead you prefer to format a textobject, say a paragraph, by gq, then add to the file after/ftplugin/sh.vim in your Vim configuration folder the lines

if executable('shfmt')
  let &l:formatprg='shfmt -i ' . &l:shiftwidth . ' -ln posix -sr -ci -s'
endif

and press, say gqip. Customize the options -ln posix -sr -ci -s to your liking.

Requirements

You just need the shfmt command

Installation

Obtain a copy of this plugin and place shfmt.vim in your Vim plugin directory or be sensible and use something like Plug:

Plug 'z0mbix/vim-shfmt', { 'for': 'sh' }

Usage

You can use the :Shfmt command to run shfmt and automatically format the current buffer

You can also use the :Shfmt command together with options. For example,

:Shfmt -p
:Shfmt -i 2

Configuration

shfmt uses tabs by default for auto formatting, so if you prefer to use 2 spaces, you can set the following in your .vimrc file:

let g:shfmt_extra_args = '-i 2'

Auto format on save

If you would like to auto format shell scripts on save, you can add the following to your vim config:

let g:shfmt_fmt_on_save = 1

License

The Vim shfmt plugin is open-sourced software licensed under the MIT license.

vim-shfmt's People

Contributors

alpayne avatar konfekt avatar z0mbix avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.