what is .netrwhist?
Asked Answered
R

4

150

When I edit files in my ~/.vim, the .netrwhist file would mysteriously be changed, too.

It's content:

let g:netrw_dirhistmax  =10
let g:netrw_dirhist_cnt =6
...and so on...

What does this file do? Is it important?

Ralfston answered 24/3, 2012 at 8:52 Comment(0)
S
131

netrw is a kind of vim plugin/script which supports reading and writing files across networks. .netrwhist is a history file which maintains all the directories that were modified. So whenever you modify the contents of ~/.vim it adds one entry in .netrwhist

A sample .netrwhist is as shown

let g:netrw_dirhistmax  =10
let g:netrw_dirhist_cnt =6
let g:netrw_dirhist_1='/Users/wolever/EnSi/repos/web/env/web/lib/python2.6/site-packages/django'
let g:netrw_dirhist_2='/private/tmp/b/.hg/attic'
let g:netrw_dirhist_3='/Users/wolever/code/sandbox/pydhcplib-0.6.2/pydhcplib'
let g:netrw_dirhist_4='/Users/wolever/EnSi/repos/common/env/common/bin'
let g:netrw_dirhist_5='/Users/wolever/EnSi/repos/common/explode'
let g:netrw_dirhist_6='/Users/wolever/Sites/massuni-wiki/conf'

netrw_dirhistmax indicates the maximum number of modified directories it stores in the history file. ie Max History Size. netrw_dirhist_cnt indicates the current history count of modified directories.

If you want to disable netrw to generate history file, then see this.

Synchronism answered 24/3, 2012 at 9:40 Comment(4)
OK but...why does netrw maintain a history file? If I auto-delete it as suggested by your link, what breaks?Hoenack
Related, if it's intended for remote files, why is it recording paths for local files?Scudo
@HanSeoul-Oh, see :h netrw-u, :h netrw-U, and :h netrw-Th.Donniedonnish
@zaTricky, because "Netrw supports the browsing of directories on your local system and on remote hosts". See :h netrw-browsing.Donniedonnish
H
19

In addition, if one sets g:netrw_dirhistmax to zero, netrw will save no history or bookmarks:

:let g:netrw_dirhistmax = 0

Doing this will not cause any prior .netrwhist or .netrwbook files to be deleted, however.

Hellraiser answered 11/6, 2014 at 15:48 Comment(3)
@glts but...what's the downside of netrw saving no history bookmarks? What's different about my experience using Vim instead?Hoenack
@HanSeoul-Oh, see :h netrw-u, :h netrw-U, and :h netrw-Th.Donniedonnish
Re: ma11hew28 those help texts refer to a u/U command to go back and forward through the bookmarks and the Th seems to be some sort of marking or targetting of one of the directories. I didn't look too closely but it seems the benefit of these bookmarks are just for that manual navigation benefit. Deleting them will not affect performance or anything, you just won't have the bookmarks remembering your previous directories.Acidic
C
13

In addition, in case you want vim to respect the XDG base directory specifications in order to prevent your home folder from being littered up by dotfiles like ~/.vim, you may want to split cached files and history files from your configuration (which usually resides in the runtime path). So for example, to store .netrwhist in ~/.cache/vim, you may want to try

let g:netrw_home=$XDG_CACHE_HOME.'/vim'
Complexioned answered 12/11, 2014 at 23:59 Comment(2)
If your .vim folder is somewhere other than .vim, presumably this new location is on vim's runtimepath. g:netrw_home is set to the first directory on the runtimepath by default, which in turn is by default $HOME/.vim. So if you (ayekat) have your runtimepath set up properly, you should not have to modify g:netrw_home.Hellraiser
@Hellraiser This is true. On the other hand, if you wish to separate your configuration from things like swap files, undo files, or (as here) netrwhist, properly setting the runtimepath only partly solves the problem. But I'll edit the answer to make this a little more clear.Complexioned
S
5

From the netrw reference manual:

                        *.netrwhist*
See |g:netrw_dirhistmax| for how to control the quantity of history stack
slots.  The file ".netrwhist" holds history when netrw (and vim) is not
active.  By default, it's stored on the first directory on the user's
|'runtimepath'|.

In my case, the first path in runtimepath is ~/.vim (check with :echo &runtimepath). I'm good with that, so I don't need to change g:netrw_home.


  *g:netrw_dirhistmax*            =10: controls maximum quantity of past
                                       history.  May be zero to supppress
                                       history.

So, yeah, let g:netrw_dirhistmax=0 will stop writing to the history file.

Safford answered 30/9, 2016 at 15:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.