]> git.madduck.net Git - etc/vim.git/blob - README.mdown

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge pull request #93 from pmrowla/ignore-count
[etc/vim.git] / README.mdown
1 vim-flake8
2 ==========
3 `vim-flake8` is a Vim plugin that runs the currently open file through Flake8,
4 a static syntax and style checker for Python source code.  It supersedes both
5 [vim-pyflakes](https://github.com/nvie/vim-pyflakes) and
6 [vim-pep8](https://github.com/nvie/vim-pep8).
7
8 [Flake8](https://pypi.python.org/pypi/flake8/) is a wrapper around PyFlakes
9 (static syntax checker), PEP8 (style checker) and Ned's MacCabe script
10 (complexity checker).
11
12
13 Installation
14 ------------
15
16 Make sure you've installed the
17 [flake8](https://pypi.python.org/pypi/flake8/) package.
18
19 If you use vim >= 8, install this plugin with:
20 ```
21 mkdir -p ~/.vim/pack/flake8/start/
22 cd ~/.vim/pack/flake8/start/
23 git clone https://github.com/nvie/vim-flake8.git
24 ```
25
26 Otherwise, install [vim-pathogen](https://github.com/tpope/vim-pathogen)
27 if you're not using it already. Then, simply put the
28 contents of this repository in your `~/.vim/bundle` directory.
29
30 Usage
31 -----
32 1. Open a Python file
33 2. Press `<F7>` to run `flake8` on it
34
35 It shows the errors inside a quickfix window, which will allow your to quickly
36 jump to the error locations by simply pressing [Enter].
37
38 If any of `g:flake8_show_in_gutter` or `g:flake8_show_in_file` are set to `1`, call:
39
40     call flake8#Flake8UnplaceMarkers()
41
42 To remove all markers. No default mapping is provided.
43
44 Customization
45 -------------
46 If you don't want to use the `<F7>` key for flake8-checking, simply remap it to
47 another key.  It autodetects whether it has been remapped and won't register
48 the `<F7>` key if so.  For example, to remap it to `<F3>` instead, use:
49
50     autocmd FileType python map <buffer> <F3> :call flake8#Flake8()<CR>
51
52 For flake8 configuration options please consult the following page:
53
54 http://flake8.pycqa.org/en/latest/user/configuration.html
55
56 To customize the location of your flake8 binary, set `g:flake8_cmd`:
57
58     let g:flake8_cmd="/opt/strangebin/flake8000"
59
60 To customize the location of quick fix window, set `g:flake8_quickfix_location`:
61
62     let g:flake8_quickfix_location="topleft"
63
64 To customize the height of quick fix window, set `g:flake8_quickfix_height`:
65
66     let g:flake8_quickfix_height=7
67
68 To customize whether the quickfix window opens, set `g:flake8_show_quickfix`:
69
70     let g:flake8_show_quickfix=0  " don't show
71     let g:flake8_show_quickfix=1  " show (default)
72
73 To customize whether the show signs in the gutter, set `g:flake8_show_in_gutter`:
74
75     let g:flake8_show_in_gutter=0  " don't show (default)
76     let g:flake8_show_in_gutter=1  " show
77
78 To customize whether the show marks in the file, set `g:flake8_show_in_file`:
79
80     let g:flake8_show_in_file=0  " don't show (default)
81     let g:flake8_show_in_file=1  " show
82
83 To customize the number of marks to show, set `g:flake8_max_markers`:
84
85     let g:flake8_max_markers=500  " (default)
86
87 To customize the gutter markers, set any of `flake8_error_marker`, `flake8_warning_marker`,
88 `flake8_pyflake_marker`, `flake8_complexity_marker`, `flake8_naming_marker`. Setting one to
89 the empty string disables it. Ex.:
90
91     flake8_error_marker='EE'     " set error marker to 'EE'
92     flake8_warning_marker='WW'   " set warning marker to 'WW'
93     flake8_pyflake_marker=''     " disable PyFlakes warnings
94     flake8_complexity_marker=''  " disable McCabe complexity warnings
95     flake8_naming_marker=''      " disable naming warnings
96
97 To customize the colors used for markers, define the highlight groups, `Flake8_Error`,
98 `Flake8_Warning`, `Flake8_PyFlake`, `Flake8_Complexity`, `Flake8_Naming`:
99
100     " to use colors defined in the colorscheme
101     highlight link Flake8_Error      Error
102     highlight link Flake8_Warning    WarningMsg
103     highlight link Flake8_Complexity WarningMsg
104     highlight link Flake8_Naming     WarningMsg
105     highlight link Flake8_PyFlake    WarningMsg
106
107 To show the error message of the current line in the ruler, call `flake8#ShowError()`:
108
109     " add binding to call the function
110     nnoremap <C-K> :call flake8#Flake8ShowError()<cr>
111     
112
113 Tips
114 ----
115 A tip might be to run the Flake8 check every time you write a Python file, to
116 enable this, add the following line to your `.vimrc` file (thanks
117 [Godefroid](https://github.com/gotcha)!):
118
119     autocmd BufWritePost *.py call flake8#Flake8()
120
121 This plugin goes well together with the following plugin:
122
123 - [PyUnit](https://github.com/nvie/vim-pyunit) (unit test helper under `<F8>`
124   and `<F9>`)
125
126
127 Max line lengths
128 ----------------
129
130 One particular customization a lot of people like to make is relaxing the
131 maximum line length default.  This is a config setting that should be set in
132 flake8 itself. (vim-flake8 "just" invokes it and deals with showing the output
133 in Vim's quickfix window.)
134
135 To do so, put the following into your `~/.config/flake8` file:
136
137     [flake8]
138     max-line-length = 120
139
140
141 History
142 -------
143 1.6: Deprecated configuring flake8 options through Vim settings.  Instead,
144 advise users to use the `~/.config/flake8` config file.
145
146     - Decprecated options:
147       - `g:flake8_builtins`
148       - `g:flake8_ignore`
149       - `g:flake8_max_line_length`
150       - `g:flake8_max_complexity`
151
152     - New options:
153       - `g:flake8_quickfix_height`
154
155 1.5: Added markers and the option to don't show the quickfix window, also split
156 functions into a autoload file. Added:
157
158     - Options:
159       - `g:flake8_show_quickfix`
160       - `g:flake8_show_in_gutter`
161       - `g:flake8_show_in_file`
162       - `g:flake8_max_markers`
163       - `flake8_error_marker`
164       - `flake8_warning_marker`
165       - `flake8_pyflake_marker`
166       - `flake8_complexity_marker`
167       - `flake8_naming_marker`
168     - Functions:
169       - `flake8#Flake8UnplaceMarkers()`
170       - `flake8#Flake8()`
171     - Highlighting:
172       - `Flake8_Error`
173       - `Flake8_Warning`
174       - `Flake8_Complexity`
175       - `Flake8_Naming`
176       - `Flake8_PyFlake`
177
178 1.4: Suppress output to stdout.
179
180 1.3: Added the following options:
181
182     - `g:flake8_builtins="_,apply"`
183     - `g:flake8_max_complexity=10`
184
185 1.2: Added the following options:
186
187     - `g:flake8_cmd="/opt/strangebin/flake8000"`
188     - `g:flake8_max_line_length=120`
189     - `g:flake8_ignore="E501,W293"`
190
191 1.1: Added `g:flake8_ignore` option.
192
193 1.0: Initial version.
194
195
196 License
197 -------
198
199 Liberally licensed under BSD terms.