Coding with text file editors

VIM

VIM/Emacs and other text file editor, details and cheat sheets

Once you get to know the Linux operating system, something that becomes very clear is the need to be able to edit system configuration files along with shell command scripts and programming code in languages such as Python or C++.

As most of this blog is aim at hardware and software development systems such as the Raspberry pi and the cubbieboard, both ARM processor based single board computers, running distributions of Linux OS, I want to explain here which text file editors can be used to best work on these systems.

These details however will not only relate to single board computers, e.g. they would also match an infrastructure based in a Linux server environment and many other configurations.

When looking at the possible editors that are available to the Linux user it is a good idea to think about the environment that you will be using, i.e. Working with a single desktop installation such as Ubuntu 14.04 desktop or working in a networked environment with two or more desktop/server based systems linked by Wi-Fi or wired Ethernet.

Along with these two definitions you need to know if the system your logging in to will even have an ability to login using an attached mouse/keyboard and screen directly. Many cloud/internet server such as (DNS, SQL, NAME-databases and HTML etc…) operate in what is called a headless form, with out any human interface devices attached at all. They are configured and monitored remotely via desktop systems and applications. If you need to sign-in to these systems, then you do so using a secure connection method such as SSH or TELNET.

For example, when I am working with applications and coding on my development boards I have one Raspberry pi set-up with a screen and a keyboard/mouse and two running headless, as I can login to the other two using the installed TCP/IP connection services of SSH and use all the applications on them that I could possible need.

With SSH you get two possible connection options, to connect using the command line only mode, giving you access to text based applications only and secondly using a mode that gives you access to X-11 based GUI applications running in a graphical mode.

To do so you use SSH as follows

Text based Login : SSH User-name@xxx.xxx.xxx.xxx # ( User name and TCP/IP address )

X11 based login : SSH -X User-name@xxx.xxx.xxx.xxx

In both the above you are presented with a text based command line at login , however with the -X version you can call a GUI based application (e.g. firefox) from this command line.

So how does all this relate to text file editors, well there are two basic type of editors, ones that can be run in text mode only (VIM and EMACS) and ones that run in GUI mode only (GEDIT and NETBEANS-IDE).

If you look in the Linux repository by searching for “text editor”, you will find that there is a large selection to chose from, so I will list just a few here mainly the ones that I use a lot.

I mainly use two as follows :

Text based editors of : VIM, EMACS

GUI editors : GVIM and GEDIT

I will post some details on all of these editors in the future but here I just want to look at VIM and GVIM.

I always find myself using VIM and its GUI version (GVIM) for a very good and simple reason, because its a standard part of the Linux operating system. This is a very important detail – because it means that no matter which UNIX/LINUX computer you have to sign in to , its always there for you.

This is true for the text based version, if you would like to use the GUI version then you need to install one of the three possible packages.

vim-gtk 2:7.4.052-1ubuntu3
vim-athena 2:7.4.052-1ubuntu3
vim-gnome 2:7.4.052-1ubuntu3

I installed “vim-gnome”

The process of learning to use vim/gvim is not a simple one, gvim is a little simpler to learn as it includes the usual graphical menu system of a GUI application , so you need to know less keyboard commands. However I would truly recommend taking a little time to learn the text based version first and it command key combinations, it faster than using a mouse.

In the text based version you have three fundamental modes (View, insert and command), you mostly start in view mode and can return to it by pressing “esc”. In view mode you can used the keys “h,j,k,l” to move around the file, for editing the file you press keys such “r,i,a,o,i” falling into insert mode my doing so.

VIM cheat sheet @ http://vim.rtorr.com/

There is no shortage of web pages available that list all the possible modes for VIM/GVIM along with Printable cheat sheets (use google images “VIM cheat sheet”).

Vim contains a massive amount of features, many more than the editors basic front end would let you think, it can be used as a scripting application , letting you changes files in batch mode. Once fully learnt it can be used as a fully featured IDE for almost any coding language going.

When it is used for coding, it is used with configuration files designed for the language you are using, checking syntax along with auto indentation, auto completion, colours highlights and many many other coding features.

The one feature that I like the most when coding with VIM/GVIM this the available command line mode “! command”, which lets you save your code using the “:W path/codename.py” command and then call it using “:! python path/codename.py” or even compile code using, for example GCC’s ( ASS or GCC ) compiler options, then using the GCC debugger. All this while not having to exit the editor, so that you can if needed make changes , save and then compile/execute/debug again. Coding in Python is very fast as no compiler is needed.

Learn to fully use VIM and you will not regret it in anyway, its available on any Linux installation is powerful and once you know how to get around it very fast to use.

Advertisements
This entry was posted in Linux, Operating systems, Text Editors and IDE's and tagged , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s