我怎样才能找出导致vim解释python文件的原因?

时间:2018-03-20 20:35:10

标签: python vim

多年后,我终于清理了我的.vimrc并深入研究了设置的确如此真实。我花了很多时间来修剪和阅读帮助文件。

现在我已经达到了一个非常小的.vimrc,我很满意 - 我相信我理解其中的每一件事(很多评论)。我将把我的.vimrc包含在这个问题的底部。

我的问题是,我正在使用Python(第一次),并且某种程度上vim有一堆设置(我不喜欢) - 看似内置。我怎么能:

  1. 找出导致这些设置的原因并将其关闭
  2. 让它为python文件提供一个漂亮的空白平板,以便我可以选择我想要的设置?
  3. 注意:我删除了我的.viminfo文件(在备份之后)以清除所有内容。

    当我打开python文件并输入old_handler = trap("INT") do puts "doing something custom in response to INT" if old_handler.respond_to?(:call) puts "calling old handler for INT" old_handler.call exit # in case old_handler is a bad citizen else case old_handler when "DEFAULT" puts "done with custom handlers, exiting in response to INT" exit when "IGNORE" puts "done with custom handlers for INT, system default ignores it" else # in the case of EXIT it is nil. Not sure of other possibilities puts "old_handler is : #{old_handler.class}" end end end 时,我得到的是:

    :set

    请注意:set --- Options --- autoindent helplang=en modified scroll=38 smartindent textwidth=76 comments=b:#,fb:- hlsearch number scrolloff=5 softtabstop=4 ttyfast expandtab incsearch relativenumber shiftwidth=4 suffixesadd=.py ttymouse=sgr filetype=python keywordprg=pydoc ruler showmatch syntax=python wildignore=*.pyc backspace=indent,eol,start cinkeys=0{,0},0),:,!^F,o,O,e commentstring=# %s fileencoding=utf-8 fileencodings=ucs-bom,utf-8,default,latin1 include=^\s*\(from\|import\) includeexpr=substitute(v:fname,'\.','/','g') indentexpr=GetPythonIndent(v:lnum) indentkeys=0{,0},:,!^F,o,O,e,<:>,=elif,=except omnifunc=pythoncomplete#Complete printoptions=paper:letter runtimepath=~/.vim,~/.vim/bundle/vundle,~/.vim/bundle/tabular,~/.vim/bundle/vim- es6,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/ share/vim/vim74,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after,~/.vim/bundle/Vundle.vim/,~/.vim/bundle/vundle/after,~/.vim/bundle/tabular/after,~/.vim/bundle/vim-es6/after shiftwidth=4,例如。

    如果我打开空白文件,这是我得到的softtabstop=4

    :set

    这就是我期望得到的(例如,注意:set --- Options --- autoindent number shiftwidth=2 ttyfast expandtab relativenumber showmatch ttymouse=sgr helplang=en ruler smartindent hlsearch scroll=38 tabstop=2 incsearch scrolloff=5 textwidth=76 backspace=indent,eol,start fileencodings=ucs-bom,utf-8,default,latin1 printoptions=paper:letter runtimepath=~/.vim,~/.vim/bundle/vundle,~/.vim/bundle/tabular,~/.vim/bundle/vim-es6,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim74,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after,~/.vim/bundle/Vundle.vim/,~/.vim/bundle/vundle/after,~/.vim/bundle/tabular/after,~/.vim/bundle/vim-es6/after suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc 。这是我的(相当简短).vimrc:

    shiftwidth=2

    那么...... python文件的自定义设置来自哪里?

    顺便说一句,我检查了我的.vimrc目录,并且python没有$ cat .vimrc " Turn on line numbering set number " Turn on relative numbers set relativenumber " Show the leader key set showcmd " Set the <leader> to space. let mapleader = " " " Always use a numberwidth minimum of 6 set numberwidth=6 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" """ Tabbing & Indenting """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Set the width of a single 'shift'. This is what occurs when using the > " or < keys. set shiftwidth=2 " Set the size of a tab. set tabstop=2 " Expand tabs to spaces. set expandtab " Copy the current line's indent to the next line when starting a new line. set autoindent " Use 'smart' indenting for C-style languages. When this is on, autoindent " should also be on. set smartindent " Lets us use <leader>gg to re-indent the file and return to our current " location. map <leader>gg gg=Gu<C-r> """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" """ Informatics """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Show an indicator of where you are in the file. set ruler """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" """ Navigation """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Make it more convenient to jump up or down a page. map <leader>j <PageDown> map <leader>k <PageUp> " Make it more convenient to go to the beginning or end of the file. map <leader>jj :$<Enter> map <leader>kk :1<Enter> """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" """ Aesthetics """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Syntax highlighting syntax on " By default, use the "distinguished" color scheme. colorscheme distinguished set scrolloff=5 """""""""""""""""""""""""""" """ Specific highlight rules highlight Todo none """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" """ Search """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Highlight matches as-you-search set showmatch " Turn on incremental search set incsearch """"""""""""""""" """ Highlighting " Show all search results highlighted set hlsearch " Clears search highlighting by just hitting a return. " The <BS> clears the command line. " (From Zdenek Sekera on the vim list.) " I added the final <cr> to restore the standard behaviour of " <cr> to go to the next line nnoremap <CR> :nohlsearch<CR>/<BS><CR> """ Highlighting """"""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" """ Line Structure """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Set the line length for breaking text set textwidth=76 " Set this expression to control the way in which lines break. " set formatexpr <expression> """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" """ File-level adjustments """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Turn off swap files. noswapfile """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" """ Plugins & Tools """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Turn on plugins filetype plugin on " Stuff for the Tabular.vim plugin map ,t :Tab /=<CR> "command -nargs=1 T1 Tabular /^[^<args>]*\zs[<args>]/l1r0 """ " Vundle config set nocompatible " be iMproved filetype off " required! set rtp+=~/.vim/bundle/Vundle.vim/ call vundle#begin() " let Vundle manage Vundle " required! Plugin 'gmarik/vundle' " Tabular Plugin 'godlygeek/tabular' " JavaScript ES6 plugin Plugin 'isRuslan/vim-es6' call vundle#end() filetype plugin indent on " required! " The JSONTidy command to format JSON. command JSONTidy %!python -m json.tool indentsyntax个文件。

    为什么color 4用于python文件?我的shiftwidth去了哪里(例如)?

2 个答案:

答案 0 :(得分:2)

  1. :verbose set optionname?会告诉您optionname的当前值及其设置位置。

  2. 默认的Python设置在:

    中定义
    $VIMRUNTIME/ftplugin/python.vim
    

    请注意,它们遵循Python的“标准”,因此更改任何内容可能会或可能不会导致问题(例如,使用短线)。

  3. 要覆盖这些默认设置,请在以下位置创建自己的Python ftplugin:

    ~/.vim/after/ftplugin/python.vim
    

    并添加所需的选项:

    setlocal shiftwidth=2
    setlocal tabstop=2
    

    顾名思义,该脚本来自内置之后的,这使其成为覆盖内置文件类型特定设置并添加自己的设置的正确位置。

答案 1 :(得分:0)

Vim附带了几个文件类型的插件。我认为引起您问题的是:https://github.com/vim/vim/blob/master/runtime/ftplugin/python.vim

您可以尝试删除该文件。或者只找到您不喜欢的选项,:let g:OPTION_NAME = 0。这里还有一些关于覆盖ftplugins的讨论:https://vi.stackexchange.com/questions/6658/how-to-override-a-ftplugin#6659