189
votes
How do I delete multiple lines in nano without affecting the clipboard?
nano of course can delete blocks, see this article
use CTRL+Shift+6 to mark the beginning of your block
move cursor with arrow keys to end of your block, the text will be highlighted.
use CTRL+K to ...
187
votes
Accepted
Copy (only copy, not cutting) in Nano?
Position the cursor at the beginning of the character from which you want to copy. Press Alt+Shift+A to set mark. ( Alternatively, set mark with Ctrl+6 )
Use arrow keys to highlight the text to copy.
...
155
votes
How to show line numbering in nano when opening a file
Accidentally found nice shortcut: Alt+#, which in some keyboard layouts can be done with Alt+Shift+3.
119
votes
Accepted
How to show line numbering in nano when opening a file
According to the man page for GNU nano 2.9.3 (also verified on version 4.8) , you have two options for automatically opening with line-numbers shown and one for toggling them on/off once nano is open:
...
63
votes
Copy (only copy, not cutting) in Nano?
Workaround: cut, then uncut, and uncut again in the place where you want to copy the text.
unicorns
rainbows
line4
I Ctrl+K unicorns
rainbows
line4
I uncut Ctrl+U
unicorns
rainbows
line4
I ...
58
votes
Getting error while opening /etc/profile: Error reading lock file /etc/.profile.swp: Not enough data read
Try to remove the hidden file .[yourfilename].swp, which is stored in the same folder as the file that you are trying to open.
In your case try the shell command rm /etc/.profile.swp.
This issue also ...
35
votes
Accepted
"file /var/log/syslog is being edited" message in nano
If the option "vim-style lock-files" is enables (set locking in nanorc), which is the case by default, nano creates a special so called "lock file" while you edit a file to indicate that the file is ...
28
votes
How to show line numbering in nano when opening a file
Compile Nano from source:
git clone git://git.savannah.gnu.org/nano.git;cd nano;./autogen.sh;./configure;sudo make install
Then add the following to your .nanorc file:
set linenumbers
You can ...
28
votes
Edit crontab with an editor other than the default
crontab should respect the EDITOR environment variable, so you can just do (for the root crontab for example)
sudo EDITOR=vi crontab -e
From man crontab
The -e option is used to edit the current ...
23
votes
Accepted
Opening a file in read-only mode using nano
Nano does not use '-R' as a "read-only-" option and uses '-R' for something else.
-R, --restricted
Restricted mode: don't read or write to any file not specified
on the command line. ...
22
votes
How do I delete multiple lines in nano without affecting the clipboard?
If you are trying to empty all of the lines.
A pretty elegant and simplest approach is from the bash-cli:
echo "" > filename.txt
nano filename.txt
15
votes
How to exit nano and save to current file automatically?
According to Nano manual
You can configure ~/.nanorc to Save automatically on exit, don't prompt
($:~)=> nano -w ~/.nanorc
# Save automatically on exit, don't prompt
set tempfile
Note: as ...
13
votes
How do I delete multiple lines in nano without affecting the clipboard?
CTRL SHIFT K
deletes current line, It can also be useful for quick editing.
Thanks
Edit1:
In some of the putty streams, the following works too
CTRL K
13
votes
Change the default editor when sudo visudo
If you never plan to use nano, you can also simply remove it. Then the system will use vi/vim as the default.
sudo apt-get purge nano
I know it is not the official answer, but it is one of the first ...
13
votes
How to move the blinking cursor with the mouse in nano editor?
Add this to your ~/.nanorc file
set mouse
This will cause the mouse to work every time you open nano
(source The GNU nanorc documentation)
13
votes
Setting permanent export EDITOR to nano for all future sessions
A couple of easy steps should see you through:
Log into your account using ssh
Open the file ~/.bashrcwith a text editor
Add something like the following:
export EDITOR='/usr/bin/nano'
Save the ...
13
votes
Accepted
How do I save and quit after making changes in a config file?
The :wq is for a different editor than the one you are using.
The one that you are using, asks you to press ctrl+o to output (write) the file, and ctrl+x to exit
10
votes
Can I enable bracket matching in nano?
set brackets ""')>]}"
set matchbrackets "(<[{)>]}"
Update ~/.nanorc (or perhaps /etc/nanorc) with these lines and it works like a charm.
When on any bracket press Meta] (often this will be ...
10
votes
Accepted
9
votes
How can I change the keyboard shortcuts in nano?
The following has been tested using nano from a terminal in MS-Windows.
It will get your nano one step closer supporting the "universal" shortcuts for copy/cut/paste etc. (at least in the Windows ...
9
votes
Change the default editor when sudo visudo
As described in this answer, add
Defaults editor=/path/to/editor
to the sudoers file.
Note: this will only work if the file being edited contains the Defaults editor=/path/to/editor line or ...
9
votes
How to move the blinking cursor with the mouse in nano editor?
See The GNU nano text editor - Feature Toggles:
[...] the Meta key (Alt or Cmd, shown as M-) [...]
[...]
Mouse Support
M-M toggles the -m (--mouse) command-line option.
Esc+M (always after ...
9
votes
.nano_history permissions error
This can happen when you don't own the .nano_history file that's normally contained inside your home directory. This happened to me when I ran nano for the first time on my Ubuntu install along with ...
9
votes
How to display line numbers in Nano text editor
Ctrl+C will show the current line/column once, and Meta+C (usually Alt+C) will toggle a continuous line/column display on and off.
Ctrl+_ (that's underscore, so on most keyboard layouts that's Ctrl+...
9
votes
Copy (only copy, not cutting) in Nano?
Yes copying text is a bit strange in nano, and somewhat confusing due to conflicting reports on the webs and lack of clarity (or common sense...) both in the way it was implemented (IMHO) and in the ...
9
votes
Accepted
date command not resolving properly in bash alias
The date commands are evaluated when you declare the alias.
Here's an example alias t:
$ alias t="echo \"$(date +%k%M)\""
$ alias t
alias t='echo "1357"'
You can fix ...
9
votes
How can one copy text from nano in Ubuntu WSL2 and paste it into a Windows application?
The usual way is selecting the text with the mouse and right click for copy.
You can also use clip.exe to copy all the content of a linux file to Windows Clipboard.
cat ~/.ssh/id_rsa.pub | clip.exe
8
votes
How to use Undo functionality in Nano?
You can also add the line
set undo
in the .nanorc file. This enables the experimental undo feature on startup in versions below 2.4, such as 2.2.6 which seems to be the standard installation on many ...
8
votes
How to show line numbering in nano when opening a file
It's 2021. The OP's question is still valid, but many of the answers here are for an older version of nano. I'm not presenting this answer as "the last word" - only as an update.
The ...
8
votes
How do I enable syntax highlighting in nano?
This should include all the syntax highlighting plugins included by default, and any you add to /usr/share/nano:
find /usr/share/nano -name '*.nanorc' -printf "include %p\n" > ~/.nanorc
Or, edit /...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
nano × 174command-line × 40
text-editor × 16
sudo × 11
permissions × 10
shortcut-keys × 9
14.04 × 7
vim × 7
vi × 6
syntax-highlighting × 6
12.04 × 5
bash × 5
scripts × 5
configuration × 5
windows-subsystem-for-linux × 5
editor × 5
16.04 × 4
18.04 × 4
server × 4
ssh × 4
ubuntu-core × 4
text × 4
apt × 3
20.04 × 3
lubuntu × 3