作为全世界最优秀的代码编辑器之一,Sublime Text 3 极高的颜值强大的功能,尤其是丰富的插件系统,使它成为了我目前的主力软件之一。这篇文章的 Markdown 源文件就是用它敲出来的。对于一个完美主义者和软件洁癖患者来说,Sublime Text 的优势还在于它非常贴心地提供了 Portable 版本。
一直以来我都觉得,只要你能想到的功能,Sublime Text 3 总能实现,最多不过是搜索一下,Install Package 一波就完成了。然而困扰我很久的一件事居然是—— Sublime Text 的 Find 历史记录怎么删除??
听起来很简单,软件多半会提供这个选项。然而,我只看到了 Sublime Text 3 的“最近打开文件”清除选项,愣是没有找到搜索历史记录的任何痕迹。其实这也不是什么新鲜事, Adobe 就很喜欢把他家软件的“最近打开文件列表”数据通通存在注册表里。然而我的 Sublime Text 是 Portable 版本,按理根本不会写入注册表,并且能存放数据的只有它自身的目录而已。但我在软件目录里翻来覆去也没有找到任何诸如 history 之类的字眼。这就很玄学了。百度上关于这个问题没有任何相关信息,换用英文表述 Google 之后,很快找到了有人的提问:Clear find results on every new find in Sublime Text.
答曰:
Unfortunately, there doesn’t seem to be a built in option to do so in the settings. The only method I know to make Sublime 3 “forget” the searched last strings is to erase them from a session file that is created after closing Sublime.
emmm…你看,真不是我蠢,人家居然还真没做这个功能,而且把数据存在了相当隐蔽的角落:
On Windows:
%appdata%\Sublime Text 3\Local\Session.sublime_session
On Linux:
~/.config/sublime-text-3/Local/Session.sublime_session
On OSX:
~/Library/Application Support/Sublime Text 3/Local/Session.sublime_session
用 Sublime Text 打开这个文件,搜索 find_history,删除相应数据即可。当然,也可以搜索 history,顺带把所有的历史记录清一清。
然而重启 ST3 ,发现历史记录还在……于是重新打开 Session.sublime_session 文件,发现刚刚删掉的东西又回来了……
再 google,发现在 Sublime 的官方论坛上有一位仁兄生动地描绘了他的惨痛经历:
Edit: Having tried this, at least for me, it doesn’t work. With just Notepad, making sure ST3 was not loaded, I cleared all the entries for the ‘find history’. The file was clear of any references to any of my recent searches. Upon starting ST3, ALL the previously deleted searches were back.
Clearly there are some other places on the system that store these details.
Edit 2: I must have done something wrong before because it works as expected.
Clear the data in both sections and history is cleared.
I don’t know why I thought it would be stored elsewhere, paranoid I guess. All those other programs writing stupid stuff to the registry. I should have realised that a cross-platform program as good as this one, would make things like this as easy as possible.
Edit 3: As usual I spoke too soon. There of course more locations where your history is stored. Every project stores its own settings in a session file and everytime you load that project ALL the history is loaded back into the general session file again.
This is stupid! Separating the histories into their own projects is a good idea. Making those settings reload into the general settings is not.
Please make a simple command to clear the general history AND to clear project histories.
好吧这位兄弟大概是气急败坏了。其实没有他说得那么严重,Sublime Text 还真没有乱存文件或者改注册表。只是……用自家的矛捅自家的盾难免发生意外。机智的我已经想到,应该是使用 Sublime Text 期间软件在不断覆写这个数据文件,导致无法保存。于是,关掉 ST3,打开万年不用的备胎 Notepad++,重复上面的操作,再打开 ST3,完美!
至此这个困扰我已久的问题终于完美解决了。不得不说,优秀的 Sublime Text 在这个小小的问题上严重伤害了痕迹抹除党们的感情。我感到有必要对开发者重申刚才那位兄弟的最后一句话:
Please make a simple command to clear the general history AND to clear project histories !