What is a good Linux editor for writing code?

I'm wondering if anyone has any thoughts on a decent editor to use for writing code, in particular bash scripting. By "decent" I guess I mean things like syntax highlighting, colouring, checking matching brackets, indentation support, that kind of thing.

I've been using nano because it's nice to work in and readily available, but it doesn't really give any assistance with the above. The Text Editor app on Synology's DSM is good, supports lots of languages, but I wanted something I can run right there in the terminal window where the bash script is living.

Is there maybe something fairly straightforward like nano but with some helpful features?

I've spent a little time looking at Visual Studio Code, it's perhaps overkill but I've not given it a fair try yet, need to spend more time getting to grips with it. I'm not sure if I want a full IDE, but then again it might be useful once I've seen what it can do (I guess breakpoints, showing variables, stepping through line by line, that kind of thing?). Bit of a learning curve to even get started with it.

I thought this might be worth asking in here since there are developers looking after Pi-hole and users creating scripts from time to time, plus undoubtedly some people involved in coding in their own work too.

Visual studio code is the best one I've tried, there's a lot of customization you can do with themes/plugins to make it feel just right for what you want to do with it.

If you're looking for something to run directly inside the terminal, I would recommend learning either Vim or Emacs - the learning curves are pretty steep for both but they are extremely powerful in the right hands. I use Vim on occasion (an added bonus is that it's installed on basically every unix-like machine on earth) but I have by no means mastered it.

To turn on Syntax hilighting in Vim, hit escape to leave editing mode, then type ': syntax on'

2 Likes

True, nano is far from being a full IDE substitute, but it has syntax highlighting - see ls -lah /usr/share/nano/, which should bring up a list of support language resources.

To take effect, the respective file would have to be referred by your .nanorc file.
You'd have to check your OS documentation for its exact location.

2 Likes

On the command line I usually use nano (it has syntax highlighting for many languages, but nothing else).
http://www.tuxarena.com/static/tut_nano_syntax.php
https://git.savannah.gnu.org/cgit/nano.git/tree/syntax

I use Visual Studio Code on my Windows machine, but you can also use it on Linux and MacOS.

+1 on nano

Doesn’t point out errors, wont show you if you closed (or not) the statement, or typos, BUT as stated above, it does have syntax highlighting and if you type it wrong, and in some cases, don’t format the statement properly, it will not “color” it right :blush:

1 Like

vim vim vim vim ... vimity vim wonderful vim...

Sung to the tune of the Spam Song by Monty Python

But seriously, neovim with plugins is an incredibly light and very portable full development environment that works in terminal.

2 Likes

Vim is honestly my last resort … it’s like the legacy thing that refuses to die and it has been around since the beginning of time.

To me Vim Vs nano is like windows notepad vs notepad++. Always there and good in a pinch. Reliable simple and last resort :blush:

Having said that, :wq

Relevant XKCD

3 Likes

It does indeed, thankyou I didn't realise these were there. I find the yellow and cyan tricky to see so will change those :slight_smile: I'm using nano for a calendar and todolist kind of setup, so it will be useful to be able to make my own syntax file for that. And here is a nano syntax repo.

I can peck my way around Vi and Vim for editing and saving, if that's all there is (and it's always there as you say), but never got on with Emacs. I think they work well if you have muscle memory for the flow of commands to operate it.

If you watch someone like IppSec on YouTube, he does all kinds of nifty stuff in Vi or Vim, such as decoding strings, replacing CRLF with CR and coding up short scripts on the fly.

You're right, I've noticed it do that especially if quotes are mismatched and so the next lines remains the same colour like it's carrying on. That helps see that the quotes or brackets were not closed properly. I guess a combination of good layout practice and highlighting goes a long way to finding mismatches.

If the editor isn't taking care of them, (like VSC and neovim), is it good practice to enter opening and closing brackets, quotes, braces, etc at the same time and then removing spaces / formatting as needed to tidy up, in order to ensure they all stay matched? Eg becomes more relevant if there is a load of nested stuff.

I tend to enter them as I go but I'm hardly doing anything complex compared to some of the code I've seen on the Pi-hole repos, so it's not hard to track down a mistake.

I'll stick with nano and play around with the syntax highlighting and best practices are for entering code and laying it out. And then when I want to step it up...

...just watched the intro video for that. It looks perfect since it's all there and working right there in the terminal where I want to experiment. Never heard of it so thanks for the tip-off!

1 Like

@chrislph

If you like nano, but wants brackets/quotes auto closing (and a few other features) you should try micro.

It is based on nano.
I only tested it for a few days sometime ago (I never really use it), but it seems to be nice. It has syntax highlighting, indentation support, plugins.

1 Like

Thanks for that suggestion. I've spent the last few hours using this and getting into the features and it's very nice. Current line highlighting and colour schemes are very useful. I think this will make a good upgrade to using nano.

To anyone else looking to explore it, install a current binary (currently 2.0.11) from the link given above, as the binaries fetched by Debian and Pi OS were older and did not have the newer wordwrap feature (softwrap wraps lines, wordwrap ensures whole words are wrapped).

I also found it useful to set the clipboard to internal and disable the mouse. That allows cutting and pasting in the document internally, and selecting, cutting and pasting via the mouse externally, which makes it behave like nano with its mouse setting disabled.

The dukelight-tc colour scheme is the one I settled on, looks great, easy to edit if any tweaks are needed.

For all the vim users I recommend these plugins for programming, scripting or just editing some files :slight_smile:

syntastic
vim-airline
vim-better-whitespace
vim-fugitive
vim-gitgutter
vim-gnupg
vim-shellcheck
vim-shfmt
vim-transparent