DEV Community

nitiwit
nitiwit

Posted on

making nano usable

nano has always been my favorite. it's not too fancy to be annoying and huge, so you can comfortably run it on servers. it's not too low-level so there's not a very steep learning curve (comparing to vi/m).
it's often pre-installed on servers too so it doesn't need installation, just write nano into the command line and there you go.

However, it's still kind of hard to work with, and get around, since it's a cli program nonetheless. some of the troubles I find myself struggling with when working with nano are (could be terminal related, or nano related):

  1. word-wrap: I paste a long line and I see 4 characters and it takes me several seconds to have an idea about what's happened Image description

  2. no line numbers: a disadvantage for obvious reasons

  3. weird shortcuts: ctrl+k cuts a line, ctrl+u pastes it, alt+delete removes the line. not very common shortcuts, for me at least.

  4. does not ask for password on save: you need to remember and sudo nano the file when opening it. if you only nano, it won't ask you for a password before writing. it simply prompts that it's a protected file and you can't save your edits. in these cases, I just copy what I've written, paste it elsewhere, sudo nano, paste and then save. pretty annoying.

On the other hand, as mentioned before, it's very handy, versatile and fun to work with as well. so it's worth to take the extra mile and modify it based on my daily use.

two of the most useful "fixes" that I use are:

  1. / and enter a number: go to line
  2. easy to use text replace (ctrl+h in vscode/etc.): ctrl+/ and enter a text to replace. enter the replacement text, and nano shows you the occurrences and confirm whichever you like to replace.
  3. esc+shift+4 toggles soft-wrapping (google if you don't what it is. nano supports two types of wrapping.) 3.1. toggle hard-wrap with esc+l
  4. alt+shit+3 to toggle line numbers

you can also start nano with various options to have features on or off. for example nano -Y enables syntax highlighting or nano -T sets the tab size. read more here or just man nano to check them out.

finally you can write you own ~/.nanorc and write you desired customizations there. options like set linenumbers and set autoindent are available. check out this article for more

reminds one of vi's command-mode, huh...

Top comments (0)