Unknown user @38.107.191.101

Tips for Vim

Templates

Vim provides a way to put contents by default on new files, very useful for header filling, in HTML for example. This is very simple, just create a file.html in your ~/.vim/templates/ folder and add this kind of line to your ~/.vimrc

 au bufNewFile *.html 0r ~/.vim/templates/xhtml.html
 au bufNewFile *.css 0r ~/.vim/templates/css.css
 au bufNewFile *.tex 0r ~/.vim/templates/latex.tex
 au bufNewFile title.tex 0r ~/.vim/templates/latex_title_page.tex

Note that the 0r is a zero, not an o!

Spellcheck

Spellchecking is very useful in office tools such as OpenOffice Writer or Microsoft Word, for those who writes texts with Vim, it could be useful to get this feature. You only have to put this to your ~/.vimrc

 augroup filetypedetect
 au BufNewFile,BufRead *.tex setlocal spell spelllang=fr
 augroup END

Here, we only activate spellchecking for *.tex files and parametrize it with french. Errors will appear in red background (or other style with some themes. You'll got suggestion for correction with the z= command. You must have the xx.utf-8.spl for spellchecking and xx.utf-8.sug for suggestions, in your ~/.vim/spell/ folder, where xx is the language code corresponding to the spelllang argument, fr in the example.

You'll find more detailed information on the vim documentation.

~/.vimrc sample

This is a sample of ~/.vimrc file, you'll pick up some things useful to be more productive with Vim.

 " empêche la compatibilité avec vi
 set nocompatible
 
 " fond de couleur noire
 set background=dark
 
 "if ! has("gui_running")
 "  set t_Co=256
 "endif 
 
 
 " coloration syntaxique
 syntax on
 colorscheme desert
 
 " auto indentation
 " set autoindent
 " numéro de ligne
 set number
 " utilisation de la souris
 set mouse=a
 " avertissement par flash (visual bell) plutôt que par bip
 set vb
 
 " surbrillance de la recherche
 set hlsearch "nolhsearch
 " recherche insensible à la casse
 set ignorecase
 
 " tabulation en espace
 set expandtab
 
 " taille de la tabulation
 set ts=2
 set softtabstop=2
 set shiftwidth=2
 
 " active les indentations en fonction du type de fichier
 " FIXME comment changer le tab size <ici>, là c'est 8
 filetype plugin indent on
 
 " fait automatiquement les indentations
 set ai
 set si
 
 " ligne courante mise en valeur
 "set cursorline
 
 " affiche la correspondance des parenthèses
 set showmatch
 
 " tabulations et espaces marqués
 set list
 set listchars=tab:>.,trail:.
 
 " affiche le numéro de colonne et de ligne en bas
 set ruler
 
 " folding
 "set foldmethod=indent
 "set foldlevel=12
 
 " pas de coupure de ligne
 "set nwrap
 
 " correction orthographique sur les fichiers .tex
 augroup filetypedetect
 au BufNewFile,BufRead *.tex setlocal spell spelllang=fr
 augroup END
 
 " templates for new files of some languages
 au bufNewFile *.html 0r ~/.vim/templates/xhtml.html
 au bufNewFile *.css 0r ~/.vim/templates/css.css
 au bufNewFile *.tex 0r ~/.vim/templates/latex.tex
 au bufNewFile title.tex 0r ~/.vim/templates/latex_title_page.tex

Initial author: olivier Last modification date: February the 3rd, 2009 by olivier.