" vimrc " Maintainer: Silvano Galliani aka kysucix " Last Change: 2010 Oct 23 " Usage: copy it to " for Unix and OS/2: ~/.vimrc " for Amiga: s:.vimrc " for MS-DOS and Win32: $VIM\_vimrc " for OpenVMS: sys$login:.vimrc """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " To be more clear I've used verbose version of option name (not the compact " one). -- kysu. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " GENERAL " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set nocompatible " Not compatibile with old vi (hehehe) if version >= 600 " Stuff which is only possible in vim 6.. filetype plugin on filetype plugin indent on filetype indent on source $VIMRUNTIME/ftplugin/man.vim " this allows me to do ':Man manpage' to read a nmap ,e :Ex " Mapping for explorer.vim, a standard plugin in vim 6 endif set history=150 " keep 150 lines of command line history set cf " Read the error file and jump to the first error set clipboard+=unnamed " yank and copy to X clipboard! :) set viminfo=%,'50,\"100,n~/.vim/viminfo " the viminfo file is read upon startup and written when exiting Vim set iskeyword+=-,$,@ " none of these should be word dividers, so make them not be set confirm " if you :q with changes it asks you if you want to continue or not set ttimeoutlen=100 " 100 milliseconds for escape timeout instead of 1000 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " COLORS " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" syntax on " Show colors if &t_Co > 2 || has("gui_running") " Switch syntax highlighting on, when the terminal has colors syntax on set hlsearch " When there is a previous search pattern, highlight all its matches endif " colorscheme fruit " I like fruit! :) " Better search color " highlight search term=bold ctermfg=14 ctermbg=11 guifg=Black guibg=#80aaaa " highlight Normal guibg=grey30 " Gvim color background " Different Color schemes "colors blue "colors darkblue "colors default "colors elflord "colors evening "colors koehler "colors morning "colors murphy "colors pablo "colors peachpuff "colors ron "colors shine "colors torte "colors zellner setlocal comments-=:// """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " VIM UI " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set linespace=2 " Number of pixel lines inserted between characters. (more readable) set ruler " show the cursor position all the time set cursorline highlight cursorline guibg=#cccccc " highlight the cursor line highlight CursorColumn guibg=#cccccc "highlight the cursor line set cmdheight=1 " Number of screen lines to use for the command-line. set lazyredraw " do not redraw while running macros (much faster) set backspace=indent,eol,start " allow backspacing over everything in insert mode set whichwrap+=<,>,h,l " backspace and cursor keys wrap to set mouse=a " use mouse " set hidden " Lets you change buffer without saving ;) set fillchars=vert:\ ,stl:\ ,stlnc:\ " select splitter rendering set clipboard+=unnamed " share clipboard with windows clipboard """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " VISUAL CLUES " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set showmatch " When a bracket is inserted, briefly jump to the matching one. set matchtime=1 " Tenths of a second to show the matching paren, when 'showmatch' is "set. set smartindent " braces affect autoindentation set cinkeys +=; " figure out indent when ; is pressed set shiftround " < and > will hit indentation levels instead of always -4/+4 set scrolloff=3 " Minimal number of screen lines to keep above and below the cursor. set noerrorbells " no freaking error bells set novisualbell " visual is way too flashy! " set statusline=%F%m%r%h%w\ buffer\ %n\ [pos\ %04l,%04v][%p%%]\ [type\ %Y] set laststatus=2 " The value of this option influences when the last window will have a status line "set smarttab "When on, a in front of a line inserts blanks according to " shiftwidth'. 'tabstop' is used in other places. set shiftwidth=4 " Number of spaces to use for each step of (auto)indent. "set softtabstop=4 " Number of spaces that a counts for while performing editing operations,like inserting a or using . "set tabstop=4 "Number of spaces that a in the file counts for. (Bad 4 Makefiles!) " set expandtab set complete=.,b,u,w,t,i,d " buffers used for loop in autocompletion " Go wild! :) set wildmenu " When 'wildmenu' is on, command-line completion operates in an enhanced mode. set wildmode=full " Completion mode that is used for the character specified with 'wildchar'. set wildchar= " Character you have to type to start wildcard expansion in the command-line set wildignore=*.o,*~,*.bak " Tab complete now ignores these set suffixes=.~,.bak,.class,.o,.aux,.bak,.dvi,.idx,.log,.ps,.swp,.tar " Ignore filename with any of these suffixes when using the :edit command. set showmode " If in Insert, Replace or Visual mode put a message on the last line. set showfulltag set wrap " Lines longer than the width of the window will wrap and displaying continues on the next line. set nolist " Show tabs as CTRL-I, show end of line with $ set terse " Add 's' flag to 'shortmess' option set verbose=0 " When bigger than zero, Vim will give messages about what it is doing. set undolevels=1000 " Maximum number of changes that can be undone. set updatecount=200 " write swap file to disk after each 200 characters set updatetime=6000 " write swap file to disk after 5 inactive seconds set foldenable " Enable folding set fo -=c set langmenu=it " No comment ;) set comments=sl:/*,mb:**,elx:* " Format Comment set title " Show title in xterm window set ttyfast " set title of the terminal set ttyscroll=999 " turn off scrolling -> faster! set icon " the icon text of the window will be set to the value of the name of the file set fileformat=unix " unix file format "autocmd BufEnter * let %titlestring=expand("%:p:~") " Per il tasto K (cercare nel man la parola sul cursore) "set keywordprg=man\ -s " Program to use for the |K| command "set listchars=tab:>>. "set listchars+=trail:. " set statusline=Vim-%{(Version())} [%02n]\ %(%M%R%H%)\ %F\ %=<%l,%c%V>\ %P set nocompatible " Use Vim settings, rather then Vi settings (much better!). set autoindent " new line has indentation equal to previous line set nostartofline " keep the horizontal cursor position when moving vertically """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " BACKUP " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set writebackup " yes, make a backup before overwriting a file set backup " keep a backup file set backupdir=~/.vim/backupfiles/ " backup dir set directory=~/.vim/temp/ " directory is the directory for temp file (e. g. annoying swap files ) " create ~/.vim/backupfiles/ if it doesn't exist. if has("unix") if !isdirectory(expand("~/.vim/backupfiles/.")) !mkdir -p ~/.vim/backupfiles/ endif if !isdirectory(expand("~/.vim/temp/.")) !mkdir -p ~/.vim/temp/ endif endif set backupext=~ " backup extension set makeef=vim.err set showcmd " display incomplete commands set report=0 " show a report when N lines were changed. report=0 thus means show all changes set shell=/bin/bash " Name of the shell to use for ! and :! commands. " set path=.,src/*,src/,src/include/,/usr/local/include/,/usr/local/include/*,/usr/include/,/usr/include/*,, " This is a list of directories which will be searched when using the |gf|, [f, ]f, ^Wf, |:find| and other commands set path=.,src/*,src/,src/include/,, " This is a list of directories which will be searched when using the |gf|, [f, ]f, ^Wf, |:find| and other commands set noterse " show search message when wrapping around " Vim-latex settings let g:tex_flavor='latex' let g:Tex_DefaultTargetFormat='pdf' let g:Tex_FormatDependency='dvi,ps,pdf' let g:Tex_MultipleCompileFormats='dvi,pdf' let g:Imap_UsePlaceHolders=0 let g:Tex_CompileRule_dvi = 'latex -interaction=nonstopmode -file-line-error-style $*' " http://linuxwisdom.blogspot.com/2007/08/fixing-latex-suites-jump-to-error.html " Pre-GUI settings " set columns=80 lines=30 " don't inherit geometry from parent term set mousemodel=popup " right mouse button pops up a menu in the GUI let &guicursor = &guicursor . ",a:blinkon0" " Use a sufficiently wide window automatically when started as "gvimdiff" if (&foldmethod == 'diff') set columns=165 endif " Customized setting when editing gentoo ebuilds if (getcwd() =~ 'gentoo-x86\|gentoo-src\|portage') set tabstop=4 "Number of spaces that a in the file counts for. (Bad 4 Makefiles!) set shiftwidth=4 " Number of spaces to use for each step of (auto)indent. set noexpandtab "In Insert mode: Use the appropriate number of spaces to insert a endif " t_vb: terminal's visual bell - turned off to make Vim quiet "set t_vb= " Cscope stuffs if has("cscope") set csprg=/usr/local/bin/cscope set csto=0 set cst set nocsverb " add any database in current directory if filereadable("cscope.out") cs add cscope.out " else add database pointed to by environment elseif $CSCOPE_DB != "" cs add $CSCOPE_DB endif set csverb endif "set incsearch " do incremental searching -> *annoying!* set smartcase " ignore case when pattern has at least one upper case character setlocal omnifunc=syntaxcomplete#Complete " turn on omnicompletion for every file type known set dictionary+=/usr/share/dict/words " add the dictionary to tab completion set completeopt-=preview " remove unuseful preview window set completeopt+=menuone " use the menu also with one match set completeopt+=longest " add as many information as possible " If you want to complete system functions you can do something like this. Use "ctags to generate a tags file for all the system header files: > " % ctags -R -f ~/.vim/systags /usr/include /usr/local/include "In your vimrc file add this tags file to the 'tags' option: > set tags+=~/.vim/systags set tags+='./.tags,.tags' " add .tags files " set tags+='./../tags,../tags,./../.tags,../.tags' " look in the level above """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " AUTOCOMMAND " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Only do this part when compiled with support for autocommands. if has("autocmd") "c sources autocmd BufRead *.c set cindent " Enables automatic C program indenting autocmd BufRead *.c set number " Print the line number in front of each line. autocmd BufRead *.c set autowrite autocmd BufRead *.c set tabstop=4 autocmd BufRead *.c set softtabstop=4 " Number of spaces that a counts for while performing editing operations,like inserting a or using . autocmd BufRead *.c set expandtab " autocmd BufRead *.c set omnifunc=ccomplete#Complete let c_comment_strings=1 " I like highlighting strings inside C comments " let c_space_errors=1 " trailing white space and spaces before a let c_gnu=1 " GNU gcc specific items let c_syntax_for_h=1 " use C syntax for *.h files, instead of C++ "set textwidth=78 " not really useful for every file " autocmd BufRead *.c if ! filereadable("Makefile.out") " set makeprg=gcc\ % "autocmd BufRead *.rb copen augroup C autocmd BufRead *.c set cinoptions=:.,+.,t0,g0,p2s,(0,=.5s formatoptions=croql cindent shiftwidth=4 tabstop=4 augroup END autocmd BufRead *.rb compiler ruby " Folding stuff, enabled for pl, pm, c, h and cpp files. au BufNewFile,BufRead * syn sync fromstart au BufNewFile,BufRead * set foldmethod=manual au BufNewFile,BufRead *.c,*.h,*.cpp,*.cc set foldmethod=syntax au BufNewFile,BufRead *.pl,*.pm set foldmethod=indent au BufNewFile,BufRead *.c,*.h,*.cpp,*.cc,*.pl,*.pm syn region myFold start="{" end="}" transparent fold au BufNewFile,BufRead * set foldlevel=99 au BufNewFile,BufRead *.html,*.htm set sw=1 au BufNewFile,BufRead *.po set tw=80 au BufNewFile,BufRead *.hg set ft=cpp au BufNewFile,BufRead *.ccg set ft=cpp " Comment out a visually selected block (C++) vmap C i/* */p au BufNewFile,BufRead *.pl,*.pm imap stderr print STDERR "\\n";3hi au BufNewFile,BufRead *.pl,*.pm imap stddump print STDERR Data::Dumper->Dump();hi "au BufNewFile,BufRead *.php imap Get $_GET['']hi "au BufNewFile,BufRead *.php imap Post $_POST['']hi " :au BufAdd,BufNewFile * nested tab sball " c++ sources autocmd BufRead *.cpp set cindent " Enables automatic C program indenting autocmd BufRead *.cpp set number " Print the line number in front of each line. autocmd BufRead *.cpp set autowrite "autocmd BufRead *.cpp copen " java sources autocmd BufRead *.java set cindent " Enables automatic C program indenting autocmd BufRead *.java set makeprg=javac\ % " Set make prog. 4 :make :) autocmd BufRead *.java set number " Print the line number in front of each line. autocmd BufRead *java ab println System.out.println("");hhi autocmd BufRead *.java set include=^#\s*import autocmd BufRead *.java set includeexpr=substitute(v:fname,'\\.','/','g') "autocmd BufRead *.java copen 10 " python files autocmd FileType python set expandtab " Use the appropriate number of spaces to insert a (U know how python behave! ;) autocmd FileType python set number " Print the line number in front of each line. autocmd FileType python set autowrite " Write the contents of the file, if it has been modified, on each command autocmd FileType python set tabstop=4 "Number of spaces that a in the file counts for. (Bad 4 Makefiles!) autocmd FileType python set shiftwidth=4 " set to the same as tabstop (see #4 in :help tabstop) autocmd FileType python set softtabstop=4 " if it looks like a tab, we can delete it like a tab autocmd FileType python set textwidth=0 " do not break lines when line lenght increases autocmd FileType python set omnifunc=pythoncomplete#Complete autocmd FileType python set tags+=~/.vim/pytags autocmd FileType python set textwidth=80 autocmd FileType python set foldmethod=indent autocmd FileType python set smarttab " Use the "shiftwidth" setting for inserting s instead of the "tabstop" setting, when at the beginning of a line. autocmd FileType python set expandtab " Insert spaces instead of character when the key is pressed. This is also the prefered method of Python coding, since Python is especially sensitive to problems with indenting which can occur when people load files in different editors with different tab settings, and also cutting and pasting between applications (ie email/news for example) can result in problems. It is safer and more portable to use spaces for indenting. autocmd FileType python set autoindent " new line has indentation equal to previous line autocmd FileType python set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class " The following line sets the smartindent mode for *.py files. It means that after typing lines which start with any of the keywords in the list (ie. def, class, if, etc) the next line will automatically indent itself to the next level of indentation " latex files " http://vim-latex.sourceforge.net/documentation/latex-suite/recommended-settings.html autocmd BufRead *.tex set spell " chwck spellimg mistakes ;) autocmd BufRead *.tex set spelllang=en_gb " chwck spellimg mistakes ;) autocmd BufRead *.tex set textwidth=0 " this is mostly a matter of taste. but LaTeX looks good with just a bit " of indentation. autocmd BufRead *.tex set shiftwidth=2 " TIP: if you write your \label's as \label{fig:something}, then if you " type in \ref{fig: and press you will automatically cycle through " all the figure labels. Very useful! autocmd BufRead *.tex set iskeyword+=: autocmd BufRead *.tex map :w:make %< autocmd BufRead *.tex map :!evince %<.pdf & " Vim outliner plugin " See here http://www.troubleshooters.com/linux/olvim.htm#Configuring autocmd BufRead *.otl set ignorecase autocmd BufRead *.otl set autoindent autocmd BufRead *.otl set backspace=2 autocmd BufRead *.otl set foldmethod=indent autocmd BufRead *.otl set noexpandtab autocmd BufRead *.otl set nosmarttab autocmd BufRead *.otl set softtabstop=0 "autocmd BufRead *.lsp,*.lisp so $HOME/.vim/plugin/VIlisp-2.0/VIlisp.vim " Enable file type detection. " Use the default filetype settings, so that mail gets 'tw' set to 72, " 'cindent' is on in C files, etc. " Also load indent files, to automatically do language-dependent indenting. " For all text files set 'textwidth' to 78 characters. "autocmd FileType text setlocal textwidth=78 " When editing a file, always jump to the last known cursor position. " Don't do it when the position is invalid or when inside an event handler " (happens when dropping a file on gvim). "autocmd BufReadPost * " \ if line("'\"") > 0 && line("'\"") <= line("$") | " \ exe "normal g`\"" | " \ endif endif " has("autocmd") "----------SOURCE " source /usr/share/vim/vim71/ftplugin/changelog.vim if filereadable("/usr/share/vim/addons/ftplugin/vo_checkbox.vim") source /usr/share/vim/addons/ftplugin/vo_checkbox.vim endif "source $HOME/a.vim " :A swithes to filename.h :AS opens it in a new window "source $HOME/info.vim " :Info "source $HOME/tagmenu.vim " Tags menu in gvim "source $HOME/python.vim " nn mi convince "source $VIMRUNTIME/ftplugin/man.vim " To use :Man or \K and open the page manual in a window "source $HOME/Preview.vim " PreviewWord puo' essere noioso "source /home/kysucix/.man.vim "source $HOME/methods/methods.vim " method menu 4 java and c++ "source $HOME/c.vim "source $HOME/costumization.vimrc "source $HOME/costumization.gvimrc "source /home/kysucix/EnhancedCommentify.vim "source $HOME/vimbuddy.vim " %{VimBuddy()} on statusline "source $HOME/cscope_macros.vim "source $HOME/cream-progressbar.vim "call ProgressBar( 100, "Loading file...", "#", 0 ) let g:miniBufExplMapCTabSwitchBufs = 1 "----------MAPPING highlight Pmenu ctermfg=0 ctermbg=2 gui=NONE highlight PmenuSel ctermfg=0 ctermbg=7 gui=NONE highlight PmenuSbar ctermfg=7 ctermbg=0 gui=NONE highlight PmenuThumb ctermfg=0 ctermbg=7 gui=NONE highlight PMenu gui=bold guibg=LightSkyBlue4 guifg=honeydew2 highlight PMenuSel gui=bold guibg=DarkGreen guifg=honeydew2 highlight PMenuSbar gui=bold guibg=LightSkyBlue4 highlight PMenuThumb gui=bold guibg=DarkGreen highlight SpellBad gui=undercurl guisp=Red highlight SpellRare gui=undercurl guisp=Orange highlight SpellLocal gui=undercurl guisp=Orange highlight SpellCap gui=undercurl guisp=Yellow :imap Date: :read !datekJ imap map _F ma[[k"xyy`a:echo @x " _F will display which function you are currently in. " I also have 2 tweaks in my .vimrc so you can use CTRL+LeftArrow and CTRL+RightArrow to move between the files with more natural key bindings. map map inoremap " map :w to :W, typical typo nmap :W :w " tab navigation like firefox :nmap :tabnext :nmap :tabprevious :map :tabprevious :map :tabnext :imap :tabpreviousi " :imap :tabnexti " :nmap :tabnew " :imap :tabnew " :map :tabclose " :imap :tabclose " Copy Function Declaration from a header file into the implementation file. "nmap "lYml[[kw"cye'l " Abbreviations when writing C/C++ code abbr #i #include abbr #d #define abbr #e #endif "nmap ma:let @n=@/"lp==:s/\/\/\*&\*\//e:s/\/\/\*&\*\//e:s/\s*=\s*0\s*//e:s/(.\{-}\zs=\s*[^,)]\{-1,}\>\ze\(\*\/\)\@!.*)/\/\*&\*\//e:s/(.\{-}\zs=\s*[^,)]\{-1,}\>\ze\(\*\/\)\@!.*)/\/\*&\*\//e:s/(.\{-}\zs=\s*[^,)]\{-1,}\>\ze\(\*\/\)\@!.*)/\/\*&\*\//e:let @/=@n'ajf(b"cPa::f;s{}kk map w :call Browser () " \w in normal mode display url under curson in galeon function! Browser () let line = getline (".") let line = matchstr (line, "http[^ ]*") exec "!firefox -n ".line endfunction " alternate plugin stuff! :) let g:alternateSearchPath = 'sfr:../source,sfr:../src/include,sfr:include,sfr:../inc' let g:alternateNoDefaultAlternate = 1 map :A "show tabs/ hide tabs / naviguate through tabs "tab labels show the filename without path(tail) (see :help statusline for options) ":set guitablabel=%t function GuiTabLabel() let label = '' let bufnrlist = tabpagebuflist(v:lnum) " Add '+' if one of the buffers in the tab page is modified for bufnr in bufnrlist if getbufvar(bufnr, "&modified") let label = '+' break endif endfor " Append the number of windows in the tab page if more than one " let wincount = tabpagewinnr(v:lnum, '$') " if wincount > 1 " let label .= wincount " endif if label != '' let label .= ' ' endif " Append the buffer name return label . bufname(bufnrlist[tabpagewinnr(v:lnum) - 1]) endfunction "set switchbuf=usetab "tab sball set guitablabel=%{GuiTabLabel()} "set guitablabel=%f "when pressing F3, open all buffer in tabs / close all tabs map :if g:toggleTabs == 1:tabo:set lines+=3:let g:toggleTabs = 0:else:set lines-=3:tab ball:let g:toggleTabs = 1:endif " tab navigation (next tab or next buffer) (firefox style) nmap :tabprevious nmap :tabnext " tab navigation (next tab or next buffer) with alt left / alt right "map :if g:toggleTabs == 1:tabnext:else:bn:endif "map :if g:toggleTabs == 1:tabprevious:else:bp:endif " I've embedded funcmenu here so with just one conf file you will have everything! """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " File: funcmenu.vim " Author: Yegappan Lakshmanan " Version: 1.4 " Last Modified: April 11, 2002 " " Overview " -------- " The "Function Menu" (funcmenu.vim) plugin script creates a "Functions" menu " containing all the functions defined in the current file. If you select a " function name from the menu, the cursor will be positioned at the location " of the selected function. " " As this script uses menus, this will work only with GUI Vim. This script " relies on the exuberant ctags utility (http://ctags.sourceforge.net) to " generate the function listing. This script will run on all the platforms " where the exuberant ctags utility is supported (this includes MS-Windows and " Unix based systems). " " This script supports the following language files: Assembly, ASP, Awk, C, " C++, Cobol, Eiffel, Fortran, Java, Lisp, Make, Pascal, Perl, PHP, Python, " Rexx, Ruby, Scheme, Shell, Slang, TCL and Vim. " " When you enter a file, a menu with all the functions in the file will be " automatically created. When you leave the file, the menu entries will be " removed. " " Configuration " ------------- " The script uses the Fmenu_ctags_path variable to locate the ctags utility. " By default, this is set to /usr/bin/ctags. Set this variable in your .vimrc " file to point to the location of the ctags utility in your system " " let Fmenu_ctags_path = 'd:\tools\ctags.exe' " " If a file contains too many functions, greater than a configurable limit, " then the function menu will be split into sub-menus. The default limit is " 25. This can be changed by setting the Fmenu_max_items variable in " your .vimrc file: " " let Fmenu_max_items = 20 " " By default, the function names will be added to the menu in the order in " which they are defined in the file. You can alphabetically sort the function " names in the menu by selecting the "Sort By->Name" menu item. You can also " change the default order by setting the variable Fmenu_sort_type to " "name" or "order" in your .vimrc file: " " let Fmenu_sort_type = "name" " " You can also tear-off the function menu. The function menu will be updated " automatically as you switch between files. " " This script will not work in 'compatible' mode. Make sure the 'compatible' " option is not set. " " if exists("loaded_funcmenu") || &cp finish endif let loaded_funcmenu=1 " This script is useful only in GUI Vim if !has("gui_running") finish endif " " To modify any of the following variable values, set them in your .vimrc " file using the ':let' commands. " " The default location of the exuberant ctags if !exists("Fmenu_ctags_path") let Fmenu_ctags_path = '/usr/bin/ctags' endif " Maximum number of functions, after which the menu will be split into " submenus. if !exists("Fmenu_max_items") let Fmenu_max_items = 25 endif " Function name sort type if !exists("Fmenu_sort_type") let Fmenu_sort_type = "order" endif " ****************** Do not modify after this line ************************ " Function menu empty or not? let s:fmenu_empty = 1 function! s:Remove_Function_Menu() if !has("gui_running") || s:fmenu_empty return endif " Cleanup the Functions menu silent! unmenu F&unctions menu F&unctions.Dummy l silent! unmenu! F&unctions amenu F&unctions.Refresh :call Refresh_Function_Menu() amenu F&unctions.Sort\ By.Name :call Sort_Function_Menu("name") amenu F&unctions.Sort\ By.Order :call Sort_Function_Menu("order") amenu F&unctions.-SEP1- : unmenu F&unctions.Dummy let s:fmenu_empty = 1 endfunction " Add_Function_Menu " Add the functions defined in the current file to the menu function! s:Add_Function_Menu(menu_clear) if !has("gui_running") return endif if (a:menu_clear) " Cleanup the Functions menu silent! unmenu F&unctions menu F&unctions.Dummy l silent! unmenu! F&unctions amenu F&unctions.Refresh :call Refresh_Function_Menu() amenu F&unctions.Sort\ By.Name :call Sort_Function_Menu("name") amenu F&unctions.Sort\ By.Order :call Sort_Function_Menu("order") amenu F&unctions.-SEP1- : unmenu F&unctions.Dummy let s:fmenu_empty = 1 endif let filename = expand("%") " empty filename if filename == "" return endif " Make sure the file is readable if !filereadable(filename) return endif " Exuberant ctags arguments to generate a function list let ctags_args = " --format=0 -f - " if g:Fmenu_sort_type == "name" let ctags_args = ctags_args . " --sort=yes " else let ctags_args = ctags_args . " --sort=no " endif let ftype = &filetype if ftype == 'asm' let ft_args = " --language-force=asm --asm-types=l " elseif ftype == 'aspperl' || ftype == 'aspvbs' let ft_args = " --language-force=asp --asp-types=fs " elseif ftype == 'awk' let ft_args = " --language-force=awk --awk-types=f " elseif ftype == 'c' let ft_args = " --language-force=c --c-types=f " elseif ftype == 'cpp' let ft_args = " --language-force=c++ --c++-types=f " elseif ftype == 'cobol' let ft_args = " --language-force=cobol --cobol-types=p " elseif ftype == 'eiffel' let ft_args = " --language-force=eiffel --eiffel-types=f " elseif ftype == 'fortran' let ft_args = " --language-force=fortran --fortran-types=f " elseif ftype == 'java' let ft_args = " --language-force=java --java-types=m " elseif ftype == 'lisp' let ft_args = " --language-force=lisp --lisp-types=f " elseif ftype == 'make' let ft_args = " --language-force=make --make-types=m " elseif ftype == 'pascal' let ft_args = " --language-force=pascal --pascal-types=f " elseif ftype == 'perl' let ft_args = " --language-force=perl --perl-types=s " elseif ftype == 'php' let ft_args = " --language-force=php --php-types=f " elseif ftype == 'python' let ft_args = " --language-force=python --python-types=f " elseif ftype == 'rexx' let ft_args = " --language-force=rexx --rexx-types=s " elseif ftype == 'ruby' let ft_args = " --language-force=ruby --ruby-types=f " elseif ftype == 'scheme' let ft_args = " --language-force=scheme --scheme-types=f " elseif ftype =~ '\<[cz]\=sh\>' let ft_args = " --language-force=sh --sh-types=f " elseif ftype == 'slang' let ft_args = " --language-force=slang --slang-types=f " elseif ftype == 'tcl' let ft_args = " --language-force=tcl --tcl-types=p " elseif ftype == 'vim' let ft_args = " --language-force=vim --vim-types=f " else return endif let ctags_cmd = g:Fmenu_ctags_path . ctags_args . ft_args let ctags_cmd = ctags_cmd . '"' . filename . '"' " Get the function list let ctags_cmd_output = system(ctags_cmd) if v:shell_error && ctags_cmd_output != "" echohl WarningMsg | echon ctags_cmd_output | echohl None return endif " We are going to add entries to the function menu, so the menu " won't be empty let s:fmenu_empty = 0 " Add the 'B' flag to the 'cpoptions' option let old_cpo = &cpo set cpo+=B " If more than max_menu_items functions are defined in the file, then " create submenus and add max_menu_items functions to each submenu " The number of functions in the ctags output is determined below " like this: Remove the max_menu_items number of entries from the " ctags output. If there are still entries left in the output, the " submenu should be created, otherwise there is no need for a submenu. let p1="\\%([^\n]\\+\n\\)\\{," . g:Fmenu_max_items . "}" let txt = matchstr(ctags_cmd_output, p1) let ctags_cmd_output = substitute(ctags_cmd_output, p1, "", "") let p2 = "\\([^\t]\\+\\)\t\\([^\t]\\+\\)\t\/^\\([^$]*\\)\\\$\/\n" if ctags_cmd_output == "" " Pattern to locate the function definition let fpat = "'" . '\\\V\\\^\3\\\$' . "'" let repl = 'anoremenu F\&unctions.\1 ' let repl = repl . ":call search(" . fpat . ', "w")|' let menu_items = substitute(txt, p2, repl, "g") exe menu_items else let submenu_num = 1 while txt != "" let fpat = "'" . '\\\V\\\^\3\\\$' . "'" let repl = 'anoremenu F\&unctions.Listing' let repl = repl . '\&' . submenu_num . '.\1 ' let repl = repl . ":call search(" . fpat . ', "w")|' let menu_items = substitute(txt, p2, repl, "g") exe menu_items let txt = matchstr(ctags_cmd_output, p1) let ctags_cmd_output = substitute(ctags_cmd_output, p1, "", "") let submenu_num = submenu_num + 1 endwhile endif " Restore the 'cpoptions' settings let &cpo = old_cpo endfunction function! s:Refresh_Function_Menu() call s:Add_Function_Menu(1) endfunction function! s:Sort_Function_Menu(sort_type) let g:Fmenu_sort_type = a:sort_type call s:Add_Function_Menu(1) endfunction amenu F&unctions.Refresh :call Refresh_Function_Menu() amenu F&unctions.Sort\ By.Name :call Sort_Function_Menu("name") amenu F&unctions.Sort\ By.Order :call Sort_Function_Menu("order") amenu F&unctions.-SEP1- : " Automatically add the functions in the current file to the menu augroup FunctionMenuAutoCmds autocmd! autocmd BufEnter * call s:Add_Function_Menu(0) autocmd BufLeave * call s:Remove_Function_Menu() augroup end