scriptencoding utf8 set encoding=utf8 "set nocompatible ruler laststatus=2 showcmd esckeys wildmenu set nocp ruler ls=2 sc ek wmnu "set noexpandtab tabstop=4 shiftwidth=4 textwidth=0 set noet ts=4 sw=4 tw=0 "This is for global vimrc respect my tw setting. let g:leave_my_textwidth_alone=1 "set autoindent smartindent cindent set ai nosi nocin filetype indent on filetype plugin on "This makes backspace work correctly! "set backspace=2 set bs=2 "This uses short messages. To get the whole message, use ":file!" "set shortmess=at set shm=at "The keys Left, Right, Backspace and Space will wrap to next/previous line. "set whichwrap=<,>,b,s set ww=<,>,b,s,[,] "Syntax highlighting syn on "Highlight search pattern (use :noh to set it off) "set hlsearch set hls "set incsearch ignorecase smartcase set is ic scs "set formatoptions set fo+=or " http://www.lesswatts.org/projects/powertop/known.php#gvim let &guicursor = &guicursor . ",a:blinkon0" set listchars=eol:$,tab:>.,trail:@,extends:>,precedes:< set showbreak=>>\ set sidescroll=10 set cpoptions+=$ set guioptions-=T set nrformats=alpha,hex set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~ set path+=/usr/local/include set history=1000 set viminfo=!,\"500,'50,/50,:500,@500,h "viminfo help:"{{{ " ! - Save and restore global variables that start with uppercase and does not have lower case characters. " " - Maximum number of lines saved for each register. " % - Save and restore buffer list. " ' - Maximum number of edited files for which the marks are remembered. " / - Maximum number of items in search pattern history. " : - Maximum number of items in command-line history. " @ - Maximum number of items in input-line history. " c - Convert viminfo text from/to 'encoding'. " f - Whether file marks need to be stored. " h - Disable the effect of 'hlsearch' when loading viminfo file. " n - Name of the viminfo file. " r - Removable media. List of pathes for which no marks will be saved. "}}} "Autodetect UTF-16 files (Opera saves some html files as UTF-16le) if has("multi_byte") "set fileencodings=ucs-bom,utf-16,utf-16le,latin1 "set fileencodings=ucs-bom,utf-16,utf-16le "I don't know if the next line will hurt, so, I will stick to the previous one. "set fileencodings=ucs-bom,utf-16,utf-16le,utf-8,latin1 endif " From http://fishshell.org/wiki/moin.cgi/Recipes at 2008-01-06 " Why does VIM give error messages when started from fish? " (Thanks to James Vega for this solution) " " When run from the fish shell, VIM gives error messages like: "E484: Can't open file /tmp/v916556/0" " " The problem occurs because VIM expects to be run from a POSIX shell, although this is not mentioned anywhere in the documentation. A workaround is to add the following lines to the your local ~/.vimrc or global /etc/vimrc file: if $SHELL =~ 'bin/fish' set shell=/bin/sh endif " Assuming /bin/sh is a link to a POSIX compliant shell - even minimal shells like 'ash' or 'dash' will do. "FileType autocommands"{{{ "Set textwidth for mail au FileType mail setlocal tw=70 nosi nocin "Disable C Indent for Pascal files au FileType pascal,*.pas,*.dpr setlocal si nocin "Disable most indent for HTML files au FileType html,*.html,*.htm,*.shtml,*.shtm,*.xhtml setlocal ai nocin nosi indentkeys= "Disable most indent for XML files au FileType xml,*.xml,*.xhtml,dtd,*.dtd setlocal ai nocin nosi indentkeys= "Disable some indents for CSS au FileType css,*.css setlocal ai si nocin "Disable C Indent for LaTeX files au FileType tex,plaintex,*.tex setlocal nocin "Set dictionary file for C files au FileType c,*.c setlocal complete+=k~/.vim/c.dic au FileType cpp,*.cpp setlocal complete+=k~/.vim/c.dic au FileType * exec('setlocal dictionary+=~/.vim/dict/' . &filetype) "An autocmd to make vim not break when used for crontab -e "See :help 'backupcopy' and scroll down a bit autocmd FileType crontab set backupcopy=yes augroup filetypedetect "Wiki type (wikipedia) au BufNewFile,BufRead *.wiki setf Wikipedia " au BufNewFile,BufRead *.xhtml setf html au BufNewFile,BufRead *.xhtml setf xml " SecondLife scripts au BufNewFile,BufRead *.lsl setf lsl augroup END "}}} ":help hex-editing"{{{ "if 0 function AutocmdsForBinary() augroup Binary au! au BufReadPre *.bin let &bin=1 au BufReadPost *.bin if &bin | %!xxd au BufReadPost *.bin set ft=xxd | endif au BufWritePre *.bin if &bin | %!xxd -r au BufWritePre *.bin endif au BufWritePost *.bin if &bin | %!xxd au BufWritePost *.bin set nomod | endif augroup END endfunction "endif "}}} "Some colors and background "set background=dark set bg=dark highlight Normal guibg=Black guifg=White "highlight Normal ctermbg=Black ctermfg=Grey highlight Visual gui=reverse guifg=Gray guibg=Black "Folding settings"{{{ highlight Folded term=standout cterm=none ctermfg=7 ctermbg=4 guifg=DarkGrey guibg=#000050 highlight FoldColumn term=standout cterm=none ctermfg=8 ctermbg=4 guifg=White guibg=#000070 set foldmethod=marker set foldtext=MyFoldText() set fillchars=vert:\|,fold:\ "Set default commentstring on C++ files au FileType cpp,*.cpp setlocal commentstring="//%s" "Set folding options for CSS files au FileType css,*.css setlocal foldmethod=marker foldmarker={,} "zS shows folds. zS stands for Show nnoremap zS :let &foldcolumn=&foldcolumn==0?4:0 "This adds leading chars to thestr up to number chars function AddLeading(chars, thestr, number) let a = a:thestr while strlen(a) < a:number let a = a:chars . a endwhile return a endfunction "This removes C and C++ comments from line. function MyFoldText() let line = getline(v:foldstart) let sub = substitute(line, '/\*\s*{{'.'{\d\?\s*\*/\|\(//\)\?\s*{'.'{{\d\?\|^\s\+\|\s\+$', '', 'g') return v:folddashes . '[' . AddLeading(' ', (v:foldend - v:foldstart + 1), 3) . '] ' . sub " return substitute(foldtext(),'//\|^+-','','g') endfunction "}}} "(don't) Configuring print"{{{ function PrintFile(fname) call system("gv " . a:fname) " call system("lpr -Paps1 -C draft:mono:a4:4pps " . a:fname) " My Opera settings: -C hi:4pps:duplex:longbind call delete(a:fname) return v:shell_error endfunc function ConfigurePrinting() "h is the font height set printfont=courier:h8 set printexpr=PrintFile(v:fname_in) set printoptions=paper:A4,left:10mm,right:10mm,top:10mm,bottom:15mm " left:10mm,right:10mm,top:10mm,bottom:15mm " Set margins. Units: in, pt (defined as 1/72 of an inch), mm, pc " (percentage of media size) " " header:{nr} " Number of lines to reserve for the header. Only the first line is " actually. Set 0 to disable header. See also 'printheader' option. " " syntax:{y|n|a} " y/n = Enable/disable syntax highlighting (disabled is faster). " a = Auto (enable it if the printer appears to be able to print color " or grey) " " number:{y|n} " Include line numbers in the printed output. " " wrap:{y|n} " Wrap long lines. " " duplex:{off|long|short} " off = Print on one side. " long = Print on both sides (when possible), bind on long side. " short = Print on both sides (when possible), bind on short side. " " collate:{y|n} " y = 1 2 3, 1 2 3, 1 2 3 " n = 1 1 1, 2 2 2, 3 3 3 " " jobsplit:{y|n} " y = Do each copy as a separate print job. " n = Do all copies in one print job " " portrait:{y|n} " Sets orientation to portrait or landscape. " " paper:{10x14|A3|A4|A5|B4|B5|executive|folio|ledger|legal|letter|quarto| " statement|tabloid} " " formfeed:{y|n} " If yes, form feed character (0x0c) will force next characters being " printed on next page. endfunc "}}} "Set key let mapleader = ']' "This cleans the "highlight search" (only works on GUI) nnoremap :nohlsearch "This makes "Y" to work from the cursor to the end of line (which is more logical, but not Vi-compatible). See :help Y nnoremap Y y$ "Some useful mappings to next/previous error"{{{ nnoremap :cprev vnoremap :cprev inoremap :cprev nnoremap :cnext vnoremap :cnext inoremap :cnext nnoremap :cfirst vnoremap :cfirst inoremap :cfirst nnoremap :clast vnoremap :clast inoremap :clast "}}} "Some useful mappings to next/previous buffer"{{{ nnoremap :bnext vnoremap :bnext inoremap :bnext nnoremap :bprev vnoremap :bprev inoremap :bprev nnoremap :bdelete vnoremap :bdelete inoremap :bdelete "}}} "Some useful digraphs (in addition to default ones)"{{{ dig ?? 191 "This is already mapped to | "dig !! 204 "}}} "Configure TList Plugin (taglist.vim)"{{{ let Tlist_Winwidth=20 let Tlist_Inc_Winwidth=0 "let Tlist_Display_Prototype = 1 let Tlist_Use_SingleClick = 1 let Tlist_Compact_Format = 1 "let Tlist_Exit_OnlyWindow = 1 " F1 -> open/update Tlist window "Shift-F1 -> Close Tlist window nnoremap :if bufwinnr(g:TagList_title) == -1\|Tlistelse\|TlistUpdateendif vnoremap :if bufwinnr(g:TagList_title) == -1\|Tlistelse\|TlistUpdateendif inoremap :if bufwinnr(g:TagList_title) == -1\|Tlistelse\|TlistUpdateendif nnoremap :TlistClose vnoremap :TlistClose inoremap :TlistClose "}}} " Start of Vim Scripting! " Don't cross the line below! "-------------------------------------------------------------------- " --- VimTips --- " {{{ " http://vim.sourceforge.net/tip_view.php?tip_id= "Use the | character to combine more than one command into only one line, like this: ":if has("gui") | echo "oi" | endif " VimTip #1: the super star " {{{ " 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. " }}} " VimTip #37: The basic operation about vim-boolean optionals " {{{ " :set number -> switch the number on " :set nonumber -> switch it off " :set invnumber -> switch it inverse against the current setting " :set number! -> switch it inverse against the current setting " :set number& -> get the default value vim assums " }}} " VimTip #38: Cursor one line at a time when :set wrap " {{{ " 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 gj " nnoremap gk " vnoremap gj " vnoremap gk " inoremap gj " inoremap gk " " What they do is remap the cursor keys to use there `g' equvilant. See :help gj " }}} " VimTip #40: Insert a file " {{{ " 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 " }}} " VimTip #42: Using marks " {{{ " 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 " }}} " VimTip #48: Moving around " {{{ " You can save a lot of time when navigating through the text by using " appropriate movements commands. In most cases the cursor keys, " or are NOT the best choice. " " Here is a selection of some basic movement commands that " hopefully helps you to acquire a taste for more: " " e - move to the end of a word " w - move forward to the beginning of a word " 3w - move forward three words " b - move backward to the beginning of a word " 3b - move backward three words " " $ - move to the end of the line " - same as $ " 0 - move to the beginning of the line " - same as 0 " " ) - jump forward one sentence " ( - jump backward one sentence " " } - jump forward one paragraph " { - jump backward one paragraph " " H - jump to the top of the display " M - jump to the middle of the display " L - jump to the bottom of the display " " 'm - jump to the beginning of the line of mark m " `m - jump to the location of mark m " " G - jump to end of file " 1G - jump to beginning of file " 50G - jump to line 50 " " '' - return to the line where the cursor was before the latest jump " `` - return to the cursor position before the latest jump (undo the jump). " " % - jump to corresponding item, e.g. from an open brace to its " matching closing brace " " For some more interesting movement commands (especially those " for programmers) refer to: " " :help motion.txt " " :help search-commands " }}} " VimTip #49: Switching case of characters " {{{ " To switch the case of one or more characters use the "~", "gU" or "gu" commands. " " Examples: " " ~ - switch case of character under cursor " (in visual-mode: switch case of highlighted text) " " 3~ - switch case of next three characters " " g~~ - switch case of current line " " U - in visual-mode: make highlighted text uppercase " " gUU - make current line uppercase " " u - in visual-mode: make highlighted text lowercase " " guu - make current line lowercase " " gUaw - make current word uppercase " " guaw - make current word lowercase " " For some more examples refer to " " :help ~ " " See also: " " :help simple-change " }}} " VimTip #82: letting variable values be overwritten in a script "{{{ "this is a simple function i wrote to get the value of a variable from three different places (in that order): the current buffer, the global setting or from the script itself. " "this allows me to set a default value for a configuration variable inside my script and the user to change it on a global level by setting the same variable with a g: prepended. then, they can further set it on a per-buffer level by the the b: mechanism. one of the examples for this might be my comments script (not uploaded). i have a variable in there that determines whether comment characters (// for java, for example) are placed the beginning of the line or just before the first-non-blanks in the text. i set up a default in my script: " "let s:comments_hug_start_of_line=0 " comments should hug the text " "that's fine as a default, but if i want to overwrite it for vim scripts, i just put the following in my ftplugin/vim.vim: " "let b:comments_hug_start_of_line=1 " vim comments should hug the first column, always " "" tries to return the buffer-specific value of a variable; if not "" found, tries to return the global value -- if that's not found "" either, returns the value set in the script itself "function! GetVar(varName) " if (exists ("b:" . a:varName)) " exe "let retVal=b:" . a:varName " elseif (exists ("g:" . a:varName)) " exe "let retVal=g:" . a:varName " elseif (exists ("s:" . a:varName)) " exe "let retVal=s:" . a:varName " else " retVal=-1 " endif " return retVal "endfunction " "personally, i never let it get to the -1 state by always having an s: set with SOME default value. "}}} " }}} end vim tips "***********************************************************" " Ctrl+S to Save (only for GUI version) " "***********************************************************" "{{{ function Salvar_setKeys() "Use Ctrl+S to save nnoremap :update vnoremap :update inoremap :update "Ctrl+Alt+S to save all does not work nnoremap :wall vnoremap :wall inoremap :wall endfunc au GUIEnter * call Salvar_setKeys() "}}} "***********************************************************" " Compiling kit - detect file type and compile it with F9 " "***********************************************************" "{{{ "Currently disabled for testing of a better version "TODO: make this works for LaTeX files. How? Exactly the " same way as described in function CompilarLaTeX " {{{ if 0 function CompilarLaTeX() update let caminho = getcwd() cd %:p:h !latex %:t exe 'cd "' caminho '"' unlet caminho endfunc function CompilarC() update let caminho = getcwd() cd %:p:h !gcc -o %:t:r %:t -Wall exe 'cd "' caminho '"' unlet caminho endfunc function CompilarCpp() update let caminho = getcwd() cd %:p:h !gpp -o %:t:r %:t -Wall exe 'cd "' caminho '"' unlet caminho endfunc function Executar() let caminho = getcwd() cd %:p:h !./%:t:r exe 'cd ' caminho unlet caminho endfunc " ==# significa Match Case " ==? significa Ignore Case " == depende do valor de 'ignorecase' function CompilarEsteArquivo() let extensao = expand('%:e') if extensao ==# 'tex' echo 'Compilando LaTeX' call CompilarLaTeX() elseif extensao ==# 'c' echo 'Compilando programa C' call CompilarC() elseif extensao ==# 'cpp' echo 'Compilando programa C++' call CompilarCpp() else echo 'Unrecognized extension' endif endfunc endif " }}} function CompilarEsteArquivo() if &makeprg."a" !=# "a" make else echoerr "Make program is not defined. Use ':set makeprg' to define one." endif endfunc function SetMakeprgIfExistsMakefile() if filereadable(expand("%:p:h")."/makefile") || filereadable(expand("%:p:h")."/Makefile") set makeprg=make endif endfunc au FileType c,*.c set makeprg=~/bin/ccomp\ %:p:r au FileType cpp,*.cpp set makeprg=~/bin/cppcomp\ %:p:r au FileType c,*.c,cpp,*.cpp call SetMakeprgIfExistsMakefile() "F9 compiles the current file nnoremap :call CompilarEsteArquivo() vnoremap :call CompilarEsteArquivo() inoremap :call CompilarEsteArquivo() "}}} "***********************************************************" " 'list' toggle with z " "***********************************************************" "{{{ function ToggleList() set list! echo &list ? 'list' : 'nolist' endfunc nnoremap z :call ToggleList() "}}} "***********************************************************" " Wrap toggle with F12 key " "***********************************************************" "{{{ function ToggleWrap() set wrap! echo &wrap ? 'wrap' : 'nowrap' endfunc "F12 toggles wrap (Thanks to Alexandre Moreira) nnoremap :call ToggleWrap() vnoremap :call ToggleWrap() inoremap :call ToggleWrap() "}}} "***********************************************************" " Horizontal scrollbar toggle with Shift+F12 key " "***********************************************************" "{{{ function ToggleHorizontalScrollbar() "set guioptions+=b if &go =~# "b" set go-=b else set go+=b endif endfunc function ToggleHorizontalScrollbar_setKeys() "Shift+F12 toggles the horizontal scrollbar nnoremap :call ToggleHorizontalScrollbar() vnoremap :call ToggleHorizontalScrollbar() inoremap :call ToggleHorizontalScrollbar() endfunc au GUIEnter * call ToggleHorizontalScrollbar_setKeys() "}}} "***********************************************************" " Make current window half of available size with ^We or ^WE" "***********************************************************" "{{{ function MakeWindowHalfWidth() exec 'vertical resize' . &columns/2 endfunc function MakeWindowHalfHeight() exec 'resize' . &lines/2 endfunc "Think E graphically, like two windows split one on top of another. "You may think also 'e' and 'E' as 'equal size' nnoremap e :call MakeWindowHalfWidth() nnoremap E :call MakeWindowHalfHeight() "}}} "***********************************************************" " VimTip #2: easy edit of files in the same directory " "***********************************************************" "{{{ if has("unix") map ,e :e =expand("%:p:h") . "/" else map ,e :e =expand("%:p:h") . "\" endif "}}} "***********************************************************" " Abbreviations, by filetype " "***********************************************************" "{{{ " STILL IN BETA TESTING!!! "TODO: Make a script to map Ctrl+Space and to work like RHIDE: " Ctrl+Space will look for last word (or last two chars) " and expand it. function AbbrForCandCpp() ab #d #define ab /*** /************************************************************/ ab print_ printf("\n"); ab fori for(i=0; i<; i++){} ab forj for(j=0; j<; j++){} ab fork for(k=0; k<; k++){} ab struct_ typedef struct Name {} Name; ab re_ return ab main( int main(int argc, char *argv[]){return 0;} endfunc function AbbrForC() call AbbrForCandCpp() ab #i #include <.h> ab {{{ /* {{{ */ ab }}} /* }}} */ endfunc function AbbrForCpp() call AbbrForCandCpp() ab #i #include <> ab {{{ // {{{ ab }}} // }}} endfunc function AbbrForJava() ab fori for(int i=0; i<.length; i++){} ab forj for(int j=0; j<.length; j++){} ab fork for(int k=0; k<.length; k++){} ab /*** /************************************************************/ ab #i import ab {{{ // {{{ ab }}} // }}} endfunc "These don't work because of '/' function AbbrForLaTeX() ab /sec \section{} ab /sub \subsection{} ab /cha \chapter{} ab /eqnarray \begin{eqnarray}\end{eqnarray} ab /array \begin{array}\end{array} ab /enum \begin{enumerate}\end{enumerate} ab /itemize \begin{itemize}\end{itemize} endfunc "au FileType tex,*.tex call AbbrForLaTeX() au FileType c,*.c call AbbrForC() au FileType cpp,*.cpp call AbbrForCpp() au FileType java,*.java call AbbrForJava() "}}}