Vim will not specify Python code correctly when using the command =
When I use the = command to indent an entire Python file or section, it won't indent correctly. Here is 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 view python files with w or b for example, or when deleted does not delete properly. For example, it won't stop. or (when deleting the work in front of them and even deleting them.
source to share
You should get rid of filetype on
and filetype plugin on
: filetype plugin indent on
is the only line you need.
change
The problem with .
and is (
almost certainly caused by iskeyword
. I vaguely remember someone else had the same problem because they found out in some misguided blog that he or she needed a dictionary based one. Since the entries in his dictionary file where in the form .method(
, he / she needed .
it to be considered a keyword character.
Try this command while editing your Python file:
:verbose set iskeyword?
It should return a comma-separated list of values that includes both .
and (
and where it is installed. This will most likely be a third party python ftplugin because ftplugin is not touched by default iskeyword
.
This line is causing the problem .
/ (
:
autocmd FileType python set complete+=k~/.vim/syntax/python.vim isk+=.,(
-
You absolutely don't need this completion mechanism because Vim's default omnicompletion is powerful enough.
-
Because of how this completion mechanism is implemented and how your dictionary file can be written,
.
both(
should be treated like keywords by Vim. -
The custom / syntax file may not even be rendered so that this option doesn't even work.
-
isk
is a short formiskeyword
, an option that defines what the keyword character is.
You seem to have copied the settings from someone else without understanding what they did. The simple fact that the answer to your question was in your own ~/.vimrc
should be enough to show you how wrong this idea is.
source to share