Skip to content

Instantly share code, notes, and snippets.

@romainl
Last active October 18, 2025 20:00
Show Gist options
  • Select an option

  • Save romainl/ce55ce6fdc1659c5fbc0f4224fd6ad29 to your computer and use it in GitHub Desktop.

Select an option

Save romainl/ce55ce6fdc1659c5fbc0f4224fd6ad29 to your computer and use it in GitHub Desktop.

Revisions

  1. romainl revised this gist Sep 3, 2021. 2 changed files with 24 additions and 1 deletion.
    23 changes: 23 additions & 0 deletions vanilla-linter.md
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,29 @@ Example:
    autocmd FileType python setlocal makeprg=pylint\ --output-format=parseable
    autocmd FileType javascript setlocal makeprg=eslint\ --format\ compact

    ## Defining `errorformat` (optional)

    The whole point of defining `makeprg` is for Vim to parse the output of the linter and display eventual errors.

    The most sensibly designed compilers/linters default to or can be told to use a simple, machine-readable, output formatting that looks more or less like this:

    path/to/file:123:4 Error message

    That format (and a few variants) is supported by default so there is no need to do anything but some compilers/linters are not as sensibly designed and you might have to handle silly formatting with ASCII arrows, multi-line messages, etc. In such a case, writing a custom `errorformat` is pretty much an obligation. See `:help errorformat` for the nitty-gritty.

    ## "Compiler"

    Chances are your linter is already natively supported via the "Compiler" feature, in which case you don't have to define either `makeprg` or `errorformat`. You simply need to call the `:compiler` command with the name of your linter as argument and you are set:

    :compiler eslint

    Of course, calling that command manually for every file you edit is not an exciting prospect but you can use an autocommand like the ones above to make it all automatic:

    autocmd FileType python compiler pylint
    autocmd FileType javascript compiler eslint

    There are currently 96 supported "compilers" so it might be a good idea to `:view $VIMRUNTIME/compiler` (and consider adding it to the default distribution if it is not ;-)).

    ## Automatic execution on `:write`

    autocmd BufWritePost <pattern> silent make! <afile> | silent redraw!
    2 changes: 1 addition & 1 deletion vanilla-linter.vim
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    augroup Linting
    autocmd!
    autocmd FileType python setlocal makeprg=pylint\ --output-format=parseable
    autocmd FileType python compiler pylint
    autocmd BufWritePost *.py silent make! <afile> | silent redraw!
    autocmd QuickFixCmdPost [^l]* cwindow
    augroup END
  2. romainl revised this gist Apr 20, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vanilla-linter.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Linting your code, the vanilla way

    You may *want* a lint plugin to lint your code in Vim but you probably don't *need* it. At least try the built-in way before jumping on the plugin bandwagon.
    You may *want* a linter plugin to lint your code in Vim but you probably don't *need* it. At least try the built-in way before jumping on the plugin bandwagon.

    ## Defining `makeprg`

  3. romainl revised this gist Apr 12, 2020. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion vanilla-linter.md
    Original file line number Diff line number Diff line change
    @@ -27,4 +27,8 @@ Example:

    This autocommand tells Vim to open the quickfix window whenever a quickfix command is executed (like `:make`) AND there are valid errors to display.

    autocmd QuickFixCmdPost [^l]* cwindow
    autocmd QuickFixCmdPost [^l]* cwindow

    ---

    [My Vim-related gists](https://gist.github.com/romainl/4b9f139d2a8694612b924322de1025ce).
  4. romainl revised this gist Nov 14, 2017. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions vanilla-linter.md
    Original file line number Diff line number Diff line change
    @@ -6,11 +6,12 @@ You may *want* a lint plugin to lint your code in Vim but you probably don't *ne

    autocmd FileType <filetype> setlocal makeprg=<external command>

    This autocommand tells Vim to use `<external command>` when invoking `:make %` in a `<filetype>` buffer. You can add as many similar lines as you need.
    This autocommand tells Vim to use `<external command>` when invoking `:make %` in a `<filetype>` buffer. You can add as many similar lines as needed for other languages.

    Example:

    autocmd FileType python setlocal makeprg=pylint\ --output-format=parseable
    autocmd FileType javascript setlocal makeprg=eslint\ --format\ compact

    ## Automatic execution on `:write`

    @@ -20,7 +21,7 @@ This autocommand tells Vim to run `:make` on the current file matching `<pattern

    Example:

    autocmd BufWritePost *.py silent make! <afile> | silent redraw!
    autocmd BufWritePost *.py,*.js silent make! <afile> | silent redraw!

    ## Automatic opening of the quickfix window

  5. romainl revised this gist Sep 11, 2017. 2 changed files with 27 additions and 18 deletions.
    28 changes: 27 additions & 1 deletion vanilla-linter.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,29 @@
    # Linting your code, the vanilla way

    You may *want* a lint plugin to lint your code in Vim but you probably don't *need* it.
    You may *want* a lint plugin to lint your code in Vim but you probably don't *need* it. At least try the built-in way before jumping on the plugin bandwagon.

    ## Defining `makeprg`

    autocmd FileType <filetype> setlocal makeprg=<external command>

    This autocommand tells Vim to use `<external command>` when invoking `:make %` in a `<filetype>` buffer. You can add as many similar lines as you need.

    Example:

    autocmd FileType python setlocal makeprg=pylint\ --output-format=parseable

    ## Automatic execution on `:write`

    autocmd BufWritePost <pattern> silent make! <afile> | silent redraw!

    This autocommand tells Vim to run `:make` on the current file matching `<pattern>` whenever you `:write` it. You can add patterns if you want that to happen with other filetypes.

    Example:

    autocmd BufWritePost *.py silent make! <afile> | silent redraw!

    ## Automatic opening of the quickfix window

    This autocommand tells Vim to open the quickfix window whenever a quickfix command is executed (like `:make`) AND there are valid errors to display.

    autocmd QuickFixCmdPost [^l]* cwindow
    17 changes: 0 additions & 17 deletions vanilla-linter.vim
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,6 @@
    augroup Linting
    autocmd!

    " This autocommand tells Vim to use '<external command>' when invoking ':make %' in a '<filetype>' buffer.
    " You can add as many similar lines as you need.
    "
    " autocmd FileType <filetype> setlocal makeprg=<external command>
    "
    " Example:
    autocmd FileType python setlocal makeprg=pylint\ --output-format=parseable

    " This autocommand tells Vim to run ':make' on the current file matching '<pattern>' whenever you ':write' it.
    " You can add patterns if you want that to happen with other filetypes
    "
    " autocmd BufWritePost <pattern> silent make! <afile> | silent redraw!
    "
    " Example:
    autocmd BufWritePost *.py silent make! <afile> | silent redraw!

    " This autocommand tells Vim to open the quickfix window whenever a quickfix command is
    " executed (like ':make') AND there are valid errors to display.
    autocmd QuickFixCmdPost [^l]* cwindow
    augroup END
  6. romainl revised this gist Aug 27, 2017. 2 changed files with 18 additions and 1 deletion.
    2 changes: 1 addition & 1 deletion vanilla-linter.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    # Linting your code, the vanilla way

    You may *want* a lint plugin to lint your code in Vim but you don't *need* it.
    You may *want* a lint plugin to lint your code in Vim but you probably don't *need* it.
    17 changes: 17 additions & 0 deletions vanilla-linter.vim
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,23 @@
    augroup Linting
    autocmd!

    " This autocommand tells Vim to use '<external command>' when invoking ':make %' in a '<filetype>' buffer.
    " You can add as many similar lines as you need.
    "
    " autocmd FileType <filetype> setlocal makeprg=<external command>
    "
    " Example:
    autocmd FileType python setlocal makeprg=pylint\ --output-format=parseable

    " This autocommand tells Vim to run ':make' on the current file matching '<pattern>' whenever you ':write' it.
    " You can add patterns if you want that to happen with other filetypes
    "
    " autocmd BufWritePost <pattern> silent make! <afile> | silent redraw!
    "
    " Example:
    autocmd BufWritePost *.py silent make! <afile> | silent redraw!

    " This autocommand tells Vim to open the quickfix window whenever a quickfix command is
    " executed (like ':make') AND there are valid errors to display.
    autocmd QuickFixCmdPost [^l]* cwindow
    augroup END
  7. romainl created this gist Aug 19, 2017.
    3 changes: 3 additions & 0 deletions vanilla-linter.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    # Linting your code, the vanilla way

    You may *want* a lint plugin to lint your code in Vim but you don't *need* it.
    6 changes: 6 additions & 0 deletions vanilla-linter.vim
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    augroup Linting
    autocmd!
    autocmd FileType python setlocal makeprg=pylint\ --output-format=parseable
    autocmd BufWritePost *.py silent make! <afile> | silent redraw!
    autocmd QuickFixCmdPost [^l]* cwindow
    augroup END