4

I use the mapping below:

nnoremap <silent><C-]> <C-w><C-]><C-w>T

But it will open duplicate file in multiple tabs.

I have two questions:

  • Has vim built-in functions which can return a list of tab files? like :tabs command
  • How to get tag's filename under the cursor?
3

Has vim built-in functions which can return a list of tab files? like :tabs command

You'll have to do some parsing, but you can use let myVar = execute('tabs') for this.

How to get tag's filename under the cursor?

I don't think there's a built in way to do this but here's a quick and dirty first stab at a function that will do it:

function! ReturnTagFileUnderCursor()
   try
      let tag = expand('<cword>')
      let tagString = split(execute("tselect ".tag), "\n")[1]
      let tagString = matchstr(tagString, '[^/\\]*$')
      return tagString
   catch /^Vim\%((\a\+)\)\=:E426/
      echohl ERROR
      echo "Tag not found!"
      echohl NORMAL
      return ""
   endtry
endfunction

Note: This will always take the first result if there are duplicate tags. Also it returns just the filename, but you can adjust the regex to get the whole path if desired.

See :h execute() and :h tselect for more info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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