Vim in Windows-how to automatically update cssag database files in the background

Source: Internet
Author: User

In the past, it was always necessary to exit Vim to update cs1_database ~~ Find this article on the Internet ~~

When using csflood in VIM to edit code, you may encounter an annoying problem. When you modify and modify some files
Ah, I suddenly found that through csloud, I was unable to accurately locate some symbol positions, and no new symbol was available.
Because the cssag data files are not automatically updated, and I have been enduring this inconvenience for a long time.
At last, I had to reconstruct some source code. This time, I couldn't stop myself in the primitive society and made up my mind
In stackoverflow, find a method with only half a star. The link is here:

Http://stackoverflow.com/questions/2744010/update-cscope-db-from-vim

Because the csparts. out data files cannot be updated when they are used, we need a way to make
When Vim is used, the cssag connection is automatically terminated, so that we can update the file through a service program.
After the update, we also need to be able to add the data file back to the vim environment without human intervention.
This is the general idea. This is the answer in stackoverflow, so follow this idea to proceed,
Vim has a working mode of remote and server. You can send commands
Server (Vim instance), which makes it possible for us to disconnect/increase csflood connections without considering intervention.
The next thing is very simple.
First, we need to add two functions in Vim. I will define them as killcs.pdf and addcs.pdf, respectively. The first one
It is used to disconnect a cssag connection, and the last one is used to establish a cssag connection. The Code is as follows:
Function! Killcscope ()
CS kill-1
Endfunction

Function! Addcscope ()
CS add cscope. Out
Endfunction

Then, we can implement the Code for automatic database updates. I use batch in windows, which is environmentally friendly and practical:

@ Echo off
Title updating % project_name % cs1_database
: Loop
CMD/C Vim -- servername % 1 -- remote-expr "killcsloud ()"
@ Echo off
Call gencs.pdf. bat
@ Echo off
CMD/C Vim -- servername % 1 -- remote-expr "addcsloud ()"
Echo sleep 140 s
Ping-N 140 127.0.0.1> NUL
Goto Loop
@ Echo on

This program is very simple, it is an infinite loop, regularly disconnects CSWs, then updates the database file, and then re-
Establish a connection, where CMD/C Vim -- servername % 1 -- remote-expr "killcscope ()" is actually sending
Remote commands are run on the server named "% 1" to execute the killcscope function, while the batch named "gencscope. Bat"
The file is used to update the cssag database. How to Write this file? I mentioned in my previous blog post and
You can also view the csul help and Ping-N 140 127.0.0.1> NUL to implement latency,
The delay length can be adjusted according to your habits, because there will be a short period of time when updating the database
Therefore, this time cannot be set too short.

Finally, all we need is when to start the update script. I map the F11 key for this action. When I only read
You do not need to update the background when running the code. Therefore, you can use this key to start the program.

The Vim function is as follows:
Map <F11>: Call updatecscope () <CR>

Function! Updatecscope ()
Silent execute 'asynccommand continuous_build '.'. V: servername
Endfunction
Here the asynccommand plug-in is used, which can be easily separated from vim, And the CMD command is called without the need for me
And other operations.

This topic is about this. I hope you can enjoy happy vimming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.