See also
•
https://www.growspice.com/Termux-tricks-td3491.htmlSo, now that I have an Android device and a bluetooth keyboard for it, I've decided to use Termux (downloaded from the F-Droid appstore). I've been wanting to program, write and stuff on a command-line app for Termux; so, after reviewing my options, I decided Nano was the best place to start. I've already used Nano before for small tasks, but I mostly just used my own GUI-based text editor that I programmed for Linux until now.
Before I tell you more about Nano, let me tell you about the alternatives I've discovered:
• pico
• wordgrinder (This is an actual command-line word processor. It's kind of cool, and similar to nano, although it requires heavy use of the menus for what I would want to do with it.)
• joe (I think this is another word processor, but I didn't look at it too much.)
• jed
• jove
• Emacs
• Vim
There are a few others. Most really serious command-line gurus like either Emacs or Vim; they have a much bigger learning curve than Nano. Nano is the most similar thing I've found for the command-line to a modern standard GUI-based text editor (and it has some cool features most of those don't).
Anyway, here's a comparison of the shortcuts for doing stuff in a standard GUI-based text editor and Nano:
Standard GUI-based text editor:
• Copy: ctrl+c
• Cut: ctrl+x
• Paste: ctrl+v
• Select all: ctrl+a
• Go to the beginning of the current line: home
• Go to the end of the current line: end
• Go to the beginning of the document: Ctrl+home key
• Go to the end of the document: Ctrl+end key
• Go left one word: Ctrl+left arrow key
• Go right one word: Ctrl+right arrow key
• Go up one paragraph: Ctrl+up arrow key
• Go down one paragraph: Ctrl+down arrow key
• Select from the current position to the beginning of the current line: shift+home
• Select from the current position to the end of the current line: shift+end
• Select from the current position to the beginning of the document: Ctrl+shift+home key
• Select from the current position to the end of the document: Ctrl+shift+end key
• Select to the left one word: Ctrl+shift+left arrow key
• Select to the right one word: Ctrl+shift+right arrow key
• Select up one paragraph: Ctrl+shift+up arrow key
• Select down one paragraph: Ctrl+shift+down arrow key
• Delete previous word: ctrl+backspace
• Delete next word: ctrl+delete
• Find: Ctrl+f
• Find next: Ctrl+g
• Find previous: Ctrl+shift+g
• Replace: Ctrl+h
• Undo: Ctrl+z
• Redo: Ctrl+shift+z
• New tab (new blank unsaved file in another tab): Ctrl+t
• New window: Ctrl+n
• Close tab: Ctrl+w
• Next tab: Ctrl+tab
• Previous tab: Ctrl+shift+tab
• Open file: Ctrl+o
• Save: Ctrl+s
• Save as: Ctrl+shift+s
• PageUp: PgUp
• PageDown: PgDn
• Toggle wordwrap: alt+y
• Jump to line number: ctrl+j
Now here's how you do things in Nano:
• Copy: alt+6
• Cut: ctrl+k
• Paste: ctrl+u (If you're running nano in Termux, Ctrl+Alt+v will paste from the Android clipboard instead of nano's.)
• Select all: no shortcut for this; try Ctrl+end then Ctrl+shift+home then Ctrl+k; you can make a macro to function like select all, though: to do this, try pressing shift+alt+: then ctrl+end then ctrl+shift+home then shift+alt+: (then you can just press alt+; to select all--but you can't have more than one macro to work with at the same time; so, if you make another macro, selecting all with alt+; won't work anymore)
• Go to the beginning of the current line: home
• Go to the end of the current line: end
• Go to the beginning of the document: Ctrl+home key
• Go to the end of the document: Ctrl+end key
• Go left one word: Ctrl+left arrow key
• Go right one word: Ctrl+right arrow key
• Go up one paragraph: Ctrl+up arrow key
• Go down one paragraph: Ctrl+down arrow key
• Select from the current position to the beginning of the current line: shift+home
• Select from the current position to the end of the current line: shift+end
• Select from the current position to the beginning of the document: Ctrl+shift+home key
• Select from the current position to the end of the document: Ctrl+shift+end key
• Select to the left one word: Ctrl+shift+left arrow key
• Select to the right one word: Ctrl+shift+right arrow key
• Select up one paragraph: Ctrl+shift+up arrow key
• Select down one paragraph: Ctrl+shift+down arrow key
• Delete previous word: alt+backspace (or if you have the settings in nanorc below, Ctrl+backspace and Ctrl+h will do it)
• Delete next word: ctrl+delete
• Find: Ctrl+w
• Find backwards: Ctrl+q
• Find next: alt+w; or ctrl+w then enter
• Find previous: alt+q
• Replace: Ctrl+\
• Undo: alt+u
• Redo: alt+e
• New buffer (basically the same thing as a new tab, without a tab bar): Ctrl+t then alt+f; then press enter
• Close current buffer: Ctrl+x
• Next buffer: alt+right
• Previous buffer: alt+left
• Open multiple files, each in a buffer (at nano startup): open them with nano (e.g. nano test.txt test2.txt, or to open all txt files in a folder, nano *.txt)
• Open file (when nano is already open): ctrl+r
• Open a file in a new buffer (when nano is already open): ctrl+r; alt+f (or Esc; f); type the name of the file; press enter.
• Save: Ctrl+s
• Save as: Ctrl+o (warning: if you have something selected, it'll only save what's selected, however)
• PageUp: PgDn
• PageDown: PgUp
• Toggle wordwrap: alt+s
• Jump to line number: ctrl+shift+- (ctrl+_)
• Spellcheck: F12 (You actually need to have a spellchecker installed, and enable it with .nanorc or such.)
• Alt+c: Toggle the statusbar on and off. (If you want line numbers instead, do `set linenumbers` in the nanorc file below. I have them off since they're kind of bright.)
You may want to create the file ~/.nanorc with the following contents, to make some features closer to the modern GUI-based text editor standard:
set tabsize 4
set tabstospaces
set nowrap
set softwrap
set autoindent
set atblanks
set afterends
set zap
#set nonewlines
#set multibuffer
set speller "hunspell -x -c"
set rawsequences
bind ^H chopwordleft main
bind F1 scrollup main
bind F2 scrolldown main
Those bindings to F1 and F2 (you can change them to other F-keys, or del and ins) are to make it so you can scroll more like an e-reader (without having to scroll all the way up and down before the screen moves). You may need to disable F-keys in your terminal settings first.
Also, add this to ~/.bashrc:
echo -ne "\e[3 q" #Blinking underlined
#echo -ne "\e[4 q" #Underlined
If you keep the default block cursor it'll make it seem like you're selecting one more character than you are when you're selecting to the right.
Updating nano:
To get the latest version of nano's source code (because distributions sometimes have old versions of nano), I recommend compiling it manually (I did this on Xubuntu 18.04.5 LTS) if that's the only way to get the latest version.
• To get dependencies, if you're on Ubuntu, type `sudo apt-get build-dep nano` (and maybe uninstall the one that's already there; I did).
• Download the latest version from here:
https://www.nano-editor.org/download.php (I did this with version 5.8.)
• Decompress the file
• `./configure`
• `make`
• `sudo make install`
• If you don't restart your command-line, type `bash` to get it to show up in your path.
Some issues with Nano:
• Nano doesn't delete selected text when you type, although delete and backspace will delete selected text if `set zap` above is there. If you want to delete a portion of selected text when `set zap` above isn't enabled, press ctrl+k (which will cut it, and thus delete it; but this will also put it in your clipboard). You can also press alt+delete to delete selected text without putting it on the clipboard, but be careful as it does something else if there's no selected text.
• Note that `set rawsequences` disables mouse support (if you have it enabled, which I don't above). However, it needs to be set if you want ctrl+backspace to delete the word to the left; alternatively, you can make a script that executes nano with --raw for those times when you don't care to use a mouse (don't forget to make it executable with chmod +x):
#!/bin/bash
nano --raw "$@"
Notes:
• Nano has multiple shortcuts for a lot of things (so if you don't like the ones I mentioned above, there may be others).
• This post is about GNU nano, version 5.5 on Termux, compiled options: --disable-libmagic --disable-nls --enable-utf8
Some sources:
•
https://www.nano-editor.org/dist/latest/nanorc.5.html•
https://forums.bunsenlabs.org/viewtopic.php?id=1731•
https://gist.github.com/Herteby/148b858a367baf96d38f776234af500a
2 Comments
Re: A desktop user's guide to Nano, a command-line text editor
Re: A desktop user's guide to Nano, a command-line text editor