Difference between revisions of "Unix Text Editors"
(2 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
\setlength{\parskip}{0.02in} | \setlength{\parskip}{0.02in} | ||
− | \title{ | + | \title{Choosing a Text Editor} |
− | \ | + | Any serious programmer needs a robust text editor to write program, and you (as aspiring scientists) |
− | \ | + | are going to need to be serious programmers. So you need to put some thought into |
− | + | choosing your editor. Here is a quick breakdown of your choices for a serious text editor: | |
− | \ | + | |
− | \ | + | \begin{itemize} |
+ | \item {\bf vi/vim} (gvim adds windows/tabs/mouse capability) | ||
+ | \begin{itemize} | ||
+ | \item free and installed by default on all unix (and OSX) systems | ||
+ | \item steep learning curve, but there will be vim experts nearby | ||
+ | \item arguably faster to control once you master it | ||
+ | \end{itemize} | ||
+ | \item {\bf emacs} | ||
+ | \begin{itemize} | ||
+ | \item free and installed by default on all unix (and OXS) systems | ||
+ | \item less steep learning curve, and there will likely be emacs experts nearby | ||
+ | \end{itemize} | ||
+ | \item {\bf Others}, including sublime, atom, ultraedit: | ||
+ | \begin{itemize} | ||
+ | \item you'll probably have to install these yourself, which can be annoying if you are working on a computer you don't own/control | ||
+ | \item you're on your own for learning | ||
+ | \end{itemize} | ||
+ | \end{itemize} | ||
+ | |||
+ | My suggestion is that you pick between vi/vim/gvim and emacs, at least to start. You should also be warned that people tend to be monogamous with their editors. You may end up using the editor you choose now for the rest of your life. For example, I picked vi in college and have never strayed. If you choose the red pill, go to the section on vi. If you choose the blue pill, go to the section on emacs. | ||
+ | |||
+ | \section{A Beginners Guide to Vi} | ||
+ | |||
+ | Vi is a text file editor in Unix environments. This includes our | ||
+ | lab which runs a flavor of Linux. You can use vi | ||
+ | to quickly edit a simple text file, as an editor for your Python source | ||
+ | code, or as a nice front end to typesetting documents in \LaTeX, the | ||
+ | required typesetting utility in this class. | ||
+ | |||
+ | \subsection{The Basics} | ||
+ | |||
+ | \subsubsection{Opening} | ||
+ | Most of the programs that you will be using on these systems will be | ||
+ | started from the command line. To begin a new document, simply | ||
+ | navagate (via the Unix command line) to the directory where you want | ||
+ | the file to be and type: | ||
+ | \begin{verbatim} | ||
+ | vim something.txt | ||
+ | \end{verbatim} | ||
+ | Where {\tt something.txt} is the new file that you wish to create, or | ||
+ | the old file that you wish to update. | ||
+ | |||
+ | Before we go any further, you need to know that vi has {\bf three} operating modes: COMMAND mode, INSERT mode, and VISUAL mode, which | ||
+ | are described in the table below. | ||
+ | |||
+ | \begin{table}[h] | ||
+ | \begin{center} | ||
+ | \begin{tabular}{|c|c|} \hline | ||
+ | COMMAND & the default mode vi starts in. Get here from other modes with ESC. \\ \hline | ||
+ | INSERT & what you type goes into the document. Get here from COMMAND mode with 'i'. \\ \hline | ||
+ | VISUAL & like command mode, but you can highlight text. Get here from COMMAND mode with 'v' or CTRL+'v'. \\ \hline | ||
+ | \end{tabular} | ||
+ | \end{center} | ||
+ | \caption{Vi Modes} | ||
+ | \end{table} | ||
+ | |||
+ | Now that you have vi open (in COMMAND mode), you can press 'i' to enter INSERT mode and type some text. In the next section we will save the file. | ||
+ | |||
+ | \subsubsection{Saving and Exiting} | ||
+ | To save a document, go to COMMAND mode (press ESC), then type ':w' to write the file under the name you opened it. If you would like to change the | ||
+ | name, you can write ':w newname.txt'. If you'd like to save and exit, replace ':w' with ':wq'. To just exit, type ':q'. If you've made changes to a file | ||
+ | and you don't want to save them, you will need to add an exclamation point to force vi to lose your changes: ':q!'. | ||
+ | In the | ||
+ | interest of simplifying your life, this document will concentrate on | ||
+ | the usage of keyboard shortcuts in using vi. | ||
+ | |||
+ | \subsubsection{Keyboard Shortcuts in COMMAND mode} | ||
+ | |||
+ | What makes vi powerful (with a steep learning curve) are the rich set of | ||
+ | keyboard shortcuts in COMMAND mode. We'll cover a few simple ones | ||
+ | here, but you should be aware that there is probably a command to accelerate | ||
+ | anything you find yourself doing, if you take the time to learn how. Guru-level | ||
+ | vi programmers pride themselves in almost never moving their hands away from the | ||
+ | keyboard to use a mouse or arrow keys. | ||
+ | |||
+ | Some basic COMMANDs: \\ | ||
+ | {\bf :open somefile.txt} - Open a file \\ | ||
+ | {\bf :w} - Save file \\ | ||
+ | {\bf :q} - Close vi\\ | ||
+ | |||
+ | {\bf i} - enter INSERT mode \\ | ||
+ | {\bf A} - move to end of line in INSERT mode \\ | ||
+ | {\bf I} - move to beginning of line in INSERT mode \\ | ||
+ | |||
+ | {\bf x} - delete character under cursor (put in buffer)\\ | ||
+ | {\bf dw} - delete word (put in buffer)\\ | ||
+ | {\bf dd} - delete line (put in buffer)\\ | ||
+ | {\bf p} - paste from buffer \\ | ||
+ | {\bf yy} - yank current line into paste buffer (without deleting) \\ | ||
+ | |||
+ | {\bf h},{\bf j},{\bf k},{\bf l} - move left, up, down, right, respectively \\ | ||
+ | {\bf b} - move back one word \\ | ||
+ | {\bf w} - move forward one word \\ | ||
+ | |||
+ | |||
+ | \subsection{\LaTeX Integration} | ||
+ | Vi has nice \LaTeX integration. If you start a file with the ending | ||
+ | \emph{.tex}, Vi will automatically load up in a mode to highlight | ||
+ | special characters and special modes to make life a little | ||
+ | easier. | ||
+ | |||
+ | \subsection{Python Integration} | ||
+ | |||
+ | Vi also has a nice mode for integrating with Python. For the purposes | ||
+ | of this lab, we will only need to use the highlighting features of | ||
+ | Vi. This checks to make sure that you have matching parentheses and will color | ||
+ | special keywords separately from other commands. | ||
+ | |||
+ | |||
+ | \section{A Beginners Guide to Emacs} | ||
− | |||
Emacs is a text file editor in Unix environments. This includes our | Emacs is a text file editor in Unix environments. This includes our | ||
− | lab which runs a | + | lab which runs a flavor of Linux. You can use emacs |
− | + | to quickly edit a simple text file, as an editor for your Python source | |
− | to quickly edit a simple text file, as an editor for your | ||
code, or as a nice front end to typesetting documents in \LaTeX, the | code, or as a nice front end to typesetting documents in \LaTeX, the | ||
required typesetting utility in this class. This document will outline | required typesetting utility in this class. This document will outline | ||
the basics of using emacs. | the basics of using emacs. | ||
− | \ | + | \subsection{The Basics} |
− | \ | + | \subsubsection{Opening} |
Most of the programs that you will be using on these systems will be | Most of the programs that you will be using on these systems will be | ||
started from the command line. To begin a new document, simply | started from the command line. To begin a new document, simply | ||
Line 62: | Line 169: | ||
TeX & LaTeX specific functions. Only appears when the filename you are | TeX & LaTeX specific functions. Only appears when the filename you are | ||
\\ & editing ends with \emph{.tex}.\\ \hline | \\ & editing ends with \emph{.tex}.\\ \hline | ||
− | + | Python specific functions. Only appears when you are | |
− | editing a filename\\ & that end with \emph{. | + | editing a filename\\ & that end with \emph{.py}\\ \hline |
Help & Emacs' extensive help and configuration area. \\ \hline | Help & Emacs' extensive help and configuration area. \\ \hline | ||
\end{tabular} | \end{tabular} | ||
Line 73: | Line 180: | ||
area. In the next section we will save the file. | area. In the next section we will save the file. | ||
− | \ | + | \subsubsection{Saving} |
In Emacs, saving a document is as simple as $\pi$. You can click on | In Emacs, saving a document is as simple as $\pi$. You can click on | ||
the \verb1Files1 menu, then click on \verb1Save Buffer...1 You can | the \verb1Files1 menu, then click on \verb1Save Buffer...1 You can | ||
also save by using the keyboard shortcut \verb1C-x C-s1. In the | also save by using the keyboard shortcut \verb1C-x C-s1. In the | ||
− | interest of | + | interest of simplifying your life, this document will concentrate on |
the usage of keyboard shortcuts in using emacs. | the usage of keyboard shortcuts in using emacs. | ||
− | \ | + | \subsubsection{Keyboard Shortcuts} |
Just about every aspect of emacs can be accessed and configured with | Just about every aspect of emacs can be accessed and configured with | ||
keyboard shortcuts. This means that to work on a document, you rarely | keyboard shortcuts. This means that to work on a document, you rarely | ||
Line 123: | Line 230: | ||
{\bf \verb1C-e1} - Move to the end of a line \\ | {\bf \verb1C-e1} - Move to the end of a line \\ | ||
− | \ | + | \subsubsection{Cutting, Pasting, and Navigation} |
In Emacs cutting and pasting is simple, yet slightly different from what | In Emacs cutting and pasting is simple, yet slightly different from what | ||
you may be used to. {\it To do it using keystrokes only}: | you may be used to. {\it To do it using keystrokes only}: | ||
Line 143: | Line 250: | ||
where you want to paste and click the middle mouse button. | where you want to paste and click the middle mouse button. | ||
− | \ | + | \subsection{\LaTeX Integration} |
Emacs has nice \LaTeX integration. If you start a file with the ending | Emacs has nice \LaTeX integration. If you start a file with the ending | ||
\emph{.tex}, Emacs will automatically load up in a mode to highlight | \emph{.tex}, Emacs will automatically load up in a mode to highlight | ||
Line 161: | Line 268: | ||
\end{table} | \end{table} | ||
− | \ | + | \subsection{Python Integration} |
− | Emacs also has a nice mode for integrating with | + | Emacs also has a nice mode for integrating with Python. For the purposes |
of this lab, we will only need to use the highlighting features of | of this lab, we will only need to use the highlighting features of | ||
− | Emacs. This checks to make sure that you have matching parentheses | + | Emacs. This checks to make sure that you have matching parentheses and will color |
− | + | special keywords separately from other commands. | |
− | special keywords separately from other commands. | ||
− | |||
− | |||
\end{document} | \end{document} | ||
</latex> | </latex> |
Latest revision as of 14:02, 13 January 2022
Short Topical Videos[edit]
Reference Material[edit]
- Basic vi commands (Colorado State University)
- VI cheat sheet
- GNU Emacs reference card
- Editor War (Wikipedia)
Choosing a Text Editor
Any serious programmer needs a robust text editor to write program, and you (as aspiring scientists) are going to need to be serious programmers. So you need to put some thought into choosing your editor. Here is a quick breakdown of your choices for a serious text editor:
- vi/vim (gvim adds windows/tabs/mouse capability)
- free and installed by default on all unix (and OSX) systems
- steep learning curve, but there will be vim experts nearby
- arguably faster to control once you master it
- emacs
- free and installed by default on all unix (and OXS) systems
- less steep learning curve, and there will likely be emacs experts nearby
- Others, including sublime, atom, ultraedit:
- you’ll probably have to install these yourself, which can be annoying if you are working on a computer you don’t own/control
- you’re on your own for learning
My suggestion is that you pick between vi/vim/gvim and emacs, at least to start. You should also be warned that people tend to be monogamous with their editors. You may end up using the editor you choose now for the rest of your life. For example, I picked vi in college and have never strayed. If you choose the red pill, go to the section on vi. If you choose the blue pill, go to the section on emacs.
A Beginners Guide to Vi
Vi is a text file editor in Unix environments. This includes our lab which runs a flavor of Linux. You can use vi to quickly edit a simple text file, as an editor for your Python source code, or as a nice front end to typesetting documents in LaTeX, the required typesetting utility in this class.
The Basics
Opening
Most of the programs that you will be using on these systems will be started from the command line. To begin a new document, simply navagate (via the Unix command line) to the directory where you want the file to be and type:
vim something.txt
Where something.txt is the new file that you wish to create, or the old file that you wish to update.
Before we go any further, you need to know that vi has three operating modes: COMMAND mode, INSERT mode, and VISUAL mode, which are described in the table below.
COMMAND |
the default mode vi starts in. Get here from other modes with ESC. |
INSERT |
what you type goes into the document. Get here from COMMAND mode with ’i’. |
VISUAL |
like command mode, but you can highlight text. Get here from COMMAND mode with ’v’ or CTRL+’v’. |
Now that you have vi open (in COMMAND mode), you can press ’i’ to enter INSERT mode and type some text. In the next section we will save the file.
Saving and Exiting
To save a document, go to COMMAND mode (press ESC), then type ’:w’ to write the file under the name you opened it. If you would like to change the name, you can write ’:w newname.txt’. If you’d like to save and exit, replace ’:w’ with ’:wq’. To just exit, type ’:q’. If you’ve made changes to a file and you don’t want to save them, you will need to add an exclamation point to force vi to lose your changes: ’:q!’. In the interest of simplifying your life, this document will concentrate on the usage of keyboard shortcuts in using vi.
Keyboard Shortcuts in COMMAND mode
What makes vi powerful (with a steep learning curve) are the rich set of keyboard shortcuts in COMMAND mode. We’ll cover a few simple ones here, but you should be aware that there is probably a command to accelerate anything you find yourself doing, if you take the time to learn how. Guru-level vi programmers pride themselves in almost never moving their hands away from the keyboard to use a mouse or arrow keys.
Some basic COMMANDs: \:open somefile.txt - Open a file \:w - Save file \:q - Close vi\
i - enter INSERT mode \A - move to end of line in INSERT mode \I - move to beginning of line in INSERT mode \
x - delete character under cursor (put in buffer)\dw - delete word (put in buffer)\dd - delete line (put in buffer)\p - paste from buffer \yy - yank current line into paste buffer (without deleting) \
h,j,k,l - move left, up, down, right, respectively \b - move back one word \w - move forward one word \
LaTeXIntegration
Vi has nice LaTeXintegration. If you start a file with the ending .tex, Vi will automatically load up in a mode to highlight special characters and special modes to make life a little easier.
Python Integration
Vi also has a nice mode for integrating with Python. For the purposes of this lab, we will only need to use the highlighting features of Vi. This checks to make sure that you have matching parentheses and will color special keywords separately from other commands.
A Beginners Guide to Emacs
Emacs is a text file editor in Unix environments. This includes our lab which runs a flavor of Linux. You can use emacs to quickly edit a simple text file, as an editor for your Python source code, or as a nice front end to typesetting documents in LaTeX, the required typesetting utility in this class. This document will outline the basics of using emacs.
The Basics
Opening
Most of the programs that you will be using on these systems will be started from the command line. To begin a new document, simply navagate (via the Unix command line) to the directory where you want the file to be and type:
emacs something.txt &
Where something.txt is the new file that you wish to create, or the old file that you wish to update. After a few moments, a new window will popup with a blank screen that you can type into. You can use the mouse to navigate the menus at the top. See table 1 for information on what the different menu options do.
Buffers |
Contains information about the currently open files in this instance of |
Emacs. | |
Files |
Contains basic commands for opening, saving, and closing files. |
Tools |
Contains advanced functions for doing things like version control. |
Edit |
Contains cut, paste, and spell checking capabilities of emacs. |
Search |
Contains search and replace functions. |
Mule |
Advanced editing functions. |
TeX |
LaTeX specific functions. Only appears when the filename you are |
editing ends with .tex. | |
Python specific functions. Only appears when you are editing a filename | |
that end with .py | |
Help |
Emacs’ extensive help and configuration area. |
Now that you have emacs open you can type something in the text area. In the next section we will save the file.
Saving
In Emacs, saving a document is as simple as . You can click on the Files menu, then click on Save Buffer... You can also save by using the keyboard shortcut C-x C-s. In the interest of simplifying your life, this document will concentrate on the usage of keyboard shortcuts in using emacs.
Keyboard Shortcuts
Just about every aspect of emacs can be accessed and configured with keyboard shortcuts. This means that to work on a document, you rarely need to move your hands away from the keyboard and use the mouse. This increases productivity, and just makes things easier. All the keyboard shortcuts that I mention in this document will be summarized at the end.
All keyboard shortcuts are represented in a format like C-x C-f. When you see a -, that means you hold the key that comes before and after the - down at the same time. The capitol C however, does not correspond to the letter c, but rather the control button (abbreviated CTRL) on the keyboard. So, if you see C-x C-f, that means press and hold the CTRL button, then press the x key, then press the f key, then release the CTRL button. If you see something of the form C-x d, then that means to press and hold the CTRL button, press x, release CTRL, then press d. I think you get the picture. Similarly, M represents the ALT button.
In some of the menus, you will see keyboard shortcuts that are labelled as M-%.
On the Sun workstations that corresponds to the , and works identically to the CTRL key. On non-Sun workstations this key is simulated by pressing ESC then CTRL-whatever.
Some basic keystroke Shortcuts: \C-x C-f - Open a file \C-x C-s - Save file \C-x C-c - Close Emacs\
C-space - Start Selection \C-w - Cut ("kill") selection \M-w - Copy selection \C-y - Paste ("yank") selection \C-k - Kill a line \
C-x C-2 - Split window horizontally \C-x C-3 - Split window vertically \
C-a - Move to the beginning of a line \C-e - Move to the end of a line \
In Emacs cutting and pasting is simple, yet slightly different from what you may be used to. To do it using keystrokes only:
- Select and cut the block of text by
- moving the cursor to its beginning, type C-spacebar.
- using the arrow keys, move the cursor to its end abd type C-k.
- Paste the block by
- moving the cursor to where you want to paste
- type C-y .
To do it using the mouse: Select the text with your mouse and the double right click in the selection. To paste, move the cursor to where you want to paste and click the middle mouse button.
LaTeXIntegration
Emacs has nice LaTeXintegration. If you start a file with the ending .tex, Emacs will automatically load up in a mode to highlight special characters and special modes to make life a little easier. Emacs also has a couple modes to automatically compile LaTeXfiles and display the result in xdvi (refer to the LaTeXhandout if none of this makes sense to you. Below are the basic LaTeXshortcuts.
Compile LaTeXfile |
C-c C-f |
View file in xdvi |
C-c C-v |
Python Integration
Emacs also has a nice mode for integrating with Python. For the purposes of this lab, we will only need to use the highlighting features of Emacs. This checks to make sure that you have matching parentheses and will color special keywords separately from other commands.