Can I write a script to indicate which files are currently being edited in vim?

I use tmux with many windows, and often lose information about the files that I edit in vim. I would like to open another shell that runs a script that tells me the file paths that vim is currently editing.

I am running Mac OS.

+4
source share
3 answers

The way I solved the problem was to request all remote Vim processes for their open buffers. You can use the functionality of the Vim client server for this. GVIM server names are usually called sequentially: GVIM , GVIM1 , ...; for the Vim terminal, you will have to call them the argument --servername (for example, through a shell alias).

You can then query the list of open files with the --remote-expr argument. A simple expression to loop over all of the buffers listed (for example, as shown by :ls ):

 map(filter(range(1, bufnr('$')), 'buflisted(v:val) && ! empty(bufname(v:val))'), 'bufname(v:val)') 

As you can see, this is a bit related and may affect your workflow for launching Vim. Think about whether you really need it!

+1
source

What I know about is that there is no way to get every open vim buffer from an external process. Instead of using separate tmux layouts and a separate vim instance to edit multiple files, you can have one vim instance and edit several separate files using :split and :tabnew . Then in this vim instance you can use :ls to view the paths of all open files relative to the current working directory. :pwd also works.

If this is not your style, and you still want to use vim in separate layouts, you can use ps to view the arguments for each vim process and check the cwd of those processes. Sort of:

 paste <(pgrep vim | xargs pwdx) <(pgrep vim | xargs ps -o %a | sed 1d) 

Note that if you use multiple buffers in vim, this will not work, because it will only list the arguments given to each vim command, not the list of actual buffers.

0
source

You can configure using ps -eF | grep vim ps -eF | grep vim for your script. At the end of each line of the result, you will see various processes related to everything related to "vim". Therefore, you will find out which files vim is currently editing (for example, vim foo.txt), as well as the "grep vim" that was active to get this result. To get a good result, you will have to filter all of them with a script. Hope this helps you.

0
source

Source: https://habr.com/ru/post/1502310/


All Articles