1

I know it is basically meaningless to measure productivity by the number of lines of code, but I am curious. I use Vim, my goal is :

have a number_of_lines_code.txt file automatically update itself when I am coding, it records the number of line of code so that I can check out how much I have written within a week, month, year.

Eren Bay
  • 63
  • 6
  • I can imagine a wrapper around the vi(m) command that checks if the target file exists. If the file does not exist set a :start" variable to 0. else set it to the result of `wc -l targetFile`. Fork vim to edit the targetFile. After vim returns do another `wc -l` on the target file and subtract start from the end value and store the result with a datetime stamp in your tracking file. – 7 Reeds Aug 03 '18 at 18:35
  • 8
    it is not the task of vim/editor, you can get that information from version control system, e.g. git – Kent Aug 03 '18 at 20:06
  • I don't think Vim is the answer to your problem. Maybe try using some mix of scripts and aliases that will save the number of lines in a file before you edit it and after you edit it and subtract them from each other then add this to some sort of counter? – Stun Brick Aug 06 '18 at 08:06
  • See [Git: How to estimate a contribution of a person to my project in terms of added/changed lines of code?](https://stackoverflow.com/a/4593065/240443), that answer gives a snippet that specifically counts one's contributions (measured in LoC) in a given time interval. – Amadan Aug 06 '18 at 12:26

1 Answers1

0

As someone else has mentioned in the comments, keeping track of edited locs is not the editor's job (you should use git, or other vcs). An obvious weakness of trying to use the editor for this task, imho, is that the editor is generally not aware of preceding or following sessions of the same editor.

However, one manual, naif way to do what you want could be the following

  • save the file
  • undo all the changes (this can be very easy to do, if you use the Gundo plugin, but I bet there are other ways to do the same)
  • save the file with another name
  • quit vim
  • diff the two files and/or do whatever you need to transform the diff in a number
Enlico
  • 23,259
  • 6
  • 48
  • 102