diff options
author | Bram Moolenaar <Bram@vim.org> | 2004-06-30 16:16:41 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2004-06-30 16:16:41 +0000 |
commit | 843ee41eb8258ac50ed81976757d8b228382a880 (patch) | |
tree | d0fcdff9e19b05b182de1bb1be46b2e6f5b8b0b7 /runtime/kde-tips | |
parent | f4b8e57ffd048f9ca46dd7618939ba7a1b2294ec (diff) |
updated for version 7.0003
Diffstat (limited to 'runtime/kde-tips')
-rw-r--r-- | runtime/kde-tips | 9314 |
1 files changed, 9314 insertions, 0 deletions
diff --git a/runtime/kde-tips b/runtime/kde-tips new file mode 100644 index 0000000000..67b350d865 --- /dev/null +++ b/runtime/kde-tips @@ -0,0 +1,9314 @@ +*vimtips.txt* This file comes from the Vim Online tip database. These tips +were downloaded on Tue, 24 Sep 2002 15:27:26 -0700 More tips can be found at <A +HREF="http://vim.sf.net/tip_index.php">http://vim.sf.net/tip_index.php</A><BR> +A new tip file can be downloaded from <A +HREF="http://vim.sf.net/tip_download.php">http://vim.sf.net/tip_download.php</A><BR> + +Thanks for using vim online. + +<Tip category="KVim"> <html><center>the super star</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=1">http://vim.sf.net/tip_view.php?tip_id=1</A><BR> + +When a discussion started about learning vim on the vim list Juergen Salk +mentioned the "*" key as something that he wished he had know earlier. When +I read the mail I had to go help on what the heck the "*" did. I also wish +I had known earlier... + +Using the "*" key while in normal mode searches for the word under the cursor. + +If that doesn't save you a lot of typing, I don't know what will. + +</pre></tip> </html> <Tip category="KVim"> <html><center>easy +edit of files in the same directory</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=2">http://vim.sf.net/tip_view.php?tip_id=2</A><BR> + +It was often frustrating when I would open a file deep in the code tree and +then realize I wanted to open another file in that same directory. Douglas +Potts taught me a nice way to do this. Add the following snipit to your vimrc: + +" Edit another file in the same directory as the current file " uses +expression to extract path from current file's path " (thanks Douglas Potts) +if has("unix") + map ,e :e <C-R>=expand("%:p:h") . "/" <CR> +else + map ,e :e <C-R>=expand("%:p:h") . "\" <CR> +endif + +Then when you type ,e in normal mode you can use tab to complete to the +file. You can also expand this to allow for spitting, etc. Very very nice. + +</pre></tip> </html> <Tip category="KVim"> <html><center>use +vim to quickly compile java files</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=3">http://vim.sf.net/tip_view.php?tip_id=3</A><BR> + +For a number of years I used vim on an SGI box. When I left my job at SGI +I went to a company that developed on PCs. For 2 years I used IDEs. I was +unhappy. I was frustrated. I couldn't figure out why. (Beyond my machine +crashing twice a day.) Finally I upgraded to windows 2000 (kind of stable!) and +started using vim as an IDE. All was good. Here is how you use vim to compile +your java: + +1. While I'm sure this works with javac, javac is slow slow slow. So download +the Jikes complier first. (Jikes is from ibm, search on google for jikes +and you will find it..available on most platforms.) + +2. Add the following to your vimrc: + +set makeprg=jikes -nowarn -Xstdout +E % set +errorformat=%f:%l:%c:%*\d:%*\d:%*\s%m + +3. When you are editing a java file type :make and it will compile the +current file and jump you to the first error in the file (if any). Read +":help quickfix" for how to move between errors. + +To setup your classpath environment either launch gvim from a shell that +has your classpath/path setup or use the "let" command to configure it in +your vimrc. + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Any word completion</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=4">http://vim.sf.net/tip_view.php?tip_id=4</A><BR> + +Either when programming or writing, I tend to have some identifiers or words +that I use all the time. By sheer accident, I noticed the 'ctrl-n' command, +that will attempt to complete the word under the cursor. Hit it once, and it +will try to complete it with the first match in the current file. If there is +no match, it will (at least in the case of C code) search through all files +included from the current one. Repeated invocations will cycle through all +found matches. + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Quickly searching for a word</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=5">http://vim.sf.net/tip_view.php?tip_id=5</A><BR> + +To search for a word under the cursor in the current file you can use either +the "*" or "#" keys. + +The "*" key will search for the word from the current cursor position to +the end of the file. The "#" key will search for the word from the current +cursor position to the top of the file. + +Note that the above two keys will search for the whole word and not the +partial word. This is equivalent to using the <word> pattern in the +search commands (/ and ?). + +To search for partial matches, you can use the "g*" and "g#" key sequence. + +You can also use the mouse to search for a word. This will only work in +the GUI version of VIM (gvim) or a console version of VIM in an xterm which +accepts a mouse. Also, the 'mousemodel' should be set to 'extend'. Add the +following line to your .vimrc: + +set mousemodel=extend + +To search for a word under the cursor from the current cursor position to +the end of the file, press the shift key and click on the word using the +left mouse button. To search in the opposite direction, press the shift +key and click on the word using the the right mouse button. + +To get more help on these, use + +:help * :help # :help g* :help g# :help <S-LeftMouse> :help +<S-RightMouse> + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Using the % key</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=6">http://vim.sf.net/tip_view.php?tip_id=6</A><BR> + +The % key can be used + +1. To jump to a matching opening or closing parenthesis, square + bracket or a curly brace i.e. ([{}]) +2. To jump to start or end of a C-style comment /* */. 3. To jump to a +matching #if, #ifdef, #else, #elif, #endif C + preprocessor conditionals. + +To get more information about this, do + + :help % + +The % key can be extended to support other matching pairs by modifying the +"matchpairs" option. Read the help on + + :help matchpairs + +</pre></tip> </html> <Tip category="KVim"> <html><center>Jumping +to the start and end of a code block</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=7">http://vim.sf.net/tip_view.php?tip_id=7</A><BR> + +To jump to the beginning of a C code block (while, switch, if etc), use the +[{ command. + +To jump to the end of a C code block (while, switch, if etc), use the ]} +command. + +The above two commands will work from anywhere inside the code block. + +To jump to the beginning of a parenthesis use the [( command. + +To jump to the end of a parenthesis use the ]) command. + +To get more help on these commands, do + +:help [{ :help ]} :help [( :help ]) + +</pre></tip> </html> <Tip category="KVim"> <html><center>Jumping +to the declaration of a local/global variable</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=8">http://vim.sf.net/tip_view.php?tip_id=8</A><BR> + +'gd' command: To jump to the declaration of a local variable in a C program, +position the cursor on the name of the variable and use the gd command. + +'gD' command: To jump to the declaration of a global variable in a C program, +position the cursor on the name of the variable and use the gD command. + +</pre></tip> </html> <Tip category="KVim"> <html><center>Displaying +a variable/macro definition</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=9">http://vim.sf.net/tip_view.php?tip_id=9</A><BR> + +To display the definition of a variable, place the cursor on the variable +and use the [i command. To display a macro definition, place the cursor on +the macro name and use the [d command. Note that these commands will work +most of the time (not all the time). To get more help on these commands, use + +:help [i :help [d + +</pre></tip> </html> <Tip category="KVim"> <html><center>Jumping +to previosuly visited locations in a file</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=10">http://vim.sf.net/tip_view.php?tip_id=10</A><BR> + +Vim remembers all the locations visited by you in a file in a session. +You can jump to the older locations by pressing the Ctrl-O key. You can +jump to the newer locations by pressing the Ctrl-I or the <Tab> key. + +To get more help on these keys, use + +:help CTRL-O :help CTRL-I :help jump-motions + +</pre></tip> </html> <Tip category="KVim"> <html><center>Completing +words quicky in insert mode</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=11">http://vim.sf.net/tip_view.php?tip_id=11</A><BR> + +In Insert mode, press the Ctrl-p or Ctrl-n key to complete part of a word +that has been typed. + +This is useful while typing C programs to complete long variable and +function names. This also helps in avoiding typing mistakes. + +Note that using the 'complete' option, you can complete keywords defined in +one of the include files, tag file, etc. + +To get more help on this, use + +:help i_Ctrl-N :help i_Ctrl-P :help ins-completion :help complete + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Converting tabs to spaces</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=12">http://vim.sf.net/tip_view.php?tip_id=12</A><BR> + +To insert space characters whenever the tab key is pressed, set the +'expandtab' option: + + set expandtab + +With this option set, if you want to enter a real tab character use +Ctrl-V<Tab> key sequence. + +To control the number of space characters that will be inserted when the tab +key is pressed, set the 'tabstop' option. For example, to insert 4 spaces +for a tab, use: + + set tabstop=4 + +After the 'expandtab' option is set, all the new tab characters entered will +be changed to spaces. This will not affect the existing tab characters. +To change all the existing tab characters to match the current tab settings, +use + + :retab + +To change the number of space characters inserted for indentation, use the +'shiftwidth' option: + + set shiftwidth=4 + +For example, to get the following coding style, + - No tabs in the source file - All tab characters are 4 space + characters + +use the following set of options: + + set tabstop=4 set shiftwidth=4 set expandtab + +Add the above settings to your .vimrc file. + +To get more help on these options, use :help tabstop :help shiftwidth :help +expandtab + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Incremental search</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=13">http://vim.sf.net/tip_view.php?tip_id=13</A><BR> + +To move the cursor to the matched string, while typing the search string, +set the following option in the .vimrc file: + + set incsearch + +You can complete the search by pressing the Enter key. To cancel the search, +press the escape key. + +</pre></tip> </html> <Tip category="KVim"> <html><center>Highlighting +all the search pattern matches</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=14">http://vim.sf.net/tip_view.php?tip_id=14</A><BR> + +To highlight all the search pattern matches in a file set the following option: + + :set hlsearch + +After this option is set, if you search for a pattern, all the matches in +the file will be highlighted in yellow. + +To disable the highlighting temporarily, use the command + + :nohlsearch + +This command will remove the highlighting for the current search. +The highlighting will come back for the next search. + +To disable the highlighting completely, set the following option: + + :set nohlsearch + +By default, the hlsearch option is turned off. + +To get more help on this option, use + +:help 'hlsearch' :help :nohlsearch + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Displaying status line always</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=15">http://vim.sf.net/tip_view.php?tip_id=15</A><BR> + +To display the status line always, set the following option in your .vimrc +file: + + set laststatus=2 + +The advantage of having the status line displayed always is, you can see +the current mode, file name, file status, ruler, etc. + +To get more help on this, use + +:help laststatus + +</pre></tip> </html> <Tip category="KVim"> <html><center>Avoiding +the "Hit ENTER to continue" prompts</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=16">http://vim.sf.net/tip_view.php?tip_id=16</A><BR> + +To avoid the "Hit ENTER to continue" prompt, use the 'shortmess' option. +Add the following line to your .vimrc file: + + set shortmess=a + +Also, you can increase the height of the command line to 2 + + set cmdheight=2 + +The default command height is 1. + +To get more help on these options, use + +:help hit-enter :help shortmess :help cmdheight + +</pre></tip> </html> <Tip category="KVim"> <html><center>Erasing +previosuly entered characters in insert mode</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=17">http://vim.sf.net/tip_view.php?tip_id=17</A><BR> + +In insert mode, to erase previously entered characters, set the following +option: + + set backspace=2 + +By default, this option is empty. If this option is empty, in insert mode, +you can not erase characters entered before this insert mode started. +This is the standard Vi behavior. + +To get more help on this, use + +:help 'backspace' + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Cleanup your HTML</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=18">http://vim.sf.net/tip_view.php?tip_id=18</A><BR> + +From Johannes Zellner on the vim list: + +You can use vim's makeprg and equalprg to clean up HTML. First download +html tidy from <A HREF="http://www.w3.org/People/Raggett/tidy/. Then use +the following commands.">http://www.w3.org/People/Raggett/tidy/. Then use +the following commands.</A><BR> + +vim6? exe 'setlocal equalprg=tidy -quiet -f '.&errorfile setlocal makeprg=tidy +-quiet -e % + +vim5? exe 'set equalprg=tidy -quiet -f '.&errorfile set makeprg=tidy -quiet +-e % + +At this point you can use make to clean up the full file or you can use = +to clean up sections. + +:help = :help equalprg :help makeprg + +</pre></tip> </html> <Tip category="KVim"> +<html><center>line numbers...</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=19">http://vim.sf.net/tip_view.php?tip_id=19</A><BR> + +I have started doing all my code reviews on a laptop because of the number +command. + +:set number will put line numbers along the left side of a window + +:help number + +</pre></tip> </html> <Tip category="KVim"> <html><center>Are *.swp +and *~ files littering your working directory?</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=20">http://vim.sf.net/tip_view.php?tip_id=20</A><BR> + +Have you ever been frustrated at swap files and backups cluttering up your +working directory? + +Untidy: + ons.txt ons.txt~ README README~ tester.py tester.py~ + +Here are a couple of options that can help: + + set backupdir=./.backup,.,/tmp set directory=.,./.backup,/tmp + +This way, if you want your backups to be neatly grouped, just create +a directory called '.backup' in your working directory. Vim will stash +backups there. The 'directory' option controls where swap files go. If your +working directory is not writable, Vim will put the swap file in one of the +specified places. + +</pre></tip> </html> <Tip category="KVim"> +<html><center>easy pasting to windows apps</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=21">http://vim.sf.net/tip_view.php?tip_id=21</A><BR> + +In Vim, the unnamed register is the " register, and the Windows Clipboard is +the * register. This means that if you yank something, you have to yank it to +the * register if you want to paste it into a Windows app. If this is too much +trouble, set the 'clipboard' option to 'unnamed'. Then you always yank to *. + +So pasting to windows apps doesn't require prefixing "* : + + set clipboard=unnamed + +</pre></tip> </html> <Tip category="KVim"> <html><center>handle +common typos for :commands</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=22">http://vim.sf.net/tip_view.php?tip_id=22</A><BR> + +I frequently hold the shift key for too long when typing, for instance :wq, +and end up with :Wq. Vim then whines "Not an editor command: Wq" + +In my .vimrc, I have taught vim my common typos: command! Q quit command! W +write command! Wq wq " this one won't work, because :X is already a built-in +command command! X xit + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Vim xterm title</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=23">http://vim.sf.net/tip_view.php?tip_id=23</A><BR> + +Check out your .vimrc. If 'set notitle' is an entry, comment it out with +a quotation mark ("). Now your xterm should inherit the title from Vim. +e.g. 'Vim - ~/.vimrc'. This can be quite nice when programming and editing +lots of files at the same time. by [jonasbn@wanadoo.dk] + +</pre></tip> </html> <Tip category="KVim"> <html><center>changing +the default syntax highlighting</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=24">http://vim.sf.net/tip_view.php?tip_id=24</A><BR> + + Here are some pointers to the vim documentation. Notice that the + mechanism is different in vim 6.0 and vim 5.x. + +1. I want *.foo files to be highlighted like HTML files. + +:help new-filetype <A +HREF="http://www.vim.org/html/autocmd.html#new-filetype">http://www.vim.org/html/autocmd.html#new-filetype</A><BR> + +2. I want to define a syntax file for *.bar files. Read the above and also + +:help mysyntaxfile <A +HREF="http://www.vim.org/html/syntax.html#mysyntaxfile">http://www.vim.org/html/syntax.html#mysyntaxfile</A><BR> + +3. I want to make a few changes to the existing syntax highlighting. +Depending on the x in 5.x, either read the above and page down a few screens, +or you may be able to skip right to + +:help mysyntaxfile-add <A +HREF="http://www.vim.org/html/syntax.html#mysyntaxfile-add">http://www.vim.org/html/syntax.html#mysyntaxfile-add</A><BR> + +4. I want to change some of the colors from their defaults. Again, read + +:help mysyntaxfile <A +HREF="http://www.vim.org/html/syntax.html#mysyntaxfile">http://www.vim.org/html/syntax.html#mysyntaxfile</A><BR> + +</pre></tip> </html> <Tip category="KVim"> <html><center>color +highlighting on telnet (esp w/ SecureCRT)</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=25">http://vim.sf.net/tip_view.php?tip_id=25</A><BR> + +The following settings in .vimrc will enable color highlighting when using +SecureCRT and may work on other telnet packages. The terminal type should +be selected as ANSI and color enabled. + +if !has("gui_running") set t_Co=8 set t_Sf=^[[3%p1%dm set t_Sb=^[[4%p1%dm endif + +The ^[ is entered as "<ctrl-v><esc>" + +</pre></tip> </html> <Tip category="KVim"> <html><center>Getting +rid of ^M - mixing dos and unix</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=26">http://vim.sf.net/tip_view.php?tip_id=26</A><BR> + +If you work in a mixed environment you will often open files that have ^M's +in them. An example would be this: + +------------------------------------------------------------------ +import java.util.Hashtable; ^M import java.util.Properties; ^Mimport +java.io.IOException; import org.xml.sax.AttributeList; ^M import +org.xml.sax.HandlerBase; ^Mimport org.xml.sax.SAXException; + +/**^M + * XMLHandler: This class parses the elements contained^M * within a XML + message and builds a Hashtable^M + +[snip] ------------------------------------------------------------------ + +Notice that some programs are not consistent in the way they insert the line +breaks so you end up with some lines that have both a carrage return and a +^M and some lines that have a ^M and no carrage return (and so blend into +one). There are two steps to clean this up. + +1. replace all extraneous ^M: + +:%s/^M$//g + +BE SURE YOU MAKE the ^M USING "CTRL-V CTRL-M" NOT BY TYPING "CARROT M"! This +expression will replace all the ^M's that have carriage returns after them +with nothing. (The dollar ties the search to the end of a line) + +2. replace all ^M's that need to have carriage returns: + +:%s/^M//g + +Once again: BE SURE YOU MAKE the ^M USING "CTRL-V CTRL-M" NOT BY TYPING +"CARROT M"! This expression will replace all the ^M's that didn't have +carriage returns after them with a carriage return. + +Voila! Clean file. Map this to something if you do it frequently. + +:help ffs - for more info on file formats + +thanks to jonathan merz, douglas potts, and benji fisher + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Convert hex to dec</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=27">http://vim.sf.net/tip_view.php?tip_id=27</A><BR> + +when you check the output of objdump, you'll confused by the $0xFFFFFFc +operand, this function translate the hexcamal to decimal. function! Hex2Dec() + let lstr = getline(".") let hexstr = matchstr(lstr, '0x[a-f0-9]+') + while hexstr != "" + let hexstr = hexstr + 0 exe 's#0x[a-f0-9]+#'.hexstr."#" let lstr = + substitute(lstr, '0x[a-f0-9]+', hexstr, "") let hexstr = matchstr(lstr, + '0x[a-f0-9]+') + endwhile +endfunction usage: 5,8call Hex2Dec() + +</pre></tip> </html> <Tip category="KVim"> <html><center>add a line-number +to every line without cat or awk alike utilities.</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=28">http://vim.sf.net/tip_view.php?tip_id=28</A><BR> + +With Unix-like environment, you can use cat or awk to generate a line number +easily, because vim has a friendly interface with shell, so everything work +in vim as well as it does in shell. :%!call -n or :%!awk '{print NR,$0}' + +But, if you use vim in MS-DOS, of win9x, win2000, you loss these tookit. +here is a very simple way to archive this only by vim: fu! LineIt() + exe ":s/^/".line(".")."/" +endf + +Well, a sequence composed with alphabet is as easy as above: + exe "s/^/".nr2char(line("."))."/" + +</pre></tip> </html> <Tip category="KVim"> <html><center>reverse +all the line with only 7 keystroke in vim</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=29">http://vim.sf.net/tip_view.php?tip_id=29</A><BR> + +:g/^/m0 well, 1. : bring you to command-line mode(also known as ex-mode) +from normal-mode(also known as command mode). 2. g means you'll take an +action through the whole file, generally perform a search, `v' also perform +a search but it match the line not match the canonical expression. 3. / +begins the regular express 4. ^ is a special character respect the start +of a line. 5. the second / ends the regular express and indicate that the +remains is action to do. 6. m means move, `t` and `co' for copy, `d' for +delete 7. 0 is the destination line. + +you can use :g/regexp/t$ to filter all lines and pick the match line together +and copy them to the end of the buffer or :g/regexp/y A to put them into a +register(not eax, ebx...) + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Increasing or decreasing numbers</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=30">http://vim.sf.net/tip_view.php?tip_id=30</A><BR> + +To increase a number under or nearest to the right of the cursor, go to +Normal mode and type: + Ctrl-A + +To decrease, type: + Ctrl-X + +Using this in a macro simplifies generating number sequences a lot. + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Find and Replace</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=31">http://vim.sf.net/tip_view.php?tip_id=31</A><BR> + +To find and replace one or more occurences of a given text pattern with a +new text string, use the s[ubstitute] command. + +There are a variety of options, but these are what you most probably want: + +:%s/foo/bar/g find each occurance of 'foo' and replace it with +'bar' without asking for confirmation + +:%s/foo/bar/gc find each occurance of 'foo' and replace it with +'bar' asking for confirmation first + +:%s/<foo>/bar/gc find (match exact word only) and replace each +occurance of 'foo' with 'bar' + +:%s/foo/bar/gci find (case insensitive) and replace each occurance of +'foo' with 'bar' + +:%s/foo/bar/gcI find (case sensitive) and replace each occurance of +'foo' with 'bar' + +NB: Without the 'g' flag, replacement occurs only for the first occurrence +in each line. + +For a full description and some more interesting examples of the substitute +command refer to + +:help substitute + +See also: + +:help cmdline-ranges :help pattern :help gdefault + +</pre></tip> </html> <Tip category="KVim"> <html><center>Write +your own vim function(scripts)</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=32">http://vim.sf.net/tip_view.php?tip_id=32</A><BR> + +compare to C and shell(bash), herein is some vim specifics about vim-script: +1. A function name must be capitalized. + hex2dec is invalid Hex2dec is valid while in c and shell(bash), both + lowercase and uppercase is allowed. +2. how to reference the parameters + fu! Hex2dec(var1, var2) + let str=a:var1 let str2=a:var2 + you must prefix the parameter name with "a:", and a:var1 itself is read-only + in c, you reference the parameter directly and the parameter is writable. +3. how to implement variable parameter + fu! Hex2dec(fixpara, ...) + a:0 is the real number of the variable parameter when you invoke the + function, with :Hex2dec("asdf", 4,5,6), a:0=3, and a:1=4 a:2=5 a:3=6 + you can combine "a:" and the number to get the value while i<a:0 + exe "let num=a:".i let i=i+1 + endwhile in c, the function get the real number by checking the additional + parameter such as printf family, or by checking the special value such + as NULL +4. where is the vim-library + yes, vim has its own function-library, just like *.a in c :help functions +5. can I use += or ++ operator? + Nop, += and ++ (and -=, -- and so on)operator gone away in vim. +6. How can I assign a value to a variables and fetch its value? + let var_Name=value let var1=var2 like it does in c, except you must use + let keyword +7. Can I use any ex-mode command in a function? + As I know, yes, just use it directly, as if every line you type appears + in the familar : +8. Can I call a function recurse? + Yes, but use it carefully to avoid infinte call. +9. Can I call another function in a function? + Course, like C does. +10. Must I compile the function? + No, you needn't and you can't, just :so script_name, after this you can + call the function freely. +11. Is it has integer and char or float data type? + No, like perl, vim script justify the variable type depend upon the context + :let a=1 :let a=a."asdf" :echo a you'll get `1asdf' :let a=1 :let a=a+2 + :echo a you'll get 3 But it differs from perl. +12. Must I append a `;' in every statement? + No, never do that. ; is required in C, and optional in shell for each + statement in a alone line. But is forbidden in vim. if you want combine + servals statement in one single line, use `|'. Take your mind that every + statement appears in function should be valid in ex-mode(except for some + special statement). + +</pre></tip> </html> <Tip category="KVim"> <html><center>toggle +off the line-number when enter on-line help</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=33">http://vim.sf.net/tip_view.php?tip_id=33</A><BR> + +I like the line-number for myself editing. But I hate it in on-line help +page because it force the screen wrapped. :au filetype help :se nonu + +</pre></tip> </html> <Tip category="KVim"> <html><center>control +the position of the new window</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=34">http://vim.sf.net/tip_view.php?tip_id=34</A><BR> + +:se splitbelow make the new window appears below the current window. +:se splitright make the new window appears in right.(only 6.0 version can +do a vsplit) + +</pre></tip> </html> <Tip category="KVim"> <html><center>translate +// style comment to /* */and vice vesa</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=35">http://vim.sf.net/tip_view.php?tip_id=35</A><BR> + +the `|' concatenate servals ex-command in one line. It's the key to translate +// style comments to /* */ style :g#^s{-}//#s##/*# | s#$#*/# + +the `|' keep the current line matchs ^s{-}// to perform s#$#*/ + +/* ... */ ---> //style :g#/*(.{-})*/#//1# + +/* .... + .... ..... +*/ =====> //...... //...... //...... style: ? Anyone implement it? + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Using Gnu-info help in vim</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=36">http://vim.sf.net/tip_view.php?tip_id=36</A><BR> + +K in normal bring you the man page about the keyword under current cursor. +:nnoremap <F1> :exe ":!info ".expand("<cword>") Now press F1 +while the cursor is hold by a keyword such as printf will bring you to +Gnu-info help page :h <F1> :h nnoremap + +</pre></tip> </html> <Tip category="KVim"> <html><center>The +basic operation about vim-boolean optionals</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=37">http://vim.sf.net/tip_view.php?tip_id=37</A><BR> + +:set number switch the number on :set nonumber switch it off :set invnumber +or :set number! switch it inverse against the current setting :set number& +get the default value vim assums. + +replace number with any legal vim-boolean optionals, they all works well. +for vim-non-boolean optionals :set optional& also works properly. + +</pre></tip> </html> <Tip category="KVim"> <html><center>Cursor +one line at a time when :set wrap</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=38">http://vim.sf.net/tip_view.php?tip_id=38</A><BR> + +If your tierd of the cursor jumping past 5 lines when :set wrap then add +these mappings to you vimrc file. + +nnoremap j gj nnoremap k gk vnoremap j gj vnoremap k gk nnoremap <Down> +gj nnoremap <Up> gk vnoremap <Down> gj vnoremap <Up> +gk inoremap <Down> <C-o>gj inoremap <Up> <C-o>gk + +What they do is remap the cursor keys to use there `g' equvilant. See :help gj + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Undo and Redo</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=39">http://vim.sf.net/tip_view.php?tip_id=39</A><BR> + +To undo recent changes, use the u[ndo] command: + +u undo last change (can be repeated to undo preceding commands) +U return the line to its original state (undo all changes in +current line) CTRL-R Redo changes which were undone (undo the undo's). + +For a full description of the undo/redo commands refer to + +:help undo + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Insert a file</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=40">http://vim.sf.net/tip_view.php?tip_id=40</A><BR> + +To insert the contents of a file (or the output of a system command) into +the current buffer, use the r[ead] command: + +Examples: + +:r foo.txt inserts the file foo.txt below the cursor + +:0r foo.txt inserts the file foo.txt above the first line + +:r !ls inserts a listing of your directory below the cursor + +:$r !pwd inserts the current working directory below the last line + +For more information about the r[ead] command refer to: + +:help read + +See also: + +:help cmdline-ranges :help !cmd + +</pre></tip> </html> <Tip category="KVim"> <html><center>Command-history +facilities for Oracle/sqlplus user</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=41">http://vim.sf.net/tip_view.php?tip_id=41</A><BR> + + First of all, thanks Benji fisher, Stefan Roemer... +and others in vim@vim.org which spend much time to answer questions, +sometimes foolish question asked by someone like me. Without their I can't +get the final solution for my sqlplus work descripted follows. + As Oracle user known, sqlplus has a very bad +command-line edition environment. It has no command-history, don't support +most of getline facilities. which MySQL and shell does it well. Even Microsoft +recogonize this point. In Windows2000, doskey is installed by default. + Below is my vim-solution to sqlplus, which +record the command-history when you use edit(sqlplus builtin command) to +open the editor specified by EDITOR environment variable. It saves the SQL +statement into a standalone file such as .sqlplus.history + Every time you open the file +afiedt.buf(sqlplus's default command-buffer file), you get two splited windows, +the buffer above is afiedt.buf, the buffer below is .sqlplus.history, you +can see every SQL statement in the windows. If you want to use SQL statement +in line 5 to replace + the current command-buffer, just press 5K, then + :xa to back to you sqlplus. and use / to repeat the command + saved in command-buffer file called afiedt.buf by default. + It can't process multi-line SQL statement convinencely. + Todo this, just use you favorite vim trick to do that: + fu! VimSQL() + nnoremap <C-K> :<C-U> + exe "let linenum=".v:count<CR>:1,$-1d<CR><C-W>j:exe + lin enum."y"<CR><C-W>kP + let linenum=line("$") 1,$-1w! >> ~/.sqlplus.history e + ~/.sqlplus.history execute ":$-".(linenum-1).",$m0" %!uniq if + line("$")>100 + 101,$d + endif b# set splitbelow sp ~/.sqlplus.history au! BufEnter afiedt.buf +endf au BufEnter afiedt.buf call VimSQL() + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Using marks</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=42">http://vim.sf.net/tip_view.php?tip_id=42</A><BR> + +To mark one or more positions in a file, use the m[ark] command. + +Examples: + +ma - set current cursor location as mark a + +'a - jump to beginning of line of mark a + +`a - jump to postition of mark a + +d'a - delete from current line to line of mark a + +d`a - delete from current cursor position to mark a + +c'a - change text from current line to line of mark a + +y`a - yank text to unnamed buffer from cursor to mark a + +:marks - list all the current marks + +NB: Lowercase marks (a-z) are valid within one file. Uppercase marks (A-Z), +also called file marks, are valid between files. + +For a detailed description of the m[ark] command refer to + +:help mark + +See also: + +:help various-motions + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Using abbreviations</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=43">http://vim.sf.net/tip_view.php?tip_id=43</A><BR> + +To define abbreviations, use the ab[breviate] command. + +Examples: + +:ab rtfm read the fine manual - Whenever you type 'rtfm' followed by a +<space> (or <esc> or <cr>) vim + will expand this to 'read the fine manual'. + +:ab - list all defined abbreviations + +:una[bbreviate] rtfm - remove 'rtfm' from the list of abbreviations + +:abc[lear] - remove all abbreviations + +NB: To avoid expansion in insert mode, type CTRL-V after the last character +of the abbreviation. + +For a detailed description of the ab[breviate] command and some more examples +refer to + +:help abbreviations + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Repeat last changes</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=44">http://vim.sf.net/tip_view.php?tip_id=44</A><BR> + +Simple text changes in normal mode (e.g. "dw" or "J") can be repeated with +the "." command. The last command-line change (those invoked with ":", +e.g. ":s/foo/bar") can be repeated with the "@:" command. + +For more informations about repeating single changes refer to: + +:help single-repeat + +</pre></tip> </html> <Tip category="KVim"> +<html><center>Using command-line history</center> <pre> <A +HREF="http://vim.sf.net/tip_view.php?tip_id=45"& |