📄 editors.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head> <title></title> <link rel="stylesheet" media="screen" type="text/css" href="./style.css" /> <link rel="stylesheet" media="screen" type="text/css" href="./design.css" /> <link rel="stylesheet" media="print" type="text/css" href="./print.css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><a href=start.html>start</a></br><div class="toc"><div class="tocheader toctoggle" id="toc__header">Table of Contents</div><div id="toc__inside"><ul class="toc"><li class="clear"><ul class="toc"><li class="level2"><div class="li"><span class="li"><a href="#editors" class="toc">Editors</a></span></div><ul class="toc"><li class="level3"><div class="li"><span class="li"><a href="#popular_editors" class="toc">Popular Editors</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#editing_a_file_in_vim" class="toc">Editing a file in vim</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#saving_the_file_and_or_quiting_vim" class="toc">Saving the file and/or quiting vim</a></span></div></li></ul></li></ul></li></ul></div></div><h2><a name="editors" id="editors">Editors</a></h2><div class="level2"></div><!-- SECTION [1-18] --><h3><a name="popular_editors" id="popular_editors">Popular Editors</a></h3><div class="level3"><p>Since we’ll be programming, we need a text editor. There are many available with Linux and programmers become emotionally attached to their preferred editors. </p><p>However, the one editor that will always be available is vi. In particular, if an embedded Linux has an editor, it is most likely vi. For example, uClinux provides vi. Consequently, we’ll give a quick overview of vi, with no insistence that it is the best editor, merely that it is omnipresent. The references at the end of this chapter give more thorough expositions. Also note that GNU version of vi (called vim, but will answer to vi) provides a tutorial. Further, it will operate in what you might consider to be a more friendly fashion than classic vi. If vim is available on your system with its documentation, you can run the tutorial by entering:</p><pre class="code">cd /usr/doc/vim-common-5.6/tutorvi tutor</pre><p> where the version number (5.6) may be different on your system. If you haven’t encountered a modal editor before, vi will seem strange at first (maybe later on, too). It provides three modes of which we’ll discuss only the first two: </p><ul><li class="level1"><div class="li">command mode</div></li><li class="level1"><div class="li">insert mode</div></li></ul><p>Upon startup, vi is in command mode. Our approach here will be demonstrate how to edit a file, save it, close it, and then reopen it for subsequent editing. We will not explore vi in any depth.</p></div><!-- SECTION [19-1387] --><h3><a name="editing_a_file_in_vim" id="editing_a_file_in_vim">Editing a file in vim</a></h3><div class="level3"><p>To edit a file (let’s say hello.c), invoke vi at the command line as follows: vi hello.c If the file does not yet exist, this will allow you to create, edit, and then save the file with this name. If the file does already exist, it will be opened for editing with vi. As mentioned earlier, vi wakes up in command mode, but we want to enter text and to do so we enter a command which puts us into insert mode where we can enter text. The command is simply to press the i (for insert) key. You can now enter text. The vim implementation allows you to delete characters with the backspace key and navigate with the arrow keys while in insert mode. Classic vi is less friendly, requiring that you return to command mode for character deletion and navigation - so the insert mode is for text insertion only. To return to command mode press the Esc key. To then navigate in classic vi, one uses these keys to move the cursor: </p><ul><li class="level1"><div class="li"><code>h </code> moves cursor left</div></li><li class="level1"><div class="li"><code>j </code> moves cursor down</div></li><li class="level1"><div class="li"><code>k</code> moves cursor up</div></li><li class="level1"><div class="li"><code>l </code> moves cursor right</div></li></ul><p>For text deletion in classic vi, we have these keys: </p><ul><li class="level1"><div class="li"><code>x </code> deletes the character under the cursor</div></li><li class="level1"><div class="li"><code>dw</code><code> </code> deletes the word the cursor is on</div></li><li class="level1"><div class="li"><code>dd</code><code> </code> deletes the line the cursor is on</div></li></ul><p>Note that vim can perform its deletion and navigation tasks in the classic fashion as well as in its more contemporary style. The upshot is that editing with vim can be done remaining in insert mode; whereas editing with classic vi requires constant moving back and forth between command and insert modes. The current uClinux comes with the classic vi. Your Linux workstation likely has a variety of editors and the implementation of vi is probably vim, but if you’re not a vi devotee you’ll possibly prefer a different editor. However, vi is much more powerful (many more commands etc.) than our terse description suggests.</p><p>Other editors, each with its own following, include </p><ul><li class="level1"><div class="li"> emacs - present in typical Linux distributions (really more than an editor)</div></li><li class="level1"><div class="li"><a href="http://www.nedit.org" class="urlextern" title="http://www.nedit.org" rel="nofollow">nedit</a></div></li><li class="level1"><div class="li"><a href="ftp://ftp.ibiblio.org/pub/Linux/apps/editors/X/cooledit" class="urlextern" title="ftp://ftp.ibiblio.org/pub/Linux/apps/editors/X/cooledit" rel="nofollow">cooledit</a></div></li></ul><p>plus many more. We’ll later see that you can do virtually all of your editing tasks on the Linux workstation because your working directory can be nfs mounted on the target uClinux file system hierarchy. Nevertheless, there might be an instance where the classic vi on uClinux is what you need.</p></div><!-- SECTION [1388-3822] --><h3><a name="saving_the_file_and_or_quiting_vim" id="saving_the_file_and_or_quiting_vim">Saving the file and/or quiting vim</a></h3><div class="level3"><p>Remember: </p><ul><li class="level1"><div class="li">when in command mode, you enter insert mode by pressing the i key</div></li><li class="level1"><div class="li">when in insert mode, you enter command mode by pressing the Esc key</div></li></ul><p>Saving and quitting require that vi be in command mode. Each of these commands begins with a colon. Here are the possibilities:</p><p><code>:q</code> quit vi, but only if the file is unmodified - the file will not be saved by this command</p><p><code>:q!</code> quit vi whether or not the file is modified - the file will not be saved by this command</p><p><code>:w</code> save the file, but not quit vi</p><p><code>:wq</code> saves the file and quits vi</p></div><!-- SECTION [3823-] --></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -