Before I came here, I went to executing command from within Vim and learned it can be done using:

:!command

Then I went to executing it silently and figured how that I need to run:

:silent exec "!command"

Now I want to do it periodically like every 5 seconds or so. Can anyone help me?

The requirement is that I need to generate tags on the go as I write the code using Ctags.

I'll prefer OG answers if possible over the Plugins and some other tools/utilities.

  • putting the command into bash file and running the bash file silently? Will that work? – MaNyYaCk Sep 12 at 12:54
  • 2
    you can make use of the timer functionality (see :h timer_start) – Christian Brabandt Sep 12 at 13:13
  • If you decide to do this outside of Vim, then you may want to look at watch. See man watch – Peter Rincker Sep 12 at 14:49
  • Just out of interest, what is "OG" meant to stand for? – user579 Sep 14 at 10:49
  • Old generation, Not in a disrespectful way but as in more experienced and one prefering the old ways to do it. – MaNyYaCk Sep 14 at 11:12
up vote 3 down vote accepted

As @ChristianBrabandt mentions in the comments, presuming you're using a reasonably recent version of Vim, you could do this with a timer.

In fact, you can virtually just copy-paste the example in from :help timer-start:

func MyHandler(timer)
  silent exec "!command"
endfunc
let timer = timer_start(500, 'MyHandler', {'repeat': -1})

I wouldn't recommend this though. I think you're better of using an alternative method such as:

  • generate tags on file save by using an autocommand,
  • generate the tags outside of Vim with something like watch, inotify or git hooks,
  • use a plugin. I use gutentags, but there are several others.
  • I made a change to my .vimrc by copying that into it for testing. It takes me out of vi everytime. Now I can't edit my .vimrc using vim LOL. GUIs Text Editor for the rescue. And I figured out just now that I may open other files using vim as well, so generating tags and scope file for that sounds so stupid to me, didn't think about that myself. – MaNyYaCk Sep 13 at 5:15
  • You could also have started vim with the command vim -Nu NONE ~/.vimrc to ignore your vimrc while you fixed it. If you want to persist with rolling your own Vimscript solution, I’d look into autocommands. – Rich Sep 13 at 6:01
  • No, I don't persist to use my own script, I had it on high preference since sometimes plugins dont exactly match your need and time is wasted. I looked into your Alternative methods, gutentags seems fine as of now , I am still testing. Will let you know by the end of day, Indian Standard Time. – MaNyYaCk Sep 13 at 7:18

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.