what is .netrwhist?

VimNetrw

Vim Problem Overview


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?

Vim Solutions


Solution 1 - Vim

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.

Solution 2 - Vim

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.

Solution 3 - Vim

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'

Solution 4 - Vim

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLai Yu-HsuanView Question on Stackoverflow
Solution 1 - VimPavan ManjunathView Answer on Stackoverflow
Solution 2 - Vimuser21497View Answer on Stackoverflow
Solution 3 - VimayekatView Answer on Stackoverflow
Solution 4 - VimericbnView Answer on Stackoverflow