문제

지금은 다음과 같습니다 .vimrc:

au BufWritePost *.c,*.cpp,*.h !ctags -R

이것에는 몇 가지 문제가 있습니다.

  1. 느리게 - 마지막 태그 생성 이후 변경되지 않은 파일의 태그를 재생합니다.
  2. 입력 버튼을 눌러야합니다 다시 피할 수없는 "Enter 또는 Type 명령을 계속 누르십시오"때문에 파일을 작성한 후에.

이 두 가지 문제를 결합하면 추가 Enter가 너무 빨리 푸시됩니다 (전 ctags -R 완료되었습니다) 그런 다음 성가신 오류 메시지를보고 다시 입력해야합니다.

나는 그것이 큰 문제처럼 들리지 않는다는 것을 알고 있지만, 주어진 날에 내가하는 파일의 양을 사용하면 정말 성가신 경향이 있습니다. 더 좋은 방법이 있어야합니다!

도움이 되었습니까?

해결책

au BufWritePost *.c,*.cpp,*.h silent! !ctags -R &

단점은 완료 될 때까지 유용한 태그 파일이 없다는 것입니다. 당신이 *nix 시스템을 사용하는 한, 이전 ctags가 완료되기 전에 여러 저술을하는 것이 좋을 것입니다. 그러나 그것을 테스트해야합니다. Windows 시스템에서는 백그라운드에 넣지 않으며 첫 번째 CTAGS가 완료 될 때까지 파일이 잠겨 있다고 불평합니다 (VIM에서는 문제를 일으키지 않아야하지만 약간 오래된 태그 파일로 끝납니다. ).

참고, 당신은 그것을 사용할 수 있습니다 --append Tonylo가 제안한대로 옵션이지만 비활성화해야합니다. tagbsearch 이는 태그 검색이 태그 파일의 크기에 따라 훨씬 더 오래 걸린다는 것을 의미 할 수 있습니다.

다른 팁

편집하다: 다음 선을 따라 매우 많은 솔루션이 게시되었습니다. 그만큼 자동 태그 VIM 스크립트. 스크립트에 유의하십시오 파이썬 지원이 필요한 VIM이 필요합니다, 하지만.

내 솔루션은 대신 AWK로 껍질을 벗기므로 더 많은 시스템에서 작동해야합니다.


au FileType {c,cpp} au BufWritePost <buffer> silent ! [ -e tags ] &&
    \ ( awk -F'\t' '$2\!="%:gs/'/'\''/"{print}' tags ; ctags -f- '%:gs/'/'\''/' )
    \ | sort -t$'\t' -k1,1 -o tags.new && mv tags.new tags

스크립트로만이 방법 만 쓸 수 있습니다. 그렇지 않으면 한 줄로 가야합니다.

거기에 많은 일이 일어나고 있습니다.

  1. 이 자동 명령은 파일이 C 또는 C ++로 감지되었을 때 트리거되고 차례로 BufWritePost 이벤트.

  2. 사용합니다 % 실행 시간에 버퍼의 파일 이름으로 대체되는 자리 표시자는 :gs 수정자는 파일 이름을 쉘 쿼트하는 데 사용됩니다 (임베디드 한 단일 크기를 견적 에스케이프 쿼트로 바꾸어).

  3. 그렇게하면 tags 파일이 존재하며,이 경우 방금 구조 된 파일을 참조하는 줄을 제외하고는 콘텐츠가 인쇄됩니다. ctags 방금 구조 된 파일에서만 호출되며 결과는 다음과 같습니다. sort에드와 제자리에 다시 넣습니다.

경고 구현 자 : 이것은 모든 것이 동일한 디렉토리에 있으며 이는 버퍼 로컬 전류 디렉토리라고 가정합니다. 나는 경로를 망울로 생각하지 않았다.

나는 썼다 EasyTags.vim 이 작업을 수행하려면 : 자동으로 업데이트하고 태그를 강조 표시합니다. 플러그인은 편집중인 파일 만 또는 편집중인 파일 디렉토리의 모든 파일 만 업데이트하도록 구성 할 수 있습니다 (재귀 적으로). 글로벌 태그 파일, 파일 유형 특정 태그 파일 및 프로젝트 별 태그 파일을 사용할 수 있습니다.

나는 이것이 오래된 스레드라는 것을 알았습니다 ... 사용 인크 론 *nix와 같은 환경을 지원하는 환경. 디렉토리의 파일이 변경 될 때마다 항상 명령을 시작합니다. 즉,

/home/me/Code/c/that_program IN_DELETE,IN_CLOSE_WRITE ctags --sort=yes *.c

그게 다야.

아마도 다음과 같이 설명한대로 CTAG에 대한 Append 인수를 사용하십시오.

http://vim.wikia.com/wiki/autocmd_to_update_ctags_file

코드 브라우징에 일반적으로 소스 통찰력을 사용하기 때문에 실제로 보증 할 수는 없지만 vim을 편집기로 사용합니다 ... GO 그림으로 사용하십시오.

CTAG가 Crontab을 통해 실행할 예정인 것은 어떻습니까? 프로젝트 트리가 구조에서 상당히 안정적이라면 가능해야합니까?

"Enter 프레스"프롬프트를 억제하려면 :조용한.

OSX 에서이 명령은 적어도 나에게는 그렇지 않습니다.

au BufWritePost *.c,*.cpp,*.h silent! !ctags -R &

나는 a를 찾았다 게시하다, -R 옵션이 포함 된 표준 CTAGS 버전을 얻는 방법을 설명합니다. 이것만으로도 저에게는 효과가 없었습니다. Homebrew가 프로그램을 설치하는 빈을 선택하기 위해 .bash_profile의 경로 변수에/usr/local/bin을 추가해야했습니다.

내 Opninion에서는 플러그인 인덱서가 더 좋습니다.

http://www.vim.org/scripts/script.php?script_id=3221

그것은 될 수 있습니다:

1) project.tar.gz 용 추가 기능

2) 독립 플러그인

  • 배경 태그 생성 (CTAGS가 작동하는 동안 대기하지 않음)
  • 여러 프로젝트가 지원됩니다

VIM 플러그인이 호출됩니다 자동 태그 이것을 위해 정말 잘 작동합니다.

TagList가 설치된 경우이를 위해 업데이트됩니다.

그만큼 --append 옵션은 실제로가는 길입니다. A와 함께 사용됩니다 grep -v, 우리는 하나만 업데이트 할 수 있습니다 태그 파일. 예를 들어, 여기에 발췌가 있습니다 닦지 않은 플러그인 이 문제를 해결합니다. (NB : "외부"가 필요합니다. 라이브러리 플러그인)

" Options {{{1
let g:tags_options_cpp = '--c++-kinds=+p --fields=+imaS --extra=+q'

function! s:CtagsExecutable()
  let tags_executable = lh#option#Get('tags_executable', s:tags_executable, 'bg')
  return tags_executable
endfunction

function! s:CtagsOptions()
  let ctags_options = lh#option#Get('tags_options_'.&ft, '')
  let ctags_options .= ' '.lh#option#Get('tags_options', '', 'wbg')
  return ctags_options
endfunction

function! s:CtagsDirname()
  let ctags_dirname = lh#option#Get('tags_dirname', '', 'b').'/'
  return ctags_dirname
endfunction

function! s:CtagsFilename()
  let ctags_filename = lh#option#Get('tags_filename', 'tags', 'bg')
  return ctags_filename
endfunction

function! s:CtagsCmdLine(ctags_pathname)
  let cmd_line = s:CtagsExecutable().' '.s:CtagsOptions().' -f '.a:ctags_pathname
  return cmd_line
endfunction


" ######################################################################
" Tag generating functions {{{1
" ======================================================================
" Interface {{{2
" ======================================================================
" Mappings {{{3
" inoremap <expr> ; <sid>Run('UpdateTags_for_ModifiedFile',';')

nnoremap <silent> <Plug>CTagsUpdateCurrent :call <sid>UpdateCurrent()<cr>
if !hasmapto('<Plug>CTagsUpdateCurrent', 'n')
  nmap <silent> <c-x>tc  <Plug>CTagsUpdateCurrent
endif

nnoremap <silent> <Plug>CTagsUpdateAll     :call <sid>UpdateAll()<cr>
if !hasmapto('<Plug>CTagsUpdateAll', 'n')
  nmap <silent> <c-x>ta  <Plug>CTagsUpdateAll
endif


" ======================================================================
" Auto command for automatically tagging a file when saved {{{3
augroup LH_TAGS
  au!
  autocmd BufWritePost,FileWritePost * if ! lh#option#Get('LHT_no_auto', 0) | call s:Run('UpdateTags_for_SavedFile') | endif
aug END

" ======================================================================
" Internal functions {{{2
" ======================================================================
" generate tags on-the-fly {{{3
function! UpdateTags_for_ModifiedFile(ctags_pathname)
  let source_name    = expand('%')
  let temp_name      = tempname()
  let temp_tags      = tempname()

  " 1- purge old references to the source name
  if filereadable(a:ctags_pathname)
    " it exists => must be changed
    call system('grep -v "  '.source_name.' " '.a:ctags_pathname.' > '.temp_tags.
      \ ' && mv -f '.temp_tags.' '.a:ctags_pathname)
  endif

  " 2- save the unsaved contents of the current file
  call writefile(getline(1, '$'), temp_name, 'b')

  " 3- call ctags, and replace references to the temporary source file to the
  " real source file
  let cmd_line = s:CtagsCmdLine(a:ctags_pathname).' '.source_name.' --append'
  let cmd_line .= ' && sed "s#\t'.temp_name.'\t#\t'.source_name.'\t#" > '.temp_tags
  let cmd_line .= ' && mv -f '.temp_tags.' '.a:ctags_pathname
  call system(cmd_line)
  call delete(temp_name)

  return ';'
endfunction

" ======================================================================
" generate tags for all files {{{3
function! s:UpdateTags_for_All(ctags_pathname)
  call delete(a:ctags_pathname)
  let cmd_line  = 'cd '.s:CtagsDirname()
  " todo => use project directory
  "
  let cmd_line .= ' && '.s:CtagsCmdLine(a:ctags_pathname).' -R'
  echo cmd_line
  call system(cmd_line)
endfunction

" ======================================================================
" generate tags for the current saved file {{{3
function! s:UpdateTags_for_SavedFile(ctags_pathname)
  let source_name    = expand('%')
  let temp_tags      = tempname()

  if filereadable(a:ctags_pathname)
    " it exists => must be changed
    call system('grep -v "  '.source_name.' " '.a:ctags_pathname.' > '.temp_tags.' && mv -f '.temp_tags.' '.a:ctags_pathname)
  endif
  let cmd_line = 'cd '.s:CtagsDirname()
  let cmd_line .= ' && ' . s:CtagsCmdLine(a:ctags_pathname).' --append '.source_name
  " echo cmd_line
  call system(cmd_line)
endfunction

" ======================================================================
" (public) Run a tag generating function {{{3
function! LHTagsRun(tag_function)
  call s:Run(a:tag_function)
endfunction

" ======================================================================
" (private) Run a tag generating function {{{3
" See this function as a /template method/.
function! s:Run(tag_function)
  try
    let ctags_dirname  = s:CtagsDirname()
    if strlen(ctags_dirname)==1
      throw "tags-error: empty dirname"
    endif
    let ctags_filename = s:CtagsFilename()
    let ctags_pathname = ctags_dirname.ctags_filename
    if !filewritable(ctags_dirname) && !filewritable(ctags_pathname)
      throw "tags-error: ".ctags_pathname." cannot be modified"
    endif

    let Fn = function("s:".a:tag_function)
    call Fn(ctags_pathname)
  catch /tags-error:/
    " call lh#common#ErrorMsg(v:exception)
    return 0
  finally
  endtry

  echo ctags_pathname . ' updated.'
  return 1
endfunction

function! s:Irun(tag_function, res)
  call s:Run(a:tag_function)
  return a:res
endfunction

" ======================================================================
" Main function for updating all tags {{{3
function! s:UpdateAll()
  let done = s:Run('UpdateTags_for_All')
endfunction

" Main function for updating the tags from one file {{{3
" @note the file may be saved or "modified".
function! s:UpdateCurrent()
  if &modified
    let done = s:Run('UpdateTags_for_ModifiedFile')
  else
    let done = s:Run('UpdateTags_for_SavedFile')
  endif
endfunction

이 코드는 다음과 같습니다.

  • ^Xta 현재 프로젝트의 모든 파일에 대한 태그 기반의 업데이트를 강제합니다.
  • ^Xtc 현재 (구원받지 않은) 파일에 대한 태그 기반의 업데이트를 강제합니다.
  • 파일이 저장 될 때마다 태그 기반을 업데이트하는 자동 명령; 또한 Filetypes에 따라 CTAGS 통화를 조정하기 위해 원하지 않는 자동 업데이트를 비활성화하는 많은 옵션과 많은 옵션을 지원합니다. 팁이 아니라 플러그인의 작은 발췌.

HTH,

자동 태그는 저장시 기존 태그 파일을 업데이트하는 VIM 플러그인입니다.

태그 파일의 최대 크기를 제외하고는 문제없이 몇 년 동안 사용해 왔습니다. 동일한 태그 파일에 모두 색인 된 코드 세트가 모두 있지 않으면 해당 제한을 누르지 않아야합니다.

자동 태그는 VIM에서 Python 지원이 필요합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top