Vim

Nano:記住開始時的游標位置

  • October 5, 2019

Nano 可以在退出時保存游標的目前位置,並在重新打開文件時恢復舊的游標位置,就像 vim 一樣?

在 Ubuntu 2018 上。輸入~/.nanorc

set positionlog

作為提示,我也有這些:

set tabsize 4
set tabstospaces
set autoindent
set smooth

nano有一個編譯時選項來支持這個特性,在2011 年2 月nano.c添加:

#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 <chrisa@asty.org>                                  
       * 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

引用自:https://unix.stackexchange.com/questions/238097