Wikia

Vim Tips Wiki

Source vimrc and use tags in a parent directory

Talk0
1,610pages on
this wiki
Revision as of 17:17, September 2, 2013 by 88.241.90.116 (Talk)

tabela
Tip 571 Printable Monobook Previous Next

created September 30, 2003 · complexity basic · author mosh · version 5.7


See tip 804 for the correct way to do upward tag searches. There are several "local vimrc" plugins available which are probably a better solution for a directory-specific .vimrc file:

  • localvimrc which sources all (or configurable number of) .lvimrc files (configurable name) from the buffer's directory up to the root.
  • local_vimrc which sources all _vimrc_local.vim files from $HOME to current buffer's directory
  • local configuration which sources a .lvimrc file in the buffer's directory. Documentation is not clear whether/how far an upward search is performed.
  • perdirvimrc which sources files of several different names, starting at the root directory (or home directory, this is not made clear) and progressing to the current working directory (or the buffer's directory, this is not made clear either).
  • localrc which sources files of a configurable name in the directory of any file you are editing, optionally only for files of a configurable file extension. Some recursive searching is done but the documentation does not specify exactly how this works.

That said, here is a very simple solution:

" Source .../.vimrc and use .../tags in ancestor of source directory.
" useful when you have source tree eight fathom deep,
" an exercise in Vim loops.
let parent=1
let local_vimrc = ".vimrc"
let local_tags = "tags"
while parent <= 8
  if filewritable(local_vimrc)
    echomsg "sourcing " . local_vimrc
    exe ":so " . local_vimrc
  endif
  let local_vimrc = "../". local_vimrc
  let local_tags = "../". local_tags
  exe ":set tags+=".local_tags
  let parent = parent+1
  " TODO: stop at the root on any system and also ~ on Unix.
endwhile
unlet parent local_vimrc

References

Comments

There's a simpler way to do this for tags:

set tags+=tags;/

 TO DO 
Check above tip. It probably should be entirely replaced with the comment above.


Where is this documented in the :help?


:help 'tags' and :help file-searching


Should we delete this tip? Its content is handled in two separate tips. --Fritzophrenic 15:28, May 3, 2011 (UTC)

I haven't had to worry about large trees of source for a while, and have forgotten what all the tags tricks do (although I've got some notes I took on it somewhere, and I'm sure this tip is the wrong approach). The current tip looks unhelpful to me. While mildly interesting, it is essentially an abuse of the system (do you really need a script which does what this appears to do?). I do not understand how VimTip727 has a way to handle local vimrc, but that doesn't matter. We could just replace this with a redirect to Single tags file for a source tree (and I would handle the associated change to the tip number). Is the first comment worth transferring to the target tip? JohnBeckett 07:19, May 4, 2011 (UTC)
You're right, we do not seem to have a "local vimrc" tip. No doubt the person who added the VimTip727 comment really meant script#727. I have added a list of scripts I found to the tip. I wonder if we might instead replace the tip with a redirect to a "list of local .vimrc scripts" page, but then we'd lose the "tags" portion. Actually some general information about upward search is useful for 'tags' as well as 'path' and some other options/functions. The upward search is already noted in Single tags file for a source tree. Maybe we should refer to that tip as a "see also" on the "list of scripts" page, as well as a link to :help file-searching. --Fritzophrenic 15:13, May 4, 2011 (UTC)
Advertisement | Your ad here

Around Wikia's network

Random Wiki