Can Nano save the current position of the cursor at exit and, when you reopen the file, restore the old cursor position, like vim does?
2 Answers
On Ubuntu 2018. In ~/.nanorc put:
set positionlog
Just as a tip, I also have these:
set tabsize 4
set tabstospaces
set autoindent
set smooth
-
1Thank you. I found very useful also these options:
set atblanksset constantshowset linenumbersset mouseset softwrapMarco Sulla– Marco Sulla2019-10-07 10:18:21 +00:00Commented Oct 7, 2019 at 10:18 -
I tried also to add
set historylogandset backupdir /tmp/nano/, but it seems they does not work.Marco Sulla– Marco Sulla2019-10-07 10:20:15 +00:00Commented Oct 7, 2019 at 10:20 -
works in centos 9Boppity Bop– Boppity Bop2022-03-24 13:18:21 +00:00Commented Mar 24, 2022 at 13:18
nano has a compile-time option to support this feature, in nano.c, added in February 2011:
#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
The corresponding changelog entry is
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.
It is ifdef'd (may not be available in your packaged version). But if available, this is configured with -P (command-line option) or positionlog (or poslog, deprecated) in the nanorc file.
-
The positionlog option is enabled by default in my Debian and CentOS machines, but not on a debian production server I happen to be using today.andrew lorien– andrew lorien2018-11-22 01:21:27 +00:00Commented Nov 22, 2018 at 1:21
nano +65 /path/to/file. Not what you are looking for, I see