parsed.org

Tips by tag: vim

Add this to your .vimrc:

autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete

Try it out:

$ touch index.html
$ vim index.html
type: <ht[CTRL-X][CTRL-O]
autocompleteccsshtmljavascriptphppythonvimvimrcxml
Autocompletion in VIM using TAB by oozy on Apr 25, 2007 03:54 AM

Put this into ~/.vimrc:

fun! InsertTabWrapper()
    let col = col('.') - 1
    if !col || getline('.')[col - 1] !~ '\k'
       return "\<tab>"
    else
       return "\<c-p>"
    endif
endfun

fun! ShiftInsertTabWrapper()
    let col = col('.') - 1
    if !col || getline('.')[col - 1] !~ '\k'
       return "\<s-tab>"
    else
       return "\<c-n>"
    endif
endfun

inoremap <tab> <c-r>=InsertTabWrapper()<cr>
inoremap <s-tab> <c-r>=ShiftInsertTabWrapper()<cr>

:set dictionary+=dict.file
:set dictionary+=%
:set iskeyword+=:
:set complete+=k
autocompletionconfigurationeditorssettingsvivimvimrc
Common RC Settings by http://xinu.myopenid.com/ on Jan 13, 2005 10:56 AM

Some recommended settings for your ~/.vimrc because we all hate tabs (right?):

set sw=4
set ts=4
set sts=4
set expandtab
syntax on
configurationeditorsindentationvimvimrc

If you like working with a dark background and enjoy syntax highlighting but hate the navy blue on black, try putting the following line in your ~/.vimrc:

set background=dark
backgroundconfigurationeditorshighlightingsyntaxvimvimrc
Gvim Configuration by http://xinu.myopenid.com/ on Apr 23, 2008 07:52 AM

On a new windows install I'll always drop in these entries for startup configuration:

" general settings
set sw=4
set ts=4
set et
set nohls

" lhs comments
map ,# :s/^/#/<CR>
map ,/ :s/^/\/\//<CR>
map ,> :s/^/> /<CR>
map ," :s/^/\"/<CR>
map ,% :s/^/%/<CR>
map ,! :s/^/!/<CR>
map ,; :s/^/;/<CR>
map ,- :s/^/--/<CR>
map ,c :s/^\/\/\\|^--\\|^> \\|^[#"%!;]//<CR>

" wrapping comments
map ,* :s/^\(.*\)$/\/\* \1 \*\//<CR>
map ,( :s/^\(.*\)$/\(\* \1 \*\)/<CR>
map ,< :s/^\(.*\)$/<!-- \1 -->/<CR>
map ,d :s/^#//<CR>

" screen location & dimensions
winpos 50 50
set lines=30
set columns=120

" squirrel away backup files
set bdir=c:/backups
set directory=c:/backups

Note: You'll need to create the backup folder before you can use it.

gvimvimvimrc

add these lines to your vimrc and you can read/write .gpg files. passwortd will be prompted by vim. ('ksh' needs to be installed):

augroup gpg
  au!
  autocmd BufReadPre *.gpg set binary noswapfile
  autocmd BufRead *.gpg call s:Decrypt()
  autocmd BufWrite *.gpg call s:Encrypt()
augroup END

function s:Decrypt()
 set shell=ksh
 let s:mykey = inputsecret("Enter passphrase:")
 exe "%! { echo " . escape(s:mykey, "!\"|") . "|& };
  \ gpg -q --no-mdc-warning --passphrase-fd 3 3<&p --decrypt 2>/dev/tty"
 set nobin
 if !nextnonblank(1)
   echohl ErrorMsg
   call input("type ENTER to exit")
   :q!
 endif
endf

function s:Encrypt()
 exe "%! { echo " . escape(s:mykey, "!\"|") . "|& };
  \ gpg -q --passphrase-fd 3 3<&p -sear Fabian -"
endf
encryptiongpgvim
Opening Files in VIM by http://xinu.myopenid.com/ on Apr 22, 2008 05:00 PM

When you're choosing a file to open in vi(m), you can limit your search to a mask:

:e *.pl[tab]

At this point you're only tab'ing through the .pl files.

vivim
Reverse Lines by http://xinu.myopenid.com/ on Jan 15, 2005 05:36 PM

Running this ed command will reverse the lines in the current buffer. This would be useful for logfiles and the like:

:g/^/m0
buffercommandsededitorsvim
Search Highlighting by http://xinu.myopenid.com/ on Nov 28, 2005 08:54 AM

If you're on a dark background terminal, the hightlighting after searching in vim can be maddening. To turn it off for the session, type :set nohls.

backgroundcommandeditorshighlightingsyntaxvim
VIM Positioning by http://xinu.myopenid.com/ on Jun 14, 2008 09:26 PM

If you've got a file open in vim, try the following shortcuts in command mode:

z. = center on current line
zt = make current line the top line
zb = make current line the bottom line
gvimvim
Vim Uppercase by http://xinu.myopenid.com/ on Jan 22, 2008 09:06 AM

To take a series of lines, say from the cursor to the bottom of the file and make them uppercase, the following would be useful:

%,$s/\(.*\)/\U\1/
regexswapuppercasevivim
RSS