Monday, January 21, 2013

nano wrap lines

[UPDATED 2013-05-30] This post was originally intended for Linux, but since then I've also found a great set of nanorc's for mac. Surprised I never wrote a post on that, although I did pen this blip on vim. Point is, macs come with nano, but no nanorc files at all!

I admit that vim is slowly wining me back. But nano can be tweaked if you care to try. I made a few quick changes to the default .nanorc - I found a few gitcommit.nanorc online. I also added line wrapping, autoindent and tabs-to-spaces - and now nano is much better for me.

Since there is some bug in nano-2.2.6 that prevents it from reading both /etc/nanorc and ~/.nanorc copy nanorc to your home folder and edit that file.

    me@linux ~$ cp /etc/nanorc ~/.nanorc

I ended up going with this gist by keithamus because it was simple and sufficient for what I need.
But there were a few others:
Burried in a Github repo called dotfile by nicinabox is this nearly identical nanorc with a few additions. Another gist by koraktor is a more complex, but you can start to see common bits and pieces. There are a couple posts that might have some issues. Milian Wolff's site has a long nanorc, and void on Github is also very similar.

Append the gicommit.nanorc to the end of the nanorc file.

    me@linux ~$ echo include ~/.local/share/nano/gitcommit.nanorc >> ~/.nanorc

Then as you can see copy the new gitcommit.nanorc file to ~/.local/share/nano/gitcommit.nanorc.

Autoindent, mouse and tabstospaces are really nice features, but what I really needed was line-wrapping which I added by commenting out the line that says, "set nowrap." Voila, nearly as good as vim.

Here is a patch with my changes:

--- /etc/nanorc
+++ ~/.nanorc
@@ -16,7 +16,7 @@
 ## ", ', ), >, ], and }.

 ## Use auto-indentation.
-# set autoindent
+set autoindent

 ## Backup files to filename~.
 # set backup
@@ -51,7 +51,7 @@
 ## If fill is 0 or less, the line length will be the screen width less
 ## this number.
-# set fill -8
+set fill -8

 ## Enable ~/.nano_history for saving and reading search/replace strings.
 set historylog
@@ -70,7 +70,7 @@
 ## double click), and execute shortcuts.  The mouse will work in the X
 ## Window System, and on the console when gpm is running.
-# set mouse
+set mouse

 ## Allow multiple file buffers (inserting a file will put it into a
 ## separate buffer).  You must have configured with --enable-multibuffer
@@ -91,7 +91,7 @@
 # set nonewlines

 ## Don't wrap text at all.
-set nowrap
+# set nowrap

 ## Set operating directory.  nano will not read or write files outside
 ## this directory and its subdirectories.  Also, the current directory
@@ -150,10 +150,10 @@
 set suspend

 ## Use this tab size instead of the default; it must be greater than 0.
-# set tabsize 8
+set tabsize 4

 ## Convert typed tabs to spaces.
-# set tabstospaces
+set tabstospaces

 ## Save automatically on exit, don't prompt.
 # set tempfile
@@ -174,7 +174,7 @@
 # set undo

 ## Enable soft line wrapping (AKA full line display)
-# set softwrap
+set softwrap

 ## Color setup
@@ -297,3 +297,6 @@

 ## XML-type files
 include "/usr/share/nano/xml.nanorc"
+## git commit msg
+include /home/marko/.local/share/nano/gitcommit.nanorc

No comments:

Post a Comment

Fork me on GitHub