2

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
  • No. If you want an editor with features, use an editor with features. nano's purpose is to be a minimalist, simple editor with almost no features. Commented Oct 23, 2015 at 10:28
  • don't think so, but you can open file at a certain line nano +65 /path/to/file. Not what you are looking for, I see Commented Oct 23, 2015 at 12:17

2 Answers 2

5

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
3
  • 1
    Thank you. I found very useful also these options: set atblanks set constantshow set linenumbers set mouse set softwrap Commented Oct 7, 2019 at 10:18
  • I tried also to add set historylog and set backupdir /tmp/nano/, but it seems they does not work. Commented Oct 7, 2019 at 10:20
  • works in centos 9 Commented Mar 24, 2022 at 13:18
3

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.

1
  • 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. Commented Nov 22, 2018 at 1:21

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.