Lai Yu-Hsuan
Lai Yu-Hsuan

Reputation: 28131

what is .netrwhist?

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?

Upvotes: 153

Views: 55202

Answers (4)

ayekat
ayekat

Reputation: 333

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'

Or (update 2024-09-06), as pointed out in the comments, with the addition of XDG_STATE_HOME to the specification, the state directory probably makes more sense for history files:

let g:netrw_home=$XDG_STATE_HOME.'/vim'

Upvotes: 13

ericbn
ericbn

Reputation: 10998

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.

Upvotes: 5

user21497
user21497

Reputation: 1181

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.

Upvotes: 20

Pavan Manjunath
Pavan Manjunath

Reputation: 28545

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.

Upvotes: 134

Related Questions