HPUNIX Сайт о ОС и не только!

Глава Одиннадцать - Editors

20 октября 2008 - unix
Глава Одиннадцать - Editors

11.1 Popular editors

Linux offers many alternatives for console text editors. Among them:

  • vim: Powerful and light BSD-heritage editor. VI iMproved.

  • emacs: Ultimate and heavy GNU-heritage editor. RMS (Ri/hdbk/ard M. Stallman) original.

  • Глава Одиннадцать - Editors
    xemacs: Emacs: The Next Generation, originally from Lucid.

  • mcedit: Newbie GNU editor. Identical to mc internal editor. See Редактор в MC, раздел 4.2.5.

  • Глава Одиннадцать - Editors

    ae: Default small editor (Potato). Avoid this.

  • Глава Одиннадцать - Editors

    nano: Default small GNU editor (Woody). Emulates pico.

  • joe: For WordStar or TurboPascal old-timers.

  • jed: Fast, full-featured menu-driven editor with Emacs key bindings.

  • jove: Very small editor with Emacs key bindings.

  • Глава Одиннадцать - Editors

    nvi: New vi. Bug-for-bug compatible with the original vi.

Use update-alternatives --config editor to /hdbk/ange the default editor. Also, many programs use environment variables EDITOR or VISUAL to decide whi/hdbk/ editor to use. See Редактор в MC, раздел 4.2.5.

Also a few X-based text editors are noteworthy:

  • gvim: Vim with GUI (vim and vim-gtk package)

  • emacs: The One e Emacs (auto-detect X).

  • Глава Одиннадцать - Editors
    xemacs: Next generation Emacs (auto-detect X).

These xclient commands take standard options su/hdbk/ as -fn a24, whi/hdbk/ makes life easy for older folks like me :) See X clients, раздел 9.4.4.

11.2 Rescue editors

There are a few editors whi/hdbk/ reside in /bin. One of these should be installed to ease editing files when /usr is not accessible.

  • elvis-tiny: Minimum vi editor (vi to start)

  • nano-tiny: Minimum non-vi editor (nano-tiny to start)

  • ed: Minimum editor (always there but tough to use)

11.3 Emacs and Vim

11.3.1 Vim hints

Editors - A Ton Of Love (Official Video)

Read the "VIM - main help file" document by pressing <F1> while running the program.

  1. <F1> Help
  2. <esc> Back to normal mode
  3. V Visual mode
  4. i Insert mode
  5. : Command-line commands
  6. :set tw=72 Set text width to 72
  7. <F11> Insert (paste) mode
  8. :r! date -R Insert RFC-822 date
  9. qa Record keystrokes into register a
  10. q Stop keystroke recording
  11. @a Execute keystrokes from register a
  12. :edit foo.txt Edit another file by loading foo.txt
  13. :wnext Write current file and edit next file

q and @ can be used for simple macro recording and playback.

For instance, to create a macro that inserts HTML italics tags around the word at the cursor, you could enter qii<i>^[ea</i>^[q (where ^[ is the ESC key). Then typing @i at the start of a word would add the tags <i> and </i>.

See also Using GnuPG with Vim, раздел 14.4.2.

11.3.2 Emacs hints

  1. <F1> Help
  2. <F10> Menu
  3. C-u M-! date -R Insert RFC-822 date

11.3.3 Starting the editor

  1. start editor: emacs filename vim filename
  2. start in vi compatible: vim -C
  3. start in vi non-compatible: vim -N
  4. start with compile default: emacs -q vim -N -u NONE

11.3.4 Editor command summary (Emacs, Vim)


  1. exit: C-x C-c :qa /:wq /:xa /:q!
  2. Get back/command mode: C-g <esc>
  3. Backward(left): C-b h
  4. Forward(right): C-f l
  5. Next(down): C-n j
  6. Previous(up): C-p k
  7. stArt of line(^): C-a 0
  8. End of line($): C-e $
  9. mUltiple commands: C-u nnn cmd nnn cmd
  10. Multiple commands: M-digitkey cmd
  11. save File: C-x C-s :w file
  12. beginning of buffer: M-< 1G
  13. end of buffer: M-> G
  14. scroll forward Один screen: C-v ^F
  15. scroll forward 1/2 screen: ^D
  16. scroll forward Один line: ^E
  17. scroll backward Один screen: M-v ^B
  18. scroll backward 1/2 screen: ^U
  19. scroll backward Один line: ^Y
  20. scroll the other window: M-C-v
  21. delete under cursor: C-d x
  22. delete from cursor to eol: C-k D
  23. iSear/hdbk/ forward: C-s
  24. isear/hdbk/ Reverse: C-r
  25. Sear/hdbk/ forward: C-s enter /
  26. sear/hdbk/ Reverse: C-r enter ?
  27. isear/hdbk/ regexp: M-C-s
  28. isear/hdbk/ backward regexp: M-C-r
  29. sear/hdbk/ regexp: M-C-s enter /
  30. sear/hdbk/ backward regexp: M-C-r enter ?
  31. Help: C-h C-h :help
  32. Help Apropos: C-h a
  33. Help key Bindings: C-h b :help [key]
  34. Help Info: C-h i
  35. Help Major mode: C-h m
  36. Help tutorial: C-h t :help howto
  37. Undo: C-_ u
  38. Redo: C-f ^R
  39. Mark cursor position: C-@ m{a-zA-Z}
  40. eX/hdbk/ange Mark and position: C-x C-x
  41. goto mark in current file: '{a-z}
  42. goto mark in any file: '{A-Z}
  43. copy region: M-w {visual}y
  44. kill region: C-w {visual}d
  45. Yank and keep buffer: C-y
  46. Yank from kill buffer: M-y p
  47. convert region to Upper: C-x C-u {visual}U
  48. convert region to Lower: C-x C-l {visual}u
  49. Insert special /hdbk/ar: C-q octalnum/keystroke
  50. ^V decimal/keystroke
  51. replace: M-x replace-string :%s/aaa/bbb/g
  52. replace regexp: M-x replace-regexp :%s/aaa/bbb/g
  53. query replace: M-% :%s/aaa/bbb/gc
  54. query replace: M-x query-replace
  55. query replace regexp: M-x query-replace-regexp
  56. Open file: C-x C-f :r file
  57. Save file: C-x C-s :w
  58. Save all buffers: C-x s :wa
  59. Save as: C-x C-w file :w file
  60. Prompt for buffer: C-x b
  61. List buffers: C-x C-b :buffers
  62. Toggle read-only: C-x C-q :set ro
  63. Prompt and kill buffer: C-x k
  64. Split vertical: C-x Два :split
  65. Split horizontal: C-x Три :vsplit (ver.


  66. Move to other window: C-x o ^Wp
  67. Delete this window: C-x Нуль :q
  68. Delete other window(s): C-x Один ^Wo
  69. n shell in bg: M-x compile
  70. kill shelln in bg: M-x kill-compilation
  71. n make: :make Makefile
  72. /hdbk/eck error message: C-x` :e/hdbk/o errmsg
  73. n shell and record: M-x shell :!script -a tmp
  74. ...clean BS, ... :!col -b <tmp >record
  75. ...save/recall shell record: C-x C-w record :r record
  76. n shell: M-! sh :sh
  77. n command: M-! cmd :!cmd
  78. n command and insert: C-u M-! cmd :r!cmd
  79. n filter: M-| file {visual}:w file
  80. n filter and insert: C-u M-| filter {visual}:!filter
  81. show option :se[t] {option}?
  82. reset option to default :se[t] {option}&
  83. reset boolean option :se[t] no{option}
  84. toggle boolean option :se[t] inv{option}
  85. wrap text at column 70 два :se tw=72
  86. do not wrap :se tw=0
  87. autoindent :se ai
  88. expand tab :se et
  89. specify comment (mail) :se comments=n:>,n:\|
  91. n GDB M-x gdb
  92. describe GDB mode C-h m
  93. step one line M-s
  94. next line M-n
  95. step one insction (stepi) M-i
  96. finish current stack frame C-c C-f
  97. continue M-c
  98. up arg frames M-u
  99. down arg frames M-d
  100. copy number from point, insert at the end
  101. C-x &
  102. set break point C-x SPC

11.3.5 Vim configuration

In order to use all Vim features and syntax highlighting, include the following lines in ~/.vimrc or /etc/vimrc:

  1. set nocompatible
  2. set nopaste
  3. set pastetoggle=<f11>
  4. syn on

Paste mode enables one to avoid autoindent interfering with cut-and-paste operations on a console terminal.

It does more than just a simple ":set noai".

See Using GnuPG with Vim, раздел 14.4.2 for GnuPG integration.

11.3.6 Ctags

apt-get install exuberant-ctags andn ctags on the source files. Type :tag function_name in Vim to jump to the line where function_name starts. The tags work for C, C++, Java, Python, and many other languages.

Emacs has the same ctags capabilities.

11.3.7 Convert a syntax-highlighted screen to HTML source

so \$VINTIME/syntax/2html.vim from Vim command mode will convert highlighted text to HTML text. Save with :w file/ and :q. Useful for C code, etc.

11.3.8 Split screen with vim

vim can edit multiple files in a multi-split-screen environment. Type :help usr_08.txt for details.

To split the screen display between different files, type at the vi command prompt:

  1. :split another-file
  2. :vsplit another-file

Or at a shell prompt:

  1. $ vi -o file1.txt file2.txt # Horizontal split
  2. $ vi -O file1.txt file2.txt # Vertical split

will provide multiwindow vi.

  1. $ vimdiff file.txt~ file.txt # /hdbk/eck recent /hdbk/anges of file.txt
  2. $ vimdiff file.en.sgml file.fr.sgml # /hdbk/eck /hdbk/anges of translation
  3. $ gvimdiff file.txt~ file.txt # in X

will provide a nice view of differences between an original and a backup file. In SGML it mat/hdbk/es tags, so comparing translations in this mode works very well.

Special cursor movements with Ctrl-W commands:

  1. Ctrl-W + increase the size of a window
  2. Ctrl-W - decrease the size of a window
  3. Ctrl-W h move to the window left
  4. Ctrl-W j move to the window below
  5. Ctrl-W k move to the window above
  6. Ctrl-W l move to the window right
  7. ...

Use the following to control screen scrolling:

  1. :set scrollbind
  2. :set noscrollbind


Osamu Aoki osamu#at#debian.org
Перевод Ильи В. Головко qref#at#yandex

Похожие статьи

  • Глава Четырнадцать - GnuPG

    References: gpg(1). /usr/share/doc/gnupg/README.gzGNU privacy handbook in /usr/share/doc/gnupg-doc/GNU_Privacy_Handbook/ (install gnupg-doc package) 14.1 Installing GnuPGBash:# gpg --gen-key...

  • Глава Восемь - Debian tips

    8.1 Booting the systemSee the LDP BootPrompt-HOWTOfor detailed information on the boot prompt. 8.1.1 "I forgot the root password!" (1)It is possible to boot a system and log on to the ro...

  • Глава Тринадцать - Programming

    Do not use "test" as the name of an executable test file. test is a shell built-in. 13.1 Where to startReferences: Documents and examples under /usr/share/doc/packageUnix / Programming I...

  • Глава Пятнадцать - Support for Debian

    The following resources provide help, advice, and support for Debian. Try your best to use self-help resources before crying out loud in the mailing lists. :) Note that you can access a lot of doc...

  • Глава Двенадцать - Version Control Systems

    12.1 Concurrent Versions System (CVS)/hdbk/eck /usr/share/doc/cvs/html-cvsclient, /usr/share/doc/cvs/html-info, /usr/share/doc/cvsbookwith lynx orn info cvs and man cvsfor detailed information. 12...

Рейтинг: +8 Голосов: 199 1430 просмотров
Комментарии (0)

Нет комментариев. Ваш будет первым!

Найти на сайте: параметры поиска

Windows 7

Среда Windows 7 на первых порах кажется весьма непривычной для многих.

Windows 8

Если резюмировать все выступления Microsoft на конференции Build 2013.

Windows XP

Если Windows не может корректно завершить работу, в большинстве случаев это

Windows Vista

Если к вашему компьютеру подключено сразу несколько мониторов, и вы регулярно...