Vim Tips Wiki
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
FANDOM
Fan Central
BETA
Games
Anime
Movies
TV
Video
Wikis
Explore Wikis
Community Central
Start a Wiki
Don't have an account?
Register
Sign In
FANDOM
Explore
Current Wiki
Start a Wiki
Don't have an account?
Register
Sign In
Sign In
Register
Vim Tips Wiki
1,649
pages
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
Editing
Source vimrc and use tags in a parent directory
Back to page
Edit
Edit source
View history
Talk (0)
Edit Page
Source vimrc and use tags in a parent directory
We recommend that you
log in
before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your
Watchlist
.
Creating an account
is quick and free.
The edit appears to have already been undone.
Anti-spam check. Do
not
fill this in!
{{TipImported |id=571 |previous=570 |next=572 |created=September 30, 2003 |complexity=basic |author=mosh |version=5.7 |rating=3/2 |category1= |category2= }} {{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> let local_vimrc = ".vimrc" let local_tags = "tags" let local_path = "/" let current_path = getcwd() " If the current path is a child of $HOME directory, start from $HOME if current_path =~ $HOME let local_path = $HOME . local_path let current_path = substitute(current_path, $HOME, '') endif let path_parts = split(current_path, "/") for path_part in path_parts let local_path = local_path . path_part . "/" if filereadable(local_path . local_vimrc) exe ":so " . local_path . local_vimrc endif if filereadable(local_path . local_tags) exe ":set tags+=" . local_path . local_tags endif endfor unlet local_vimrc local_tags local_path current_path path_parts </pre> ==References== *{{help|file-searching}} *{{help|vimrc-intro}} *{{help|tags}} ==Comments== There's a simpler way to do this for tags: <pre> set tags+=tags;/ </pre> {{Todo}} 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. --[[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) ::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)
Summary:
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Dodgy
(
view source
)
Template:Help
(
view source
)
Template:Navigation
(
view source
)
Template:Script
(
view source
)
Template:TipImported
(
view source
)
Template:Todo
(
view source
)
Follow on IG
TikTok
Join Fan Lab