Last active
October 18, 2025 20:00
-
Star
(128)
You must be signed in to star a gist -
Fork
(0)
You must be signed in to fork a gist
-
-
Save romainl/ce55ce6fdc1659c5fbc0f4224fd6ad29 to your computer and use it in GitHub Desktop.
Revisions
-
romainl revised this gist
Sep 3, 2021 . 2 changed files with 24 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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! This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ augroup Linting autocmd! autocmd FileType python compiler pylint autocmd BufWritePost *.py silent make! <afile> | silent redraw! autocmd QuickFixCmdPost [^l]* cwindow augroup END -
romainl revised this gist
Apr 20, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Linting your code, the vanilla way 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` -
romainl revised this gist
Apr 12, 2020 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 --- [My Vim-related gists](https://gist.github.com/romainl/4b9f139d2a8694612b924322de1025ce). -
romainl revised this gist
Nov 14, 2017 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 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,*.js silent make! <afile> | silent redraw! ## Automatic opening of the quickfix window -
romainl revised this gist
Sep 11, 2017 . 2 changed files with 27 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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. 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 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,23 +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 -
romainl revised this gist
Aug 27, 2017 . 2 changed files with 18 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 probably don't *need* it. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 -
romainl created this gist
Aug 19, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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