Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Svn 调用system()函数,Vim脚本_Svn_Vim - Fatal编程技术网

Svn 调用system()函数,Vim脚本

Svn 调用system()函数,Vim脚本,svn,vim,Svn,Vim,当我遇到一个问题时,我正试图在Vim 7.3中自定义我的状态行 我试图将SVN信息放在状态行中,因此我制作了如下内容: function! DrawStatusLine() let svn = system("svn info") let l:status = " " let l:status = l:status . svn let l:status = l:status . "%t" "tail of the filename let l:

当我遇到一个问题时,我正试图在Vim 7.3中自定义我的状态行

我试图将SVN信息放在状态行中,因此我制作了如下内容:

function! DrawStatusLine()
    let svn = system("svn info")
    let l:status = " "
    let l:status = l:status . svn
    let l:status = l:status . "%t"       "tail of the filename
    let l:status = l:status . "%*"
    let l:status = l:status . "[%{strlen(&fenc)?&fenc:'none'}," "file encoding
    let l:status = l:status . "%{&ff}]" "file format
    let l:status = l:status . "%h"      "help file flag
    let l:status = l:status . "%m"      "modified flag
    let l:status = l:status . "%r"      "read only flag
    let l:status = l:status . "%="      "left/right separator
    let l:status = l:status . "%c,"     "cursor column
    let l:status = l:status . "%l/%L"   "cursor line/total lines
    let l:status = l:status . "\ %P"    "percent through file
    return l:status
endfunction

set statusline=%!DrawStatusLine()
但在调用系统后,光标移动非常缓慢。似乎每次我移动光标时都会调用system实际上,每次窗口中发生某些事情时都会调用system

你知道我为什么会有这种行为吗

下面是我的.vimrc的其余部分,我没有使用任何外来插件,我在Windows XP中使用Cygwin

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
    finish
endif

" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" Management of console or GUI settings.
if has("gui_running")
    " We are in gVim
    " Linux
    if has("gui_gtk2")
        :set guifont=DejaVu\ Sans\ Mono\ 11
    " Windows
    elseif has("gui_win32")
        :set guifont=DejaVu_Sans_Mono:h11:cANSI:
    endif
else
    " We are in a console
    set background=dark
endif

" Manage colors.
if filereadable($VIMRUNTIME . "/colors/wombat256.vim") ||
            \ filereadable($VIM . "/vimfiles/colors/wombat256.vim") ||
            \ filereadable($HOME . "/.vim/colors/wombat256.vim")
    colorscheme wombat256
elseif filereadable($VIMRUNTIME . "/colors/wombat.vim") ||
            \ filereadable($VIM . "/vimfiles/colors/wombat.vim") ||
            \ filereadable($HOME . "/.vim/colors/wombat.vim")
    colorscheme wombat
else
    colorscheme desert
endif

" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
let &guioptions = substitute(&guioptions, "t", "", "g")

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
    set mouse=a
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
    syntax on
    set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

    " Enable file type detection.
    " Use the default filetype settings, so that mail gets 'tw' set to 72,
    " 'cindent' is on in C files, etc.
    " Also load indent files, to automatically do language-dependent indenting.
    filetype plugin indent on

    " Put these in an autocmd group, so that we can delete them easily.
    augroup vimrcEx
        autocmd!

        " For all text files set 'textwidth' to 78 characters.
        autocmd FileType text setlocal textwidth=78

        " When editing a file, always jump to the last known cursor position.
        " Don't do it when the position is invalid or when inside an event handler
        " (happens when dropping a file on gvim).
        " Also don't do it when the mark is in the first line, that is the default
        " position when opening a file.
        autocmd BufReadPost *
                    \ if line("'\"") > 1 && line("'\"") <= line("$") |
                    \   exe "normal! g`\"" |
                    \ endif

    augroup END

else

    set autoindent " always set autoindenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
    command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
                \ | wincmd p | diffthis
endif

" Update the path with the dir where we opened Vim
set path=.,$PWD/**
" Now that we set the path to be recursive, disable
" the option that looking for completion in included files.
" Indeed, it can slow the process hard. We use tags instead.
set complete-=i

" Allow editing everywhere
set virtualedit=all

" No bells
set errorbells
set novisualbell
set vb t_vb=

" Show status bar
set laststatus=2
let loaded_matchparen = 1

" Draw the status line.
" Status line that rocks.
function! DrawStatusLine()
    let svn = system("svn info")
    let l:status = " "
    let l:status = l:status . "%t"       "tail of the filename
    let l:status = l:status . "%*"
    let l:status = l:status . "[%{strlen(&fenc)?&fenc:'none'}," "file encoding
    let l:status = l:status . "%{&ff}]" "file format
    let l:status = l:status . "%h"      "help file flag
    let l:status = l:status . "%m"      "modified flag
    let l:status = l:status . "%r"      "read only flag
    let l:status = l:status . "%="      "left/right separator
    let l:status = l:status . "%c,"     "cursor column
    let l:status = l:status . "%l/%L"   "cursor line/total lines
    let l:status = l:status . "\ %P"    "percent through file
    return l:status
endfunction

set statusline=%!DrawStatusLine()

" Highlight current line
set cursorline

" Add visible lines when start or end of the screen (3 lines)
set scrolloff=3

" Backup
set nobackup

" No preview in ins-completion.
set completeopt=menu

" Commands completion on status line.
set wildmenu

" Don't redraw while executing macros
set lazyredraw

" K = :help
set keywordprg=

" Diff always vertical
set diffopt+=vertical

" Use utf-8
set encoding=utf-8
set fileencoding=utf-8

" Remember buffer changes when jumping around.
set hidden

"""""""""""""""""
" Developpement "
"""""""""""""""""

" Line numbers
set nu

" Tabulation of 4 spaces
set expandtab
set smarttab
set shiftwidth=4
set softtabstop=4
set tabstop=4

" Show when a line exceeds 80 chars
highlight Overlength ctermbg=red ctermfg=white guibg=#592929

" Highlight Tabs and Spaces
" highlight Tab ctermbg=darkgray guibg=darkgray
" au BufWinEnter * let w:m2=matchadd('Tab', '/[^\t]\zs\t\+/', -1)
highlight Space ctermbg=darkblue guibg=darkblue
augroup matches
    autocmd!
    autocmd BufWinEnter * match Overlength /\%81v.*/
    autocmd BufWinEnter * let w:m3=matchadd('Space', '\s\+$\| \+\ze\t', -1)
    " Matches are memory greedy, shut them when the window is left
    " Mybe it is redondant.
    autocmd BufWinLeave * call clearmatches()
augroup END

set list listchars=tab:\ \ ,trail:.


" Redraw status line when saving.
" autocmd BufWritePost * set statusline=%!DrawStatusLine()

" Special indentation for switch / case
" Indentation when in unclosed (.
set cino=l1,(0

" Load Doxygen syntax
let g:load_doxygen_syntax=1

"""""""""""""""""
" Taglist
"""""""""""""""""
let Tlist_Use_Right_Window=1

"""""""""""""""""
" cscope
"""""""""""""""""
if has("cscope") && executable("cscope") && !has("gui_win32")
    set csto=0
    set cst
    set nocsverb
    " add any database in current directory
    if filereadable("cscope.out")
        cs add cscope.out
    endif
    " abbreviations
    cnoreabbrev csf cs find
    set csverb
endif

"""""""""""""
"  Mapping  "
"""""""""""""

" Don't use Ex mode, use Q for formatting
map Q gq

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","

" After repeating command, return where we were.
map . .`[

" Switch tab.
noremap <A-h> gT
noremap <A-l> gt
" For dummy terminals
noremap <Esc>h gT
noremap <Esc>l gt

" Remap the Esc command
inoremap kj <Esc>
inoremap lk <Esc>

" Better for wrapped lines
nnoremap j gj
nnoremap k gk

" omnicompletion : words
inoremap <leader>, <C-x><C-o>

" Turn off highlighting in search.
nmap <leader>/ :nohlsearch<CR>

" edit .vimrc
nmap <silent> <leader>ev :tabnew $HOME/.vimrc<CR>
" source .vimrc
nmap <silent> <leader>sv :so $HOME/.vimrc<CR>

nnoremap <silent><leader>dh :call SVNDiff()<CR>

" Build C symbols.
function! BuildSymbols()
    if has("cscope") && executable("cscope") && !has("gui_win32")
        " kill all connection.
        execute "cs kill -1"
        execute "!ctags -R && cscope -Rb"
        execute "cs add cscope.out"
    else
        execute "!ctags -R"
    endif
endfunction

" Run Vim diff on HEAD copy in SVN.
function! SVNDiff()
    let fn = expand("%:p")
    let newfn = fn .  ".HEAD"
    let catstat = system("svn cat " . fn . " > " . newfn)
    if catstat == 0
        execute 'diffsplit ' . newfn
        execute 'set filetype=c'
    else
        echo "*** ERROR: svn cat failed for ". fn . " (as " . newfn . ")"
    endif
endfunction

" Build symbols with F2.
nnoremap <F2> :call BuildSymbols()<CR>

" Taglist with F3
nnoremap <F3> :TlistToggle<CR>

" Open a explorer on a vertical split of 26.
nnoremap <F4> :26Vexplore<CR>

" When you forgot to open the file as sudo.
cmap w!! %!sudo tee > /dev/null %

这是预期的行为:每次移动光标时,整个状态行都会更新,因此每次执行操作时都会执行svn信息。每秒可能有很多次

这显然是浪费,因为当前文件的svn状态不会每秒更改10次


您应该缓存此信息,并且仅在写入时、每n分钟或沿着该行检索一次。

这是预期的行为:每次移动光标时,整个状态行都会更新,因此每次执行操作时都会执行svn信息。每秒可能有很多次

这显然是浪费,因为当前文件的svn状态不会每秒更改10次

您应该缓存此信息,并仅在写入时、每n分钟或沿着该行检索一次。

始终计算“statusline”值,否则它如何显示光标位置之类的信息?!不要在那里做耗时的事情;即使很长的Vimscript片段也会显著降低Vim的速度,系统是最糟糕的

相反,在状态行中包含一个缓冲区局部变量,例如%{exists'b:svn_info'?b:svn_info:},并使用适当的AutoCMD设置和更新它:

:autocmd BufRead * let b:svn_info = system('svn info')
“statusline”值始终处于评估状态,否则它如何显示光标位置之类的信息?!不要在那里做耗时的事情;即使很长的Vimscript片段也会显著降低Vim的速度,系统是最糟糕的

相反,在状态行中包含一个缓冲区局部变量,例如%{exists'b:svn_info'?b:svn_info:},并使用适当的AutoCMD设置和更新它:

:autocmd BufRead * let b:svn_info = system('svn info')

除了已经存在的答案之外,还有一个补充:有些插件已经像BufEnter一样自己保存缓存,或者只在BufEnter上执行一次。上述两种方法都可以替换SVNDiff函数

VCSCommand将仅提供文件状态“未知”和“新”,或者“状态”既不是“版本”、“存储库”也不是“存储库中是否存在较新版本”。我必须在这里重复,它不会更新状态,直到您切换到另一个缓冲区,然后返回

Aurum更加灵活*,但除非您愿意体验每N秒的输入延迟或切换到mercurial,否则您将被迫使用文件状态和分支**最后一个左边是当前版本信息。Subversion状态始终映射到八个mercurial状态之一。除非您使用+python编译vim,否则它使用缓存方法,缓存失效将使您遭受延迟,但是使用+python,情况就不同了:状态每N秒在一个单独的进程中获得一次,并且不会因为任何延迟而困扰您,除非您在当前使用+python时做了一些导致缓存失效的事情,否则您在失效发生时会遇到延迟,并且不会注意到它认为这是您的操作的一部分造成的无效,但没有延迟,因为它发生在statusline无效时

*从这些文档中,我猜VCSCommand的作者打算让用户自己编写更好的statusline,但我看不到任何有助于他们的东西。也许我只是找错地方了

**这里的分支表示“存储库根URL中不存在的根目录URL的尾部”。根目录是嵌套最少的目录,其.svn子目录和存储库根URL等于包含当前缓冲区的当前目录之一


即使您不愿意使用aurum,也可以随意借用重复执行的命令或缓存实现。

除了现有的答案之外,还有一个补充:有些插件已经像BufEnter一样保存缓存,或者像BufEnter一样只执行一次。上述两种方法都可以替换SVNDiff函数

VCSCommand将仅提供文件状态“未知”和“新”,或者“状态”既不是“版本”、“存储库”也不是“存储库中是否存在较新版本”。我必须在这里重复,它不会更新状态,直到您切换到另一个缓冲区,然后返回

Aurum更加灵活*,但除非您愿意体验每N秒的输入延迟或切换到mercurial,否则您将被迫使用文件状态和分支**最后一个左边是当前版本信息。Subversion状态始终映射到八种mercurial状态之一 一个。除非您使用+python编译vim,否则它使用缓存方法,缓存失效将使您遭受延迟,但是使用+python,情况就不同了:状态每N秒在一个单独的进程中获得一次,并且不会因为任何延迟而困扰您,除非您在当前使用+python时做了一些导致缓存失效的事情,否则您在失效发生时会遇到延迟,并且不会注意到它认为这是您的操作的一部分造成的无效,但没有延迟,因为它发生在statusline无效时

*从这些文档中,我猜VCSCommand的作者打算让用户自己编写更好的statusline,但我看不到任何有助于他们的东西。也许我只是找错地方了

**这里的分支表示“存储库根URL中不存在的根目录URL的尾部”。根目录是嵌套最少的目录,其.svn子目录和存储库根URL等于包含当前缓冲区的当前目录之一


即使您不愿意使用aurum,也可以随意借用重复执行的命令或缓存实现。

谢谢,现在我有了响应,这似乎很明显。谢谢,现在我有了响应,这似乎很明显。我听说过这些插件,但我想试着自己实现这些功能。我不喜欢有太多的插件。但我会检查一下,看看有什么想法。我听说过这些插件,但我想尝试自己实现这些功能。我不喜欢有太多的插件。但我会检查一下,看看有什么想法。谢谢。