76411Re: automatic code completion in vim
- Jan 1, 2007On pon sty 1 2007, Mikolaj Machowski wrote:
> > Note: much faster, noticeable on big files, would be reading of:new somename
> > tags file into buffer and just g//d proper lines and add tags at the
> > end
> how to read tags into the buffer and what does "g//d proper lines" mean?
> > - but I hate buffer management in scripts, YMMV.Safer::
> > Sounds complicated but Vim should be able to perform all actions with
> > reasonable speed. The most expensive is f) .
> > You should carefully consider when this function should be performed.
> > I would vote for ; and BufLeave and BufWritePre autocommands.
> > m.
> I write the function like this, but there are some problems.
> This is my first time to write vim script, so please give me a hand.
> inoremap <expr> ; UpdateTags()
> func UpdateTags()
> "get the file name of the current buffer
> let currentfilename=bufname("%")
let fname = expand('%:p')
Full path will prevent ambiguity in some corner cases.
> "get the last line number in the current bufferJust::
> let lastline=line('$')
> let currentfile=getline(1 , lastline)
let currentfile=getline(1, '$')
> "how to define the temporary file nameAs I wrote, better to skip writing of tags to file, faster and you avoid
> call writefile(currentfile , ".tmp.cc" , "b")
> call system('ctags --c++-kinds=+p --fields=+iaS --extra=+q -f .tags
> let currenttags=readfile(".tags" , "b")
messing with filenames::
let currenttags = system('ctags --c++-kinds=+p -- fields=+iaS
--extra=+q -f - .tmp.cc')
> "remove the comment in the tags fileAnother benefit of using '-f -' - ctags when dealing with STDOUT doesn't
> call remove(currenttags , "^!")
add !comment lines. Note for future - remove() doesn't accept RE, only
> let alltags=readfile("tags" , "b")remove() doesn't accept regexps only indexes. To remove offending lines
> call remove(alltags , currentfilename)
call filter(alltags, "v:val !~ fname")
> echo currenttags??? substitute() is for strings. Now you can do::
> substitute(currenttags , ".tmp.cc" , currentfilename , "g")
> "here I want to replace ".tmp.cc" with currentfilename in the new
> created tags file,
> "but vim always gives me an error "E486: Pattern not found: currenttags
> , ".tmp.cc" , currentfilename , "g")"
let newtags = alltags + currenttags
> "echo currenttags has showed me currenttags contains ".tmp.cc".call writefile(newtags, "tags", 'b')
> call add(alltags , currenttags)
> call writefile(alltags , "tags" , "b")
> "I want to write the updated tags into the file "tags" , but failed.m.
> "The error is "E730: using List as a String"
> "I don't understand
> Zheng Da
- << Previous post in topic Next post in topic >>