Vim Tips Wiki
Register
(→‎Comments: thoughts)
(we don't seem to have a local .vimrc tip)
Line 12: Line 12:
 
}}
 
}}
 
{{dodgy|local vimrc is handled in another tip and searching upward in a directory tree for tags is built-in, see comments}}
 
{{dodgy|local vimrc is handled in another tip and searching upward in a directory tree for tags is built-in, see comments}}
  +
  +
See [[VimTip804|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:
  +
  +
* {{script|id=441|text=localvimrc}} which sources all (or configurable number of) .lvimrc files (configurable name) from the buffer's directory up to the root.
  +
* {{script|id=727|text=local_vimrc}} which sources all _vimrc_local.vim files from $HOME to current buffer's directory
  +
* {{script|id=1408|text=local configuration}} which sources a .lvimrc file in the buffer's directory. Documentation is not clear whether/how far an upward search is performed.
  +
* {{script|id=2792|text=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).
  +
* {{script|id=3393|text=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:
  +
 
<pre>
 
<pre>
 
" Source .../.vimrc and use .../tags in ancestor of source directory.
 
" Source .../.vimrc and use .../tags in ancestor of source directory.
Line 28: Line 39:
 
exe ":set tags+=".local_tags
 
exe ":set tags+=".local_tags
 
let parent = parent+1
 
let parent = parent+1
" ToDo: stop at the root on windows and ~ on unix.
+
" TODO: stop at the root on any system and also ~ on Unix.
 
endwhile
 
endwhile
 
unlet parent local_vimrc
 
unlet parent local_vimrc
 
</pre>
 
</pre>
 
See [[VimTip727|tip 727]] for a way to handle local vimrc and [[VimTip804|tip 804]] for upward tag searches.
 
   
 
==References==
 
==References==
Line 60: Line 69:
 
Should we delete this tip? Its content is handled in two separate tips. --[[User:Fritzophrenic|Fritzophrenic]] 15:28, May 3, 2011 (UTC)
 
Should we delete this tip? Its content is handled in two separate tips. --[[User:Fritzophrenic|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? [[User:JohnBeckett|JohnBeckett]] 07:19, May 4, 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? [[User:JohnBeckett|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|id=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}}. --[[User:Fritzophrenic|Fritzophrenic]] 15:13, May 4, 2011 (UTC)

Revision as of 15:13, 4 May 2011

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)