|
|
|
|
|
|
|
Text Editors, scp, dos2unix, unix2dos
|
|
|
|
Before we get to the really cool stuff, let's tackle some gnarly stuff in more detail: the text editors.
Writing code in notepad:
It is perfectly acceptable to write code in Notepad (notepad.exe on Windows) and port it using ssh (or rather, secure ftp) to Linux. The main difficulty in porting a plain text file from Windows to Linux is that the Operating Systems handle "new lines" differently. Windows uses "carriage return, line feed" and Linux uses only "line feed". If you are wondering about the terminology, it has nothing to do with horse-drawn carts or soup kitchens; but with an ancient piece of obsolete technology called a "typewriter".
What happens to the "carriage return" that Linux doesn't use? It becomes a "non-printing character" known as "hat-em" that is: ^M. Sometimes it trips up compilers.
To eliminate "hat-em" from text files that you port from Windows, use a command called "dos to unix" dos2unix like so:
dos2unix file_created_on_windows
or sometimes
dos2unix file_created_on_windows > converted_file
This also works the other way for files that have been written on the Linux platform that will need to be ported to Windows. For that you can use the "unix to dos" unix2dos command. This will put the "carriage returns" back into the file so that the text will no longer be all on one line. Note that unix2dos makes the changes to the original file:
unix2dos file_created_on_Linux
And, if you happen to be on Macintosh, you can move files back and forth using scp (initiate command from the Macintosh side):
from Mac to LinuxLab:
scp -o User=username filename uw1-320-lab.uwb.edu:/home2/username/ or
scp filename username@uw1-320-lab.uwb.edu:/home2/username/
from LinuxLab to Mac:
scp -o User=username uw1-320-lab.uwb.edu:/home2/username/file . or
scp username@uw1-320-lab.uwb.edu:/home2/username/file .
What about text editors that are installed on Linux?
Like many Linux solutions, there are several different answers that will work, each has advantages and disadvantages. Different choices appeal to different kinds of typers and coders. Hopefully, you will find one that works for you.
vi <filename> pronounced "vee eye". Visual Editor, now the improved version called "vim"
vim <filename> pronounced "vim". Improved Visual Editor
The advantage to vi and vim is that they are installed by default on every distro of Linux and Unix that you will ever encounter. vi and vim are also both extremely fast and extremely powerful - once you have learned how to use them. The disadvantage is that learning how to use them can be difficult because they are "bimodal text editors" and therefore very different from all other text editors and word processing programs. Most people who learn and enjoy using vim, don't learn it when they are under deadline pressure to complete homework that is not directly related to learning vim. It is NOT true that if you start off with pico or emacs now that you will "never learn vi". If you continue to use Linux and decide to use vim in the future, you will be able to learn vim.
If you want to learn vim, type vimtutor on the command line with no file name after it and you will bring up the tutorial. Switch back and forth between modes by pressing the escape key or any "insert" key such as i, a, I, or A. Eventhough the tutorial will tell you to move around the document using the letters h,j,k, and l, on our (and most) Linux distros, the arrow keys work just as well (or can be made to work just as well).
Here is another tutorial:
http://staff.washington.edu/rells/R110
Vim will work fine in an ssh terminal and in an environment that doesn't have a GUI (no XWindows).
emacs <filename> pronounced "ee-max".
Emacs is the second most common text editor on the Linux platform. Almost every Linux computer you will ever encounter will have emacs installed. Emacs was one of the first projects of Richard Stallman, founder of the GNU (G is Not Unix - a self-referencial acronym) project and the Free Software Foundation and opinionated nut and genius.
Emacs text editing is characterized by two-key (or more) commands. Most of the commands in emacs are accessed either with the Ctrl key plus another key or with the "Meta" key plus another key. Depending on how your keyboard is mapped, the "Meta" key can be either the Alt key or another key, special to your OS or keyboard. Emacs also has pull-down menus for people who aren't ready to switch to all-keyboard typing.
If you want to learn emacs, open an emacs session by typing emacs at the command prompt, then use the pull-down Help menu and select "Emacs Tutorial". Inside an emacs session, the emacs tutorial can also be reached by typing "Ctrl-h f" (that is, the Ctrl and h key pressed at the same time, then released and the f key pressed immediately afterwards).
In an ssh terminal or in a NON-GUI environment (without XWindows), the keyboard commands will still be available in emacs, but the pull-down menus will not.
pico <filename> pronounced "pee-koe"
nano <filename> pronounced "nah-no"
Pico was developed by the distinguished University of Washington. When the University of Washington decided not to continue supporting pico, Richard Stallman created a GNU version of pico called nano
Pine (the email client also developed by the University of Washington) is written in pico. If you have used pine as an email client, you are already familiar with pico.
Both pico and nano are install on the workstations in the LinuxLab. Pico was the first text editor written for Linux (Unix) with command help at the bottom of the text screen. The commands are accessed by using the Alt key (and sometimes the Ctrl key) in combination with a (case insensitive) letter key. The most tricky part of pico is remembering that "WriteOut" means "Save".
Pico is the slowest but perhaps the easiest of the original text editors that are still commonly available on most Linux distros. It is simple enough that it doesn't require a tutorial and everything you need to know about using pico (nano) is inside the editor itself or accessible by typing man nano at the command line.
Nano and pico will work fine in an ssh terminal and in an environment that doesn't have a GUI (no XWindows).
gedit <filename>: pronounced "gee-edit". Gnu editor
Of all the text editors installed in the LinuxLab, gedit is the one that is most like Notepad. It is the official editor of the Gnome desktop environment. Therefore, if you have a Gnome desktop installed on your Linux computer, you will find gedit.
Gedit may not work in an ssh terminal as it does not work without a GUI.
Linux help is available through linhelp@uwb.edu and
The uwb_linux email list:
https://mailman1.u.washington.edu/mailman/listinfo/uwb_linux
|
|
|
created: April 30, 2008
updated: March 20, 2009
|
|
|