On Thu, Aug 10, 2006 at 10:22:11AM +0800, Vincent Wang wrote: > Good idea and I am sure it will help many persons! > One suggestion, why not put your tips to www.vim.org's tips page and > post a notification in this maillist? That will make your tip well > archived and easier to reach.
This tip had a specific topic (Workspace efficiency) This leads me to another idea: Why not use some kind of wiki where we can write down many tips sorted by topic? Eg the wiki might have an index like this and much more content.. Working with vim efficiently oppening/saving files " don't losse time creating directoryies, let vim create them for you! augroup BufWritePre autocmd BufWritePre * if !isdirectory(expand('%:h'))| mkdir(expand('%:h'),'p') | endif augroup end You accidently edited a file on disk and in vim? No problem: diff them: fun! DiffWithFileFromDisk() let filename=expand('%') let diffname = filename.'.fileFromBuffer' exec 'saveas! '.diffname diffthis vsplit exec 'edit '.filename diffthis endfun managing windows Insert Code Snippets moving curosr (there is - and <cr> why not introduce your own mappings for k$ or j$? map <s-cr> <esc>o is realy useful,...) (do a fast mappnig eg <c-s-w> :windcmd w and use <number><c-s-w> to go to the next window, you'll need oonly 2 keys most of the time!) editing text searching in text ( pipe to | g - and use a mapping like this " filter lines noremap <m-f><m-l> :exec 'g!/'.input("filter expr :").'/d'<cr> " drop lines noremap <m-d><m-l> :exec 'g/'.input("filter expr :").'/d'<cr> Now you can see all matches at one glance instead of pressing n n over and over again.. ) Have you ever wondered wether it's faster to use j<keep pressnig this key> or use 5j? reduce the repetition and hold time of your keyboard and j will be fastter ;) file-type plugins use an autocommand like this to automatically resource it: augroup reloadftplugins au BufWritePost ~/.vim/ftplugin/*.vim bufdo let &ft=&ft augroup end use a shortcut like this to open the ftplugin file directly (mw is my shortcut so I can insttall different plugins easily) map <m-s-f><m-s-t><m-s-p> :exec 'e ~/.vim/ftplugin/'.&filetype.'_mw.vim'<cr> Tips for working with xml (content eg xmllint, completion, dtd <- there was another nice tutorial somewhere) C (tags, templates, .., quickfix) bash/sh vimhelp vimscripting: ... It would be nice to create a collection of useful functions... fun! IfConfirm(confirm_requirement, message, cmd) if a:confirm_requirement if !input(a:message.' [y/sth. else]')=='y' return endif endif exec a:cmd endfun " just use exec DontLoadTwice("scriptname") to not load the script twice fun! DontLoadTwice(name) let cmd = "if exists('".a:name."') | finish| let g:".a:name."=1|endif" endfun " some kind of ? operator (then_v and else_v will be evaluated!) function! If(condition, then_v, else_v) if a:condition exec a:then_v else exec a:else_v endif endfunction " usage: let a=If(condition,thenvalue,elsevalue) If you think functions like this make your code harder to read I'd suggest running exuberant-ctags in.vim and using tags or the excellent wherefrom plugin Why this? It's said that the tim you need to write a program is proportional to the number of lines you need if you are familiar enough with the languge + libs I don't think this should replace vim.org but it might link to the tips/ scripts there Benefits: Its easier to keep it up to date (on vim.org you'll get still outdated matches.. Would http://www.vi-improved.org/wiki/ be a good place? I've some ideas and scripts I want to share.. some are so small that it's not worth putting them into a tip. I think it would be also good to limit comments to a short description here. Would it be great to have some kind of notification? Marc