home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vim45os2.zip / vim-4.5 / doc / vim_tips.txt < prev    next >
Text File  |  1996-10-07  |  12KB  |  328 lines

  1. *vim_tips.txt*  For Vim version 4.5.  Last modification: 1996 Aug 30
  2.  
  3. Contents:
  4.  
  5. Editing C programs                    |C-editing|
  6. Editing local HTML files (WWW)                |html-editing|
  7. Editing paragraphs without a line break            |edit-no-break|
  8. Switching screens in an xterm                |xterm-screens|
  9. Scrolling in Insert mode                |scroll-insert|
  10. Smooth scrolling                    |scroll-smooth|
  11. Correcting common typing mistakes            |type-mistakes|
  12. Renaming files                        |rename-files|
  13. Speeding up external commands                |speed-up|
  14. Useful mappings                        |useful-mappings|
  15. Compressing the help files                |gzip-helpfile|
  16. Executing shell commands in a window            |shell_window|
  17. Pseudo-Ex mode                        |pseudo-Q|
  18. Using <> notation in autocommands            |autocmd-<>|
  19.  
  20.  
  21. Editing C programs                    *C-editing*
  22. ==================
  23.  
  24. There are quite a few features in Vim to help you edit C program files.  Here
  25. is an overview with tags to jump to:
  26.  
  27. |C_indenting|        Automatically set the indent of line while typing
  28.             text.
  29. |=|            Re-indent a few lines.
  30. |format_comments|    Format comments.
  31.  
  32. |:checkpath|        Show all recursively included files.
  33. |[i|            Search for identifier under cursor in current and
  34.             included files.
  35. |[_CTRL-I|        Jump to match for "[i"
  36. |[I|            List all lines in current and included files where
  37.             identifier under the cursor matches.
  38. |[d|            Search for define under cursor in current and included
  39.             files.
  40.  
  41. |CTRL-]|        Jump to tag under cursor.
  42. |CTRL-T|        Jump back from tag.
  43.  
  44. |gd|            Go to Declaration of local variable under cursor.
  45. |gD|            Go to Declaration of global variable under cursor.
  46.  
  47. |gf|            Go to file name under the cursor.
  48.  
  49. |%|            Go to matching (), {}, [], /* */, #if, #else, #endif.
  50. |[/|            Go to previous start of comment.
  51. |]/|            Go to next end of comment.
  52. |[#|            Go back to unclosed #if, #ifdef, or #else.
  53. |]#|            Go forward to unclosed #else or #endif.
  54. |[(|            Go back to unclosed '('
  55. |])|            Go forward to unclosed ')'
  56. |[{|            Go back to unclosed '{'
  57. |]}|            Go forward to unclosed '}'
  58.  
  59. |v_S|            Select current block from "[(" to "])"
  60. |v_P|            Select current block from "[{" to "]}"
  61.  
  62.  
  63. Editing local HTML files (WWW)                *html-editing*
  64. ==============================
  65.  
  66. Vim has some features which can help simplify the creation and maintenance of
  67. HTML files, provided that the files you are editing are available on the local
  68. file system.  The "]f", "gf" and "CTRL-W f" commands can be used to jump to
  69. the file whose name appears under the cursor, thus not only checking that the
  70. link is valid (at least the file name part of the URL) but also providing a
  71. quick and easy way to edit many related HTML pages at once.  |gf|
  72. A set of macros to help with editing html can be found on the Vim pages. |www|
  73.  
  74.  
  75. Editing paragraphs without a line break            *edit-no-break*
  76. =======================================
  77.  
  78. If you are typing text in Vim that will later go to a word processor, it is
  79. useful to keep a paragraph as a single line.  To make this more easy:
  80. - set 'wrap' on, to make lines wrap                |'wrap'|
  81. - set 'linebreak' on, to make wrapping happen at a blank    |'linebreak'|
  82. - use "gk" and "gj" to move one screen line up or down        |gj|
  83.  
  84.  
  85. Switching screens in an xterm                *xterm-screens*
  86. =============================
  87.  
  88. (From comp.editors, by Juergen Weigert, in reply to a question)
  89.  
  90. >> Another question is that after exiting vim, the screen is left as it
  91. >> was, i.e. the contents of the file I was viewing (editting) was left on
  92. >> the screen. The output from my previous like "ls" were lost,
  93. >> ie. no longer in the scrolling buffer. I know that there is a way to
  94. >> restore the screen after exiting vim or other vi like editors,
  95. >> I just don't know how. Helps are appreciated. Thanks.
  96.  
  97. >I imagine someone else can answer this.  I assume though that vim and vi do
  98. >the same thing as each other for a given xterm setup.
  99.  
  100. They not necessarily do the same thing, as this may be a termcap vs.
  101. terminfo problem. You should be aware that there are two databases for
  102. describing attributes of a particular type of terminal: termcap and
  103. terminfo. This can cause differences when the entries differ *and* when of
  104. the programs in question one uses terminfo and the other uses termcap.
  105.  
  106. In your particular problem, you are looking for the control sequences
  107. ^[[?47h and ^[[?47l. These switch between xterms alternate and main screen
  108. buffer. As a quick workaround a command sequence like
  109.     echo -n "^[[?47h"; vim ... ; echo -n "^[[?47l"
  110. may do what you want. (My notation ^[ means the ESC character, further down
  111. you'll see that the databases use \E instead).
  112.  
  113. On startup, vim echoes the value of the termcap variable ti (terminfo:
  114. smcup) to the terminal. When exiting, it echoes te (terminfo: rmcup). Thus
  115. these two variables are the correct place where the above mentioned control
  116. sequences should go.
  117.  
  118. Compare your xterm termcap entry (found in /etc/termcap) with your xterm
  119. terminfo entry (retrieved with /usr/5bin/infocmp -C xterm). Both should
  120. contain entries similar to:
  121.     :te=\E[2J\E[?47l\E8:ti=\E7\E[?47h:
  122.  
  123. PS: If you find any difference, someone (your sysadmin?) should better check
  124.     the complete termcap and terminfo database for consistency.
  125.  
  126. NOTE: If you recompile Vim with SAVE_XTERM_SCREEN defined in feature.h, the
  127. builtin xterm will include the mentioned "te" and "ti" entries.
  128.  
  129.  
  130. Scrolling in Insert mode                *scroll-insert*
  131. ========================
  132.  
  133. If you are in insert mode and you want to see something that is just off the
  134. screen, you can use CTRL-X CTRL-E and CTRL-X CTRL-Y to scroll the screen.
  135.                         |i_CTRL-X_CTRL-E|
  136.  
  137. To make this easier, you could use these mappings:
  138.     :inoremap ^E ^X^E
  139.     :inoremap ^Y ^X^Y
  140. (Type CTRL-V CTRL-E to enter ^E, CTRL-V CTRL-X to enter ^X, etc.)
  141.  
  142. Also consider setting 'scrolloff' to a larger value, so that you can always see
  143. some context around the cursor.  If 'scrolloff' is bigger than half the window
  144. height, the cursor will always be in the middle and the text is scrolled when
  145. the cursor is moved up/down.
  146.  
  147.  
  148. Smooth scrolling                    *scroll-smooth*
  149. ================
  150.  
  151. If you like the scrolling to go a bit smoother, you can use these mappings:
  152.     :map ^U ^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y
  153.     :map ^D ^E^E^E^E^E^E^E^E^E^E^E^E^E^E^E^E
  154.  
  155. (Type CTRL-V CTRL-U to enter ^U, CTRL-V CTRL-Y to enter ^Y, etc.)
  156.  
  157.  
  158. Correcting common typing mistakes            *type-mistakes*
  159. =================================
  160.  
  161. When there are a few words that you keep on typing in the wrong way, make
  162. abbreviations that correct them.  For example:
  163.     :ab teh the
  164.     :ab fro for
  165.  
  166.  
  167. Renaming files                        *rename-files*
  168. ==============
  169.  
  170. Say I have a directory with the following files in them (directory picked at
  171. random :-):
  172.  
  173. addcr.c
  174. alloc.c
  175. amiga.c
  176. ...
  177.  
  178. and I want to rename *.c *.bla.  I'd do it like this:
  179.  
  180. $ vim
  181. :r! ls *.c
  182. :%s/\(.*\).c/mv & \1.bla
  183. :w !sh
  184. :q!
  185.  
  186.  
  187. Speeding up external commands                *speed-up*
  188. =============================
  189.  
  190. In some situations, execution of an external command can be very slow.  This
  191. can also slow down wildcard expansion on Unix.  Here are a few suggestions to
  192. increase the speed.
  193.  
  194. If your .cshrc (or other file, depending on the shell used) is very long, you
  195. should separate it into a section for interactive use and a section for
  196. non-interactive use (often called secondary shells).  When you execute a
  197. command from Vim like ":!ls", you do not need the interactive things (for
  198. example, setting the prompt).  Put the stuff that is not needed after these
  199. lines:
  200.  
  201.     if ($?prompt == 0) then
  202.         exit 0
  203.     endif
  204.  
  205. Another way is to include the "-f" flag in the 'shell' option, e.g.:
  206.  
  207.     :set shell=csh\ -f
  208.  
  209. (the backslash is needed to include the space in the option).
  210. This will make csh completely skip the use of the .cshrc file.  This may cause
  211. some things to stop working though.
  212.  
  213.  
  214. Useful mappings                        *useful-mappings*
  215. ===============
  216.  
  217. Here are a few mappings that some people like to use.
  218.  
  219.     :map ' `
  220. Make the single quote work like a backtick.  Puts the cursor on the column of
  221. a mark, instead of going to the first non-blank character in the line.
  222.  
  223.                             *emacs_keys*
  224. For Emacs-style editing on the command-line:
  225. :cnoremap ^A    <Home>            start of line
  226. :cnoremap ^B    <Left>            back one character
  227. :cnoremap ^D    <Del>            delete character under cursor
  228. :cnoremap ^E    <End>            end of line
  229. :cnoremap ^F    <Right>            forward one character
  230. :cnoremap ^N    <Down>            recall newer command-line
  231. :cnoremap ^P    <Up>            recall previous (older) command-line
  232. :cnoremap <Esc>^B    <S-Left>    back one word
  233. :cnoremap <Esc>^F    <S-Right>    forward one word
  234.  
  235.                             *format_bullet_list*
  236. This mapping will format any bullet list.  It requires that there is an empty
  237. line above and below each list entry:
  238.  
  239.     :map _f   :set ai<CR>{O<Esc>}{)^Wi     <CR>     <Esc>gq}{dd5lDJ
  240.  
  241. (<> notation |<>|.  Note that ^W is "^" "W", not CTRL-W.  You can copy/paste
  242. this into Vim if '<' is not included in 'cpoptions')
  243.  
  244. You also need to set 'textwidth' to a non-zero value, e.g.,
  245.     set tw=70
  246.  
  247. A mapping that does about the same, but takes the indent for the list from the
  248. first line (Note: this mapping is a single long line):
  249.  
  250.     :map _f :set ai<CR>}{a                                                          <Esc>WWmmkD`mi<CR><Esc>kkddpJgq}'mJO<Esc>j
  251.  
  252.  
  253. Compressing the help files                *gzip-helpfile*
  254. ==========================
  255.  
  256. For those of you who are really short on disk space, you can compress the help
  257. files and still be able to view them with Vim.  This makes accessing the help
  258. files a bit slower.
  259.  
  260. (1) Compress all the help files: "gzip doc/*.txt".
  261.  
  262. (2) Edit "doc/vim_tags" and do ":%s=\\.txt<Tab>/=.txt.gz<Tab>/="
  263.     (<> notation |<>|.  You have to type a single backslash for \\ and
  264.     a real Tab for <Tab>)
  265.  
  266. (3) Add these lines to your vimrc:
  267.     set helpfile=<dirname>/vim_help.txt.gz
  268.     autocmd BufReadPre  *.txt.gz set bin
  269.     autocmd BufReadPost *.txt.gz '[,']!gunzip
  270.     autocmd BufReadPost *.txt.gz set nobin
  271.     set cmdheight=2
  272.  
  273. Where <dirname> is the directory where the help files are.  If you have
  274. already included autocommands to edit ".gz" files, you should omit the three
  275. "autocmd" lines.  Setting the command height to two is to avoid having to hit
  276. return; it is not mandatory.
  277.  
  278.  
  279. Executing shell commands in a window            *shell_window*
  280. ====================================
  281.  
  282. There have been questions for the possibility to execute a shell in a window
  283. inside Vim.  The answer: you can't!  Including this would add a lot of code to
  284. Vim, which is a good reason not to do this.  After all, Vim is an editor, it
  285. is not supposed to do non-editing tasks.  However, to get something like this,
  286. you might try splitting your terminal screen or display window with the
  287. "splitvt" program.  You can probably find it on some ftp server.  The person
  288. that knows more about this is Sam Lantinga (slouken@cs.ucdavis.edu).
  289.  
  290.  
  291. Pseudo-Ex mode                        *pseudo-Q*
  292. ==============
  293.  
  294. If you really miss the "Q" command from Vi a lot, you might want to try this
  295. mapping.  It is far from a real Ex mode, but it looks like it.  The "Q"
  296. command can still be used for formatting if you use Visual mode.
  297. You need to type "visual<CR><CR>" to get out of Ex mode.  Unfortunately, any
  298. error message does that too.
  299.  
  300. nnoremap Q :cnoremap <C-V><CR> <C-V><CR>:<CR>:
  301. cabbrev visual cunmap <C-V><CR><NL>
  302.  
  303. (<> notation |<>|.  You should enter this literally.)
  304.  
  305. In a following version of Vim the "Q" command will be made Vi compatible.  Use
  306. "gq" for formatting text.
  307.  
  308.  
  309. Using <> notation in autocommands            *autocmd-<>*
  310. =================================
  311.  
  312. The <> notation is not recognized in the argument for :autocmd.  To avoid
  313. having to use special characters, you could use a mapping to get the <>
  314. notation and then call the mapping from the autocmd.  Example:
  315.  
  316.                             *buffer-menu*
  317. "
  318. " This is for automatically adding the name of the file to the menu list
  319. " first we use the normal mode to convert the 'dots' in the filename to
  320. " \., store that in register '"' and then add that name to the Buffers menu
  321. " list.  WARNING: this does have some side effects, like overwriting the
  322. " current register contents.
  323. "
  324. nmap _xaddbufmenu O<C-R>%<Esc>:.g/\./s/\./\\./g<CR>0"9y$u:menu Buffers.<C-R>9 :buffer <C-R>%<C-V><C-M><C-M>
  325. autocmd BufNewFile,BufReadPre * normal _xaddbufmenu
  326.  
  327.  vim:ts=8:sw=8:js:tw=78:
  328.