2013-05-19 41 views
2

_vimrc文件中的代码段是如何彼此交互的?
我目前的文件如下所示,但我想知道如果filetype plugin indent on这行在这个文件的开头或结尾是否很重要?
在文件中重复两次像filetype plugin indent on这样的行是否重要?
Pathogen设置应该接近开始吗?我的_vimrc中的代码段的顺序是否重要?

"------------------------------------------------------------ 
    " Must have options {{{1 


    "this will make the window maximized on startup 
    au GUIEnter * simalt ~x 

    " Attempt to determine the type of a file based on its name and possibly its 
    " contents. Use this to allow intelligent auto-indenting for each filetype, 
    " and for plugins that are filetype specific. 
    filetype indent plugin on 
    set omnifunc=syntaxcomplete#Complete 
    " Enable syntax highlighting 
    syntax on 

    "set highlight search always on 
    :set hlsearch 

    "------------------------------------------------------------ 
    " Usability options {{{1 

    " Show partial commands in the last line of the screen 
    set showcmd 
    " Use case insensitive search, except when using capital letters 
    set ignorecase 
    set smartcase 
    " Allow backspacing over autoindent, line breaks and start of insert action 
    set backspace=indent,eol,start 
    " When opening a new line and no filetype-specific indenting is enabled, keep 
    " the same indent as the line you're currently on. Useful for READMEs, etc. 
    set autoindent 
    " Stop certain movements from always going to the first character of a line. 
    " While this behaviour deviates from that of Vi, it does what most users 
    " coming from other editors would expect. 
    set nostartofline 
    " Display the cursor position on the last line of the screen or in the status 
    " line of a window 
    set ruler 
    " Always display the status line, even if only one window is displayed 
    set laststatus=2 
    " Instead of failing a command because of unsaved changes, instead raise a 
    " dialogue asking if you wish to save changed files. 
    set confirm 
    " Use visual bell instead of beeping when doing something wrong 
    set visualbell 
    " And reset the terminal code for the visual bell. If visualbell is set, and 
    " this line is also included, vim will neither flash nor beep. If visualbell 
    " is unset, this does nothing. 
    set t_vb= 
    " Enable use of the mouse for all modes 
    set mouse=a 
    " Set the command window height to 2 lines, to avoid many cases of having to 
    " "press <Enter> to continue" 
    set cmdheight=2 
    " Display line numbers on the left 
    set number 
    " Quickly time out on keycodes, but never time out on mappings 
    set notimeout ttimeout ttimeoutlen=200 
    " Use <F11> to toggle between 'paste' and 'nopaste' 
    set pastetoggle=<F11> 

    "------------------------------------------------------------ 
    " Indentation options {{{1 
    " 
    " Indentation settings according to personal preference. 

    " Indentation settings for using 2 spaces instead of tabs. 
    " Do not change 'tabstop' from its default value of 8 with this setup. 
    "set shiftwidth=2 
    "set softtabstop=2 
    "set expandtab 

    " Indentation settings for using hard tabs for indent. Display tabs as 
    " two characters wide. 
    set shiftwidth=2 
    set tabstop=2 



    "------------------------------------------------------------ 
    " Look and Feel {{{1 
    " 
    " Use CTRL-S for saving, also in Insert mode 
    :nnoremap <C-S>  :<C-U>update<CR> 
    :vnoremap <C-S>  :<C-U>update<CR>gv 
    :cnoremap <C-S>  <C-C>:update<CR> 
    :inoremap <C-S>  <C-O>:update<CR> 

    "color scheme setting 
    " Set nice colors 
    " background for normal text is light grey 
    " Text below the last line is darker grey 
    " Cursor is green, Cyan when ":lmap" mappings are active 
    " Constants are not underlined but have a slightly lighter background 
    set guifont=Consolas:h16:cANSI 
    colorscheme pyte 
    "highlight Normal guibg=grey90 
    "highlight Cursor guibg=Green guifg=NONE 
    "highlight lCursor guibg=Cyan guifg=NONE 
    "highlight NonText guibg=grey80 
    "highlight Constant gui=NONE guibg=grey95 
    "highlight Special gui=NONE guibg=grey95 

    "a quick way to locate python files 
    nnoremap <Leader>p :pyf P:\Computer Applications\Python\ 

    "quick quit command 
    noremap <Leader>e :quit<CR> "quits the current window 


    "------------------------------------------------------------ 
    " NERTtree settings {{{1 
    " 
    "get NERDTree command quick 
    nnoremap <Leader>nd :NERDTree M:\ 
    map <F2> :NERDTreeToggle<CR> 
    let NERDTreeQuitOnOpen = 1 

    " Rebind <Leader> key...not sure about this one 
    "let mapleader = "," 

    map <Leader>n <esc>:tabprevious<CR> 
    map <Leader>m <esc>:tabnext<CR> 

    "------------------------------------------------------------ 
    " dbext settings {{{1 
    " 
    "let g:sql_type_default = 'SQLSVR' 

    " Since I repeatedly need to edit stored procedures, the CREATE PROCEDURE 
    " statement is preceeded by an IF ... END IF block which will drop 
    " the procedure or it uses the CREATE OR REPLACE syntax. 
    " This function will visually select the IF block to the END; statement 
    " of the stored procedure and execute it. Or check for the 
    " CREATE OR REPLACE and stop there and look to the end. 
    function! SQLExecuteIfCreateReplace() 
     let l:old_sel = &sel 
     let &sel = 'inclusive' 
     let saveWrapScan=&wrapscan 
     let [email protected]/ 
     let l:reg_z = @z 
     let &wrapscan=0 
     let @z = '' 
     let found = 0 
     let startLine = 0 
     let endLine = 0 
     let curLine = line(".") 
     let curCol = virtcol(".") 

     " Must default the command terminator 
     let l:dbext_cmd_terminator = ";" 

     try 
       " Search backwards and do NOT wrap 
       " Find the line beginning with an IF clause 
       "  IF EXISTS(SELECT 1 ... 
       " or find an or replace clause 
       "  CREATE OR REPLACE PROCEDURE ... 
       " And execute it until we find an 
       "  END 
       " at the beginning of a line. 
      let startLine = search('\c\(^\<if\>\|^\<alter\s\+procedure\>\|\<or\s\+replace\>\)', 'bcnW') 

       if startLine > 0 
        " Search forward and visually select all lines 
        " until we find an END; clause 
        let endLine = search('^END'.l:dbext_cmd_terminator.'\s*$', 'cnW') 
        exec startLine.','.endLine.'DBExecRangeSQL' 
       endif 
      finally 
       call cursor(curLine, curCol) 
       noh 
       let l:query = @z 
       let @z = l:reg_z 
       let @/=saveSearch 
       let &wrapscan=saveWrapScan 
       let &sel = l:old_sel 
      endtry 
     endfunction 


    "------------------------------------------------------------ 
    " pathogen settings {{{1 

    "pathogen customization 
    "set nocp 

    " Use pathogen to easily modify the runtime path to include all plugins under 
    " the ~/.vim/bundle directory 
    filetype off     " force reloading *after* pathogen loaded 
    call pathogen#infect() 
    call pathogen#helptags() 
    call pathogen#runtime_append_all_bundles() 
    syntax on 

    filetype plugin indent on  " enable detection, plugins and indenting in one step 
+0

是否有你添加了':set ...'选项而不是'set ...'的原因?无论如何,如果你想'设置nocompatible'建议首先,因为设置是按顺序应用的。 – demure

回答

2

tl; dr:有些是,有些不是;使用从简单到复杂的逻辑结构。

病原希望其设置出现在顶部,因为它修改其他脚本加载的方式(通过明确:runtime,或致电自动加载功能的副作用)。

:set的顺序通常无关紧要(除非您有冲突的设置),并且您定义的任何映射或autocmds只在启动后激活,因此您可以将它们放在任何位置。一般来说,我会推荐一个逻辑结构,从病原体,设置,插件配置等基本的东西开始,然后是自定义映射,以及更多涉及autocmds的修改。

此外,我会避免将文件类型特定的东西放入~/.vimrc;而是将其放入相应的~/.vim/after/ftplugin/<filetype>.vim脚本中并使用filetype plugin on

+0

+1 Ingo。你建议将'_vimrc'中的dbext脚本移出,并简单替换为'SQLdbext plugin on'这样的一行,然后将脚本放在一个'SQLdbext.vim'文件中,并将该文件保存在'〜/ .vim/after/ .vim' ....什么是“之后”? – whytheq

+0

after目录保证东西在Vim附带的原始文件类型插件之后运行,因此您可以修改这些设置。 (哦,我在那里有一个错字。) –

+0

确定 - 最初我创建的文件'dbextVimScript.vim'在'〜/的.vim/dbextFiles /',然后加入下列行来_vimrc行:'所以M:\ dbextFiles \ dbextVimScript.vim'。 vim似乎与设置好的工作很好。但我又改成你的建议,我认为这是比较标准(添加'文件类型插件on'并将其保存在'〜/ vim的/后/文件类型插件/ sql.vim'。感谢您的时间和建议。 – whytheq

4

订单确实重要。

例如你有两条线:

选项:

set nu 
set nonu 

后者将覆盖之前的设置。

函数,如果你在你的文件的末尾声明一个函数,但在第一行调用它。当你加载你的vimrc在第一时间,你会得到错误Unknown function: function name

此外,如果你手动设置的配色方案之前,一些hi group(如果使用一个)加载,配色方案是要覆盖你的设置了。

如果您在加载之前调用某个插件中定义的某个命令/函数,您也会收到错误消息。

因此,如果您在vimrc中有多个命令/设置多次,但最后一个会生效,那就没关系。