Can't jump to line in pyflakes quickfix window - python

I recently installed the vim extension python-mode, which includes pyflakes. When I save a python file to disk, pyflakes automatically detects errors and style violations and displays them in a quickfix window. This screencast shows that hitting enter on an item from the quickfix window should jump to the corresponding line in the source code, but when I hit enter I get the error "E21: Cannot make changes, 'modifiable' is off". I can make the buffer modifiable with :set ma, and then jumping works, but I don't want to have to set this every time.
As suggested in this answer, I've tried to see if a plugin is making the buffer non-modifiable, but couldn't discover anything.
:verbose set modifiable?
nonmodifiable
:verbose setlocal modifiable?
nonmodifiable
Here is my .vimrc:
"set nocompatible
autocmd! bufwritepost .vimrc source %
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 0
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
set cpo&vim
set background=dark
syntax on
set smartindent
set shiftwidth=4
set expandtab
set tabstop=4
set bs=2
set tags=./tags;,/usr/share/vim/vim81/doc/tags;,$HOME/.local/lib/python3.7/site-packages/torch/tags
set tags+=$HOME/.local/lib/python3.7/site-packages/torch/tags
set tags+=$HOME/.local/lib/python3.7/site-packages/torchvision/tags
set tags+=$HOME/.local/lib/python3.7/site-packages/nltk/tags
set tags+=$HOME/anaconda3/lib/python3.7/site-packages/gensim/tags
set foldmethod=indent
set relativenumber
set number
inoremap kj <Esc>
vnoremap s: sort<CR>
vnoremap < <gv "better indentation
vnoremap > >gv "better indentation
nnoremap ZZ :update<cr>
nnoremap qq :wq<cr>
nnoremap mm :vsplit<cr><C-w><C-w>
nnoremap MM :split<cr><C-w><C-w>
" Ctrl-j/k deletes blank line below/above, and Alt-j/k inserts."
nnoremap <silent><C-j> m`:silent +g/\m^\s*$/d<CR>``:noh<CR>
nnoremap <silent><C-k> m`:silent -g/\m^\s*$/d<CR>``:noh<CR>
nnoremap <silent><A-j> :set paste<CR>m`o<Esc>``:set nopaste<CR>
nnoremap <silent><A-k> :set paste<CR>m`O<Esc>``:set nopaste<CR>
nnoremap <Enter> i<Enter><Esc>
nnoremap <S-Enter> o<Esc>
nnoremap <S-tab> i<tab><Esc>l
nnoremap <C-x> ^i#<Esc>
nnoremap <C-d> yy^i#<Esc>p
nnoremap <S-s> diwea,<Esc>p4bex

You have a mapping for <enter> which overrides the normal enter behavior:
nnoremap <Enter> i<Enter><Esc>
When you hit enter, you will go to insert mode in the quicklist, which isn't allowed.
HTH

Related

vim with python: [missing-function-docstring] Missing function or method docstring

I have vim 9.0 with Python support: I have auto complete and Syntax checking for Python installed. Here is my ~/.vimrc file contents:
set nocompatible " required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
" add all your plugins here (note older versions of Vundle
" used Bundle instead of Plugin)
" ...
Plugin 'tmhedberg/SimpylFold'
Plugin 'vim-scripts/indentpython.vim'
Plugin 'vim-syntastic/syntastic'
Plugin 'nvie/vim-flake8'
Plugin 'jnurmine/Zenburn'
Plugin 'altercation/vim-colors-solarized'
Plugin 'scrooloose/nerdtree'
Plugin 'jistr/vim-nerdtree-tabs'
Plugin 'kien/ctrlp.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}
Bundle 'Valloric/YouCompleteMe'
set clipboard=unnamed
set nu
let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree
"if has('gui_running')
" set background=dark
" colorscheme solarized
"else
" colorscheme zenburn
"endif
"so ~/.vim/bundle/vim-colors-solarized/autoload/togglebg.vim
let python_highlight_all=1
syntax on
let g:ycm_autoclose_preview_window_after_completion=1
map <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>
set splitbelow
set splitright
"split navigations
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" Enable folding
set foldmethod=indent
set foldlevel=99
" Enable folding with the spacebar
nnoremap <space> za
"au BufNewFile,BufRead *.py
" \ setlocal tabstop=4 set softtabstop=4 set shiftwidth=4 set textwidth=79 set expandtab set autoindent set fileformat=unix
au FileType *.js, *.html, *.css
\ setlocal tabstop=2 set softtabstop=2 set shiftwidth=2
"au BufNewFile,BufRead *.js,*.html,*.css,*.vue
"\ set tabstop=2 |
"\ set softtabstop=2 |
"\ set shiftwidth=2
"Flagging Unnecessary Whitespace
highlight BadWhitespace ctermbg=red guibg=darkred
au FileType *.py, *.pyw, *.c, *.h match BadWhitespace /\s\+$/
"au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
set encoding=utf-8
"All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
To test the Python support, I created a simple script as the Figure below shows. It has weird warning in two of its lines: [missing-function-docstring] Missing function or method docstring.
How can I suppress such kind of error/warning?
Nothing to worry about. It's a normal behaviour of the YCM Plugin:
From YCM Documentation:
The GetDoc subcommand:
Displays the preview window populated with quick
info about the identifier under the cursor.
Depending on the file type, this includes things like:
The type or declaration of identifier,
Doxygen/javadoc comments,
Python docstrings,
etc.
Thus, when trying to perform its GetDoc functionality in order to display information about the function under the cursor, YCM simply tells you that the function testing() does not have a documentation associated with it.

unix vim Error detected while processing BufRead Auto commands

I am a new vim user following this guide to make vim indent python code automatically and flag unnecssary whitespace: https://realpython.com/blog/python/vim-and-python-a-match-made-in-heaven/#vim-extensions
The issue I have is receiving this error when I start up vim on a .py file: Error detected while processing BufRead Auto commands for "*.py":
E28: No such highlight group name: BadWhitespace
This error I comment out the following lines:
" Flag unnecessary whitespace
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/ <- this line
" UTF8 Support
set encoding=utf-8
" Proper PEP8 Identation
au BufNewFile,BufRead *.py
\ set tabstop=4
" \ set softtabstop=4 <-- this line
\ set shiftwidth=4
\ set textwidth=79
\ set expandtab
\ set autoindent
\ set fileformat=unix
How can I fix this error? This is my complete .vimrc file:
set nocompatible " required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=/home/frank/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
" add all your plugins here (note older versions of Vundle
" used Bundle instead of Plugin)
Plugin 'tmhedberg/SimpylFold'
Plugin 'vim-scripts/indentpython.vim'
Bundle 'Valloric/YouCompleteMe'
Plugin 'vim-syntastic/syntastic'
Plugin 'nvie/vim-flake8'
Plugin 'jnurmine/Zenburn'
Plugin 'altercation/vim-colors-solarized'
Plugin 'scrooloose/nerdtree'
Plugin 'jistr/vim-nerdtree-tabs'
Plugin 'kien/ctrlp.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}
" ...
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" Split navigations
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" Enable folding
set foldmethod=indent
set foldlevel=99
" Enable folding with the spacebar
nnoremap <space> za
" See docstrings for folded code
let g:SimpylFold_docstring_preview=1
" Flag unnecessary whitespace
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/ <-this line
" UTF8 Support
set encoding=utf-8
" Proper PEP8 Identation <-this line
au BufNewFile,BufRead *.py
\ set tabstop=4
" \ set softtabstop=4
\ set shiftwidth=4
\ set textwidth=79
\ set expandtab
\ set autoindent
\ set fileformat=unix
" For Full stack development 'au' command
"au BufNewFile,BufRead *.js, *.html, *.css
" \ set tabstop=2
" \ set softtabstop=2
" \ set shiftwidth=2
" YouCompleteMe plugin customization
let g:ycm_autoclose_preview_window_after_completion=1
map <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>
"python with virtualenv support
py << EOF
import os
import sys
if 'VIRTUAL_ENV' in os.environ:
project_base_dir = os.environ['VIRTUAL_ENV']
activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
EOF
" Makes python code pretty
let python_highlight_all=1
syntax on
" Adds a bit of logic to define which color scheme to use based upon VIM mode
if has('gui_running')
set background=dark
colorscheme solarized
else
colorscheme zenburn
endif
" Press F5 to toggle between dark and light theme
call togglebg#map("<F5>")
" Hybrid line numbers
:set number relativenumber
:augroup numbertoggle
: autocmd!
: autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
: autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
:augroup END
set pastetoggle=<F10>
There is a simpler solution. You see I had ran into same problem and after this little trick there was no error message and everything is working as it should.
Trick is, BufNewFile,BufRead should be seperated by a space.
So the line should look like
au BufNewFile, BufRead *.py
and not au BufNewFile,BufRead *.py
best regards
The command:
match BadWhitespace /\s\+$/
will highlight trailing white spaces provided that BadWhitespace highlighting group is defined. To check that it is defined do :highlight BadWhitespace. If it is not defined you can either use a default highlighting group, for example:
match Cursor /\s\+$/
or define a BadWhitespace highlighting group. A possible color combination is:
:highlight BadWhitespace ctermfg=16 ctermbg=253 guifg=#000000 guibg=#F8F8F0
Add this line of code before the autocmd that uses BadWhitespace.
The problem is the multiple sets. The first set from this line:
\ set tabstop=4
is the command, and all the following sets are treated as arguments.
It should look like this:
au BufNewFile,BufRead *.py
\ set tabstop=4
\ softtabstop=4
\ shiftwidth=4
\ textwidth=79
\ expandtab
\ autoindent
\ fileformat=unix
Alternatively from here:
" Use the below highlight group when displaying bad whitespace is desired.
highlight BadWhitespace ctermbg=red guibg=red
" Display tabs at the beginning of a line in Python mode as bad.
au BufRead,BufNewFile *.py,*.pyw match BadWhitespace /^\t\+/
" Make trailing whitespace be flagged as bad.
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/

VIM: EOF error when python code requires input

I did setup Vim on my OS X machine, but when I try to execute a code
x=input("which one you like? ")
print(x)
I get an error:
I should mention that there was similar thread, but no acceptable solution was suggested except for not writing any interactive programs..
I will post my .vimrc file content, maybe it can help:
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
"git interface
Plugin 'tpope/vim-fugitive'
"filesystem
Plugin 'scrooloose/nerdtree'
Plugin 'jistr/vim-nerdtree-tabs'
Plugin 'kien/ctrlp.vim'
"html
Plugin 'isnowfy/python-vim-instant-markdown'
Plugin 'jtratner/vim-flavored-markdown'
Plugin 'suan/vim-instant-markdown'
Plugin 'nelstrom/vim-markdown-preview'
"python sytax checker
Plugin 'nvie/vim-flake8'
Plugin 'vim-scripts/Pydiction'
Plugin 'vim-scripts/indentpython.vim'
Plugin 'scrooloose/syntastic'
"auto-completion stuff
"Plugin 'klen/python-mode'
Plugin 'Valloric/YouCompleteMe'
Plugin 'klen/rope-vim'
"Plugin 'davidhalter/jedi-vim'
Plugin 'ervandew/supertab'
""code folding
Plugin 'tmhedberg/SimpylFold'
"Colors!!!
Plugin 'altercation/vim-colors-solarized'
Plugin 'jnurmine/Zenburn'
call vundle#end()
filetype plugin indent on " enables filetype detection
let g:SimpylFold_docstring_preview = 1
"autocomplete
let g:ycm_autoclose_preview_window_after_completion=1
"custom keys
let mapleader=" "
map <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>
"
call togglebg#map("<F5>")
"colorscheme zenburn
"set guifont=Monaco:h14
let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree
"I don't like swap files
set noswapfile
"turn on numbering
set nu
"python with virtualenv support
py << EOF
import os.path
import sys
import vim
if 'VIRTUA_ENV' in os.environ:
project_base_dir = os.environ['VIRTUAL_ENV']
sys.path.insert(0, project_base_dir)
activate_this = os.path.join(project_base_dir,'bin/activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
EOF
"it would be nice to set tag files by the active virtualenv here
":set tags=~/mytags "tags for ctags and taglist
"omnicomplete
autocmd FileType python set omnifunc=pythoncomplete#Complete
"------------Start Python PEP 8 stuff----------------
" Number of spaces that a pre-existing tab is equal to.
au BufRead,BufNewFile *py,*pyw,*.c,*.h set tabstop=4
"spaces for indents
au BufRead,BufNewFile *.py,*pyw set shiftwidth=4
au BufRead,BufNewFile *.py,*.pyw set expandtab
au BufRead,BufNewFile *.py set softtabstop=4
" Use the below highlight group when displaying bad whitespace is desired.
highlight BadWhitespace ctermbg=red guibg=red
" Display tabs at the beginning of a line in Python mode as bad.
au BufRead,BufNewFile *.py,*.pyw match BadWhitespace /^\t\+/
" Make trailing whitespace be flagged as bad.
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
" Wrap text after a certain number of characters
au BufRead,BufNewFile *.py,*.pyw, set textwidth=100
" Use UNIX (\n) line endings.
au BufNewFile *.py,*.pyw,*.c,*.h set fileformat=unix
" Set the default file encoding to UTF-8:
set encoding=utf-8
" For full syntax highlighting:
let python_highlight_all=1
syntax on
" Keep indentation level from previous line:
autocmd FileType python set autoindent
" make backspaces more powerfull
set backspace=indent,eol,start
"Folding based on indentation:
autocmd FileType python set foldmethod=indent
"use space to open folds
nnoremap <space> za
"----------Stop python PEP 8 stuff--------------
Pauliuss-MacBook-Pro:~ Paulius$ less .vimrc
" Use UNIX (\n) line endings.
au BufNewFile *.py,*.pyw,*.c,*.h set fileformat=unix
" Set the default file encoding to UTF-8:
set encoding=utf-8
" For full syntax highlighting:
let python_highlight_all=1
syntax on
" Keep indentation level from previous line:
autocmd FileType python set autoindent
" make backspaces more powerfull
set backspace=indent,eol,start
"Folding based on indentation:
autocmd FileType python set foldmethod=indent
"use space to open folds
nnoremap <space> za
If you do :w !python, the standard input is a temporary file or pipe with your code, which python naturally reads to the end in order to execute the script, hence it's EOF when it gets to input(), and input is not from a terminal.
To solve this problem, insert a line
#!/usr/bin/env python
as the first line of your code file, save it, do :!chmod +x % once and then execute it with :!%.

Vim won't properly indent Python code when using the = command

When I use the = command to indent an entire Python file or a section it won't properly indent it. Here's my vimrc:
set nocompatible
syntax on
set ruler
set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab
set smarttab
set hlsearch
set incsearch
set ignorecase
set autoindent
" turn on line numbers:
set number
" Toggle line numbers and fold column for easy copying:
nnoremap <F2> :set nonumber!<CR>:set foldcolumn=0<CR>
nnoremap <F4> :set nospell!<CR>
nnoremap <F3> :set invpaste paste?<Enter>
imap <F3> <C-O><F3>
set pastetoggle=<F3>
filetype on
filetype plugin indent on
filetype plugin on
" Execute file being edited with <Shift> + e:
map <buffer> <S-e> :w<CR>:!/usr/bin/env python % <CR>
let g:solarized_termcolors=256
set background=dark
colorscheme solarized
"set spell spelllang=en_us
set backspace=indent,eol,start
autocmd FileType python set complete+=k~/.vim/syntax/python.vim isk+=.,(
autocmd VimEnter * NERDTree
Also when I loop through my python files using w or b for instance, or when deleting it won't delete properly. For instance it will not stop on the . or ( when deleting a work before them and will even delete these.
You should get rid of filetype on and filetype plugin on: filetype plugin indent on is the only line you need.
edit
The problem with . and ( is almost certainly caused by iskeyword. I vaguely remember someone having the same problem because he/she found out in some misinformed blog post that he/she needed dictionary-based completion. Because the entries in his/her dictionary file where in the form .method(, he/she needed the . to be considered a keyword character.
Try this command when editing a Python file:
:verbose set iskeyword?
It should return a comma separated list of values that includes . and ( and the place where it is set. It's most likely to be a third party python ftplugin because the default ftplugin doesn't touch iskeyword.
This line is what is causing the ./( problem:
autocmd FileType python set complete+=k~/.vim/syntax/python.vim isk+=.,(
You absolutely don't need that completion mechanism because Vim's default omnicompletion is powerful enough.
Because of how that completion mechanism is implemented and how your dictionary file may be written, . and ( must be considered by Vim as keyword characters.
Your custom/ syntax file may not even be formed like that so this setting may not even work.
isk is the short form of iskeyword, the option that defines what is a keyword character.
You seem to have copied settings from someone else without understanding what they did. The simple fact that the answer to your question was in your own ~/.vimrc should suffice to show you how wrong this idea is.
you can paste normally usign the :set paste, I have a very handy macro for that:
set pastetoggle=<F10>
You can set it to be any other key, just add it to your .vimrc file

How do I set up Vim autoindentation properly for editing Python files?

I've trouble setting up Vim (7.1.xxx) for editing Python files (*.py).
Indenting seems to be broken (optimal 4 spaces).
I've followed some tutorials I found via Google. Still no effect :/
Please help.
I use this on my macbook:
" configure expanding of tabs for various file types
au BufRead,BufNewFile *.py set expandtab
au BufRead,BufNewFile *.c set expandtab
au BufRead,BufNewFile *.h set expandtab
au BufRead,BufNewFile Makefile* set noexpandtab
" --------------------------------------------------------------------------------
" configure editor with tabs and nice stuff...
" --------------------------------------------------------------------------------
set expandtab " enter spaces when tab is pressed
set textwidth=120 " break lines when line length increases
set tabstop=4 " use 4 spaces to represent tab
set softtabstop=4
set shiftwidth=4 " number of spaces to use for auto indent
set autoindent " copy indent from current line when starting a new line
" make backspaces more powerfull
set backspace=indent,eol,start
set ruler " show line and column number
syntax on " syntax highlighting
set showcmd " show (partial) command in status line
(edited to only show stuff related to indent / tabs)
I use:
$ cat ~/.vimrc
syntax on
set showmatch
set ts=4
set sts=4
set sw=4
set autoindent
set smartindent
set smarttab
set expandtab
set number
But but I'm going to try Daren's entries
A simpler option: just uncomment the following part of the configuration (which is originally commented out) in the /etc/vim/vimrc file:
if has("autocmd")
filetype plugin indent on
endif
I use the vimrc in the python repo among other things:
http://svn.python.org/projects/python/trunk/Misc/Vim/vimrc
I also add
set softtabstop=4
I have my old config here that I'm updating
Ensure you are editing the correct configuration file for VIM. Especially if you are using windows, where the file could be named _vimrc instead of .vimrc as on other platforms.
In vim type
:help vimrc
and check your path to the _vimrc/.vimrc file with
:echo $HOME
:echo $VIM
Make sure you are only using one file. If you want to split your configuration into smaller chunks you can source other files from inside your _vimrc file.
:help source
Combining the solutions proposed by Daren and Thanos we have a good .vimrc file.
-----
" configure expanding of tabs for various file types
au BufRead,BufNewFile *.py set expandtab
au BufRead,BufNewFile *.c set noexpandtab
au BufRead,BufNewFile *.h set noexpandtab
au BufRead,BufNewFile Makefile* set noexpandtab
" --------------------------------------------------------------------------------
" configure editor with tabs and nice stuff...
" --------------------------------------------------------------------------------
set expandtab " enter spaces when tab is pressed
set textwidth=120 " break lines when line length increases
set tabstop=4 " use 4 spaces to represent tab
set softtabstop=4
set shiftwidth=4 " number of spaces to use for auto indent
set autoindent " copy indent from current line when starting a new line
set smartindent
set smarttab
set expandtab
set number
" make backspaces more powerfull
set backspace=indent,eol,start
set ruler " show line and column number
syntax on " syntax highlighting
set showcmd " show (partial) command in status line
for more advanced python editing consider installing the simplefold vim plugin. it allows you do advanced code folding using regular expressions. i use it to fold my class and method definitions for faster editing.

Categories