Giter Site home page Giter Site logo

gofmt.vim's Introduction

gofmt.vim

A Vim plugin that runs gofmt when you save. The cursor position and folds are retained without causing a full screen redraw.

Installation

Follow your package manager's instructions.

Usage

Edit a .go file, then save it. Alternatively, use :Gofmt.

Config

Name Default Description
g:gofmt_exe gofmt Sets the executable to use when saving a file.
g:gofmt_on_save 1 Enables or disables running gofmt on save. Setting this to an empty string effectively disables the plugin

If you want to use goimports instead of gofmt:

let g:gofmt_exe = 'goimports'

gofmt.vim's People

Contributors

mhinz avatar orklann avatar tweekmonster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gofmt.vim's Issues

gofmt adds empty changes to undo tree

Description

Every time gofmt#apply is invoked, another change is added to the undo tree. This is perfectly fine when gofmt actually changes the buffer, but it's unnecessary and inconvenient if the buffer doesn't actually change.

The empty change in the undo tree makes it more effort to navigate the undo tree (for example with u and CTRL-R) and it marks the buffer as modified. This can force users to save the buffer unnecessarily, if the buffer was previously unmodified. This can happen when the function gets invoked in a way other than with the autocmd, like with a mapping.

Suggestion

gofmt#apply could check whether gofmt -l lists its standard input as differing from its formatting. Based on that gofmt#apply could terminate without making any changes to the buffer.

from gofmt --help:

  -l    list files whose formatting differs from gofmt's

The -l option is also supported by goimports.

It might be a good idea to also add an option to enable or disable this behavior, for example if g:gofmt_exe doesn't support the -l flag or if it's undesired for some other reason.

Shows error message in Vim would be perfect

gofmt command line will shows error message if the .go file has some syntax errors, and would not format the .go file. So if any improvement in this plugin to show errors as well in Vim window after saving .go file which has syntax error?

I like this little plugin, and it works fine.

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.