4

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.

MaNyYaCk
  • 175
  • 1
  • 7

1 Answers1

5

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.
Rich
  • 31,891
  • 3
  • 72
  • 139
  • 1
    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 '18 at 05: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 '18 at 06: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 '18 at 07:18