![Nano:记住开始时的光标位置](https://linux22.com/image/75804/Nano%EF%BC%9A%E8%AE%B0%E4%BD%8F%E5%BC%80%E5%A7%8B%E6%97%B6%E7%9A%84%E5%85%89%E6%A0%87%E4%BD%8D%E7%BD%AE.png)
Nano 是否可以像 vim 一样在退出时保存光标的当前位置,并在重新打开文件时恢复旧的光标位置?
答案1
在 Ubuntu 2018 上~/.nanorc
。输入:
set positionlog
作为提示,我还有这些:
set tabsize 4
set tabstospaces
set autoindent
set smooth
答案2
nano
有一个编译时选项来支持此功能,在nano.c
,添加到2011年2月:
#ifndef DISABLE_HISTORIES
else if (ISSET(POS_HISTORY)) {
ssize_t savedposline, savedposcol;
/* If edited before, restore the last cursor position. */
if (check_poshistory(argv[i], &savedposline, &savedposcol))
do_gotolinecolumn(savedposline, savedposcol,
FALSE, FALSE);
}
#endif
相应的变更日志条目是
2011-02-18 Chris Allegretta <[email protected]>
* New saved cursor position history option. Command line option -P or --poslog, rc file
entry "poslog". Search history changes to ~/.nano/search_history, cursor position log
is ~/.nano/filepos_history. Added checks to move the legacy .nano_history file to the
new location. Several new functions to files.c: load_poshistory(), save_poshistory(),
check_poshistory(), update_poshistory(), and reworking of histfilename(). New FAQ entry
4.15 discussing the change and offering an interoperability workaround.
它是 ifdef'd(可能在您的打包版本中不可用)。但如果可用,可以在文件中使用-P
(命令行选项) 或positionlog
(或poslog
, 已弃用)进行配置nanorc
。