Archive for the ‘ FreeBSD ’ Category

## Writing with Emacs and AucTeX part 1

The purpose of this post is to explain my setup for GNU/Emacs I made during the period I got a try to it to write files compiled with XeLaTeX. First, here is not a place where I want to restart the childish “war editor”. Like the “FreeBSD vs Linux”, it would make no sense. Be sure that if you find a post about Emacs criticizing Vim, even if they are hosted by websites which seems serious, you should not pay attention to them. Of course, in these posts like, say, “Emacs: an advertisement” at charlietanksley.net, some criticize the “unin­tu­itive way that Vim forces you to move around”. The only advice someone should tell is : make your own choice after trying both text editors. Also, I personally recommend Vim.

1. If you plan to use Emacs, since I had problem with Ubuntu 10.04, I recommend not to install it from you package manager, but from the official website. The download link is the following :

choose emacs-23.2.tar.bz2

f you are not familiar with Unix command, then save your emacs version in you home (/home/username, where username is the name of your computer). To install it, you will have to use the terminal (press alt+F2 and enter gnome-terminal in the prompt). Then, enter the following commands :

cd ~ tar xjvf emacs-23.2.tar.bz2 cd emacs-23.2 ./configure make sudo make install

The installation will take some time to process.

2. After the installation has completed, you will have to download all the files I have put at Github. To do so, you will have to use the terminal (with Ubuntu, press ctrl+t and gnome-terminal will appear), to install git if you don’t have it yet, and to download all the files at github. To do so, copy-paste the following, and type enter after all new lines :
cd ~ sudo apt-get instal git git 

Notice that my .emacs.d contains several plugins, such as yasnippet, completion-ui, autopairs, etc.

Finally, I will make a short description of my file init.el, important to be aware of all configurations I have made to make emacs work like I wanted :

;;##################################################################################################
;;##################################################################################################

; LaTeX

;;##################################################################################################

; ——————————————————————————————————————
; ——————————————————————————————————————
(require ‘tex-site)
(require ‘tex-style)
; ——————————————————————————————————————
; To turn on RefTeX Minor Mode for all LaTeX files, and other
; ——————————————————————————————————————
(add-hook ‘LaTeX-mode-hook ‘turn-on-reftex) ; with AUCTeX LaTeX mode

‘(lambda ()
(setq TeX-open-quote “«~”)
(setq TeX-close-quote “~»”)
(auto-fill-mode t)
))

; ——————————————————————————————————————
; Smart quotes
; ——————————————————————————————————————
(setq TeX-open-quote “<<“) (setq TeX-close-quote “>>”)

; ——————————————————————————————————————
;LaTeX-math and other usefull stuff
; see http://www.emacswiki.org/emacs/AUCTeX
; ——————————————————————————————————————

;;; ———————— dictionnaire – correction orthographique ———–
;(setq-default ispell-program-name “hunspell”)

; (lambda ()
; (flyspell-mode 1)
; (ispell-change-dictionary “francais”)
; (turn-on-auto-fill)
;))
;————————————————————————————————–
; completion, style file, or multi-file stuff work
;————————————————————————————————–
(setq TeX-auto-save t)
(setq TeX-parse-self t)
;————————————————————————————————–
;;Mode PDFLatex par défaut ou non
;————————————————————————————————–
(setq TeX-PDF-mode t); pour mettre par défaut décommenter cette ligne et commenter celle du dessous

;————————————————————————————————–
;;Visualiseurs
;————————————————————————————————–
(setq TeX-output-view-style (quote (
(“^pdf$” “.” “evince %o”) (“^ps$” “.” “gv %o”)
(“^dvi$” “.” “xdvi %o”) ))) (setq tex-dvi-view-command “xdvi”) (setq tex-dvi-print-command “dvips”) (setq tex-alt-dvi-print-command “dvips”) ;————————————————————————————————– ;; Pour aller a la ligne automatiquement ;————————————————————————————————– (turn-on-auto-fill) ; —————————————————————————————————————— ; Autopairs ;see http://autopair.googlecode.com/svn/trunk/autopair.el ; —————————————————————————————————————— (add-to-list ‘load-path “~/.emacs.d/lisp”) (require ‘autopair) (autopair-global-mode) ;; to enable in all buffers ;see http://www.emacswiki.org/emacs/AutoPairs#Discussion ; ————————————————- (setq skeleton-pair t) ; enable pairing ; —————————————————————————————————————— ; master file ; —————————————————————————————————————— (setq-default TeX-master nil) TeX-master nil ;; ;;; ———————— Template ——————————- ;; (setq load-path (cons (expand-file-name “~/.emacs.d/lisp”) ;; load-path)) ;; (require ‘template) ;; (template-initialize) ;; ;;;; If you don’t want to use yasnippet, look download the tarball here : ;; ;;;; voir http://emacs-template.sourceforge.net/ ; —————————————————————————————————————— ; Wrapping the region in double quotes ; —————————————————————————————————————— (defadvice TeX-insert-quote (around wrap-region activate) (cond (mark-active (let ((skeleton-end-newline nil)) (skeleton-insert (nil ,TeX-open-quote _ ,TeX-close-quote) -1))) ((looking-at (regexp-opt (list TeX-open-quote TeX-close-quote))) (forward-char (length TeX-open-quote))) (t ad-do-it))) (put ‘TeX-insert-quote ‘delete-selection nil) ; —————————————————————————————————————— ; Inserting and wrapping single quotes ; —————————————————————————————————————— (defun TeX-insert-single-quote (arg) (interactive “p”) (cond (mark-active (let ((skeleton-end-newline nil)) (skeleton-insert (nil ? _ ?’) -1))) ((or (looking-at “\\<“) (looking-back “^\\|\\s-\\|”)) (insert “”)) (t (self-insert-command arg)))) (add-hook ‘LaTeX-mode-hook ‘(lambda () (local-set-key “‘” ‘TeX-insert-single-quote))) ; —————————————————————————————————————— ;;set xetex mode in tex/latex ; —————————————————————————————————————— (add-hook ‘LaTeX-mode-hook (lambda() (add-to-list ‘TeX-command-list ‘(“XeLaTeX” “%xelatex%(mode)%’ %t” TeX-run-TeX nil t)) (setq TeX-command-default “XeLaTeX”) (setq TeX-save-query nil) (setq TeX-show-compilation t) )) ;———————————————————————————————— ;Whizzy TeX ;———————————————————————————————— ;; (setq my-toggle-whizzy-count 0) ;; (defun my-toggle-whizzy-mode () ;; (interactive) ;; (if (= (mod my-toggle-whizzy-count 2) 0) ;; (progn ;; (whizzytex-mode) ;; (message “WhizzyTeX on”)) ;; (progn ;; (whizzy-mode-off) ;; (kill-buffer (concat “*” (buffer-name) “*”)) ;; (message “WhizzyTeX off”))) ;; (setq my-toggle-whizzy-count (+ my-toggle-whizzy-count 1))) ;; (add-hook ‘LaTeX-mode-hook ;; (lambda () ;; (define-key LaTeX-mode-map (kbd “”) ‘my-toggle-whizzy-mode))) This first part load AucTeX when a .tex file is opened, turn on reftex, enable hook for math, turn on pdf by default instead of dvi, command AucTeX to use evince as pdf viewer, gv for postscript and xdvi for dvi, automatically close bracket or complete the other bracket once you have opened one, etc. Notice that some things which you might think useful are commented, such as whizzy tex and flyspell. Therefore you will have to uncomment it if you want to use it. One other important thing for me is to unable compilation for XeLaTeX. For this reason, XeLaTeX is the default setting. ;——————————————————————————— ;Yasnippet ;; Auto completion / snippets (add-to-list ‘load-path “~/.emacs.d/lisp/yasnippet.el”) (require ‘yasnippet) (setq yas/root-directory “~/.emacs.d/snippets”) (yas/load-directory yas/root-directory) (yas/global-mode) (define-key global-map [f6] ‘yas/expand) (require ‘dropdown-list) ;; (setq yas/prompt-functions ‘(yas/dropdown-prompt ;; yas/ido-prompt ;; yas/completing-prompt)) Yasnippet is used by default. For this reason, if you want to use it and want to know what are the files available, just look at the menu : ;;################################################################################################## ;; ;; GNUPlot ;;################################################################################################## (add-to-list ‘load-path “~/emacs.d/lisp/”) (autoload ‘gnuplot-mode “gnuplot” “gnuplot major mode” t) (autoload ‘gnuplot-make-buffer “gnuplot” “open a buffer in gnuplot mode” t) ;; this line automatically causes all files with the .gp extension to ;; be loaded into gnuplot mode (setq auto-mode-alist (append ‘((“\\.gp$” . gnuplot-mode)) auto-mode-alist))

;; This line binds the function-9 key so that it opens a buffer into
;; gnuplot mode
(global-set-key [(f9)] ‘gnuplot-make-buffer)

;;##################################################################################################
;; key board / input method settings
;;##################################################################################################

;————————————————————————————————–
;; key board / input method settings
(setq locale-coding-system ‘utf-8)
(set-terminal-coding-system ‘utf-8)
(set-keyboard-coding-system ‘utf-8)
(set-language-environment ‘UTF-8) ; prefer utf-8 for language settings
(load-library “iso-transl”) ; for accent ^
;see http://tldp.org/HOWTO/Keyboard-and-Console-HOWTO-12.html
;http://www.docmirror.net/fr/linux/howto/hardware/Keyboard-and-Console-HOWTO/Keyboard-and-Console-HOWTO-8.html
;http://www.faqs.org/docs/Linux-HOWTO/Keyboard-and-Console-HOWTO.html
;(iso-accents-customize french)
;;; Pour le clavier
;(iso-accents-mode)

;————————————————————————————————–
;Keyboard shortcuts
;————————————————————————————————–
(require ‘redo)
(define-key global-map (kbd “C-_”) ‘undo)
(define-key global-map (kbd “C-x C-_”) ‘redo)
;if you want to keep the C-w, M-w, and C-y original settings, there is a way is to bind cut,
;copy and past keys by using the default X11 :
;http://www.emacswiki.org/emacs/CopyAndPaste
;; (global-set-key [(shift delete)] ‘clipboard-kill-region)
;; (global-set-key [(control insert)] ‘clipboard-kill-ring-save)
;; (global-set-key [(shift insert)] ‘clipboard-yank)

;;######################################################################################################
;;######################################################################################################
;————————————————————————————————–
;————————————————————————————————–
(tool-bar-mode -1)
(toggle-scroll-bar -1)
;(set-scroll-bar-mode ‘right) ;;スクロールバーを右に表示
;————————————————————————————————–
;menu avec les buffer dans une tabbar
; thanks to http://www.emacswiki.org/emacs/TabBarMode
;————————————————————————————————–
(require ‘tabbar)
(tabbar-mode 1)

;; the following is taken from http://d.hatena.ne.jp/alfad/20100425/1272208744
;; 左に表示されるボタンを無効化
;———————————–
;(setq tabbar-home-button-enabled “”)
;(setq tabbar-scroll-left-button-enabled “”)
;(setq tabbar-scroll-right-button-enabled “”)
(setq tabbar-scroll-left-button-disabled “”)
(setq tabbar-scroll-right-button-disabled “”)

;; Firefoxライクなキーバインドに
;———————————–
(global-set-key [(f8)] ‘tabbar-forward)
(global-set-key [(f7)] ‘tabbar-backward)

;all tabs is just one group
;———————————–
(setq tabbar-buffer-groups-function
(lambda ()
(list “All”))) ;; code by Peter Barabas

;————————————————————————————————–
; one more item n the menu for new files
;————————————————————————————————–

:help “Specify a new file’s name, to edit the file”))

;————————————————————————————————–
;; A list of recent files
;————————————————————————————————–

(require ‘recentf)
(setq recentf-exclude ‘(“^/ftp.*” “^/ssh.*” “^/private.*” ))
(setq recentf-save-file “~/.emacs.d/recentf”)
(recentf-mode 1)

;; GS-05/07/2006-12:15
;; http://www.emacswiki.org/cgi-bin/wiki/RecentFiles#toc6
(defun recentf-interactive-complete ()
“find a file in the recently open file using iswitchb for completion”
(interactive)
(let* ((all-files recentf-list)
(file-assoc-list (mapcar (lambda (x) (cons (file-name-nondirectory x) x)) all-files))
(filename-list (remove-duplicates (mapcar ‘car file-assoc-list) :test ‘string=))
(iswitchb-make-buflist-hook
(lambda ()
(setq iswitchb-temp-buflist filename-list)))
(filename (iswitchb-read-buffer “Find Recent File: “))
(result-list (delq nil (mapcar (lambda (x) (if (string= (car x) filename) (cdr x))) file-assoc-list)))
(result-length (length result-list)))
(find-file
(cond
((= result-length 0) filename)
((= result-length 1) (car result-list))
( t
(let ( (ido-make-buffer-list-hook
(lambda ()
(setq iswitchb-temp-buflist result-list))))
))))

;; to open recent files with keyboard
;;(global-set-key “\C-x\C-r” ‘recentf-open-files-compl)
(global-set-key “\C-x\C-r” ‘recentf-interactive-complete)

;————————————————————————————————–
;; the minibuffer
;————————————————————————————————–
(setq
enable-recursive-minibuffers nil ;; allow mb cmds in the mb
max-mini-window-height .25 ;; max 2 lines
minibuffer-scroll-window nil
resize-mini-windows nil)

;(icomplete-mode t) ;; completion in minibuffer
;; (setq
;; icomplete-prospects-height 1 ;; don’t spam my minibuffer
;; icomplete-compute-delay 0) ;; don’t wait
;; (require ‘icomplete+ nil ‘noerror) ;; drew adams’ extras

The first part is for Gnuplot, then for the encoding (utf-8). Notice that at the line 211, I load something to get the dead key working for accent circumflex with an azerty keyboard. Also, I have a shortcut to undo and redo an action, a setup for the menu, the toolbar and the scrollbar, a setup for the tabbar, etc.

;;################################################################################################
;; FULLSCREEN : appuyer sur F11
;;thanks to http://www.emacswiki.org/emacs/FullScreen
;;################################################################################################

; ———————————————————————————–
;F11 is for fullscreen
; ———————————————————————————–
(defun fullscreen (&optional f)
(interactive)
(set-frame-parameter f ‘fullscreen
(if (frame-parameter f ‘fullscreen) nil ‘fullboth)))

(global-set-key [f11] ‘fullscreen)

; ———————————————————————————–
;Send X Messages to the Window Manager
; ———————————————————————————–
(defun fullscreen ()
(interactive)
(x-send-client-message nil 0 nil “_NET_WM_STATE” 32
‘(2 “_NET_WM_STATE_FULLSCREEN” 0)))

; ———————————————————————————–
; fullscreen mode
; ————————————————————————————–
(run-with-idle-timer 0.1 nil ‘fullscreen)

; —————————————————————————————–
;To maximize the window only, uncomment
; —————————————————————————————–
(defun fullscreen (&optional f)
(interactive)
(x-send-client-message nil 0 nil “_NET_WM_STATE” 32
‘(2 “_NET_WM_STATE_MAXIMIZED_VERT” 0))
(x-send-client-message nil 0 nil “_NET_WM_STATE” 32
‘(2 “_NET_WM_STATE_MAXIMIZED_HORZ” 0)))

;;#################################################################################################
;; MOUSE, CURSOR
;;#################################################################################################

(mouse-wheel-mode t)
(setq scroll-conservatively 10000)

;————————————————————————————————–
;; If you like to get a scroll one line at a time (less “jumpy” than defaults), uncomment
;;thanks to http://www.emacswiki.org/emacs/SmoothScrolling
;————————————————————————————————–
; (setq mouse-wheel-scroll-amount ‘(1 ((shift) . 1))) ;; one line at a time

(setq mouse-wheel-progressive-speed nil) ;; don’t accelerate scrolling
; (setq mouse-wheel-progressive-speed true) ;;accelerate scrolling

;(setq mouse-wheel-follow-mouse ‘t) ;; scroll window under mouse

;(setq scroll-step 1) ;; keyboard scroll one line at a time
;(setq scroll-step 0) ;; keyboard don’t scroll one line at a time

;————————————————————————————————–
; Molette de la souris
;————————————————————————————————–
(defun up-slightly () (interactive) (scroll-up 5))
(defun down-slightly () (interactive) (scroll-down 5))
(global-set-key [mouse-4] ‘down-slightly)
(global-set-key [mouse-5] ‘up-slightly)
(defun up-one () (interactive) (scroll-up 1))
(defun down-one () (interactive) (scroll-down 1))
(global-set-key [S-mouse-4] ‘down-one)
(global-set-key [S-mouse-5] ‘up-one)
(defun up-a-lot () (interactive) (scroll-up))
(defun down-a-lot () (interactive) (scroll-down))
(global-set-key [C-mouse-4] ‘down-a-lot)
(global-set-key [C-mouse-5] ‘up-a-lot)

;————————————————————————————————–
;; curseur en barre et non clignotant
;————————————————————————————————–
;;(setq cursor-type ‘bar) -> default-frame-alist
;;(set-cursor-color “black”)

;————————————————————————————————–
; Laisser le curseur en place lors d’un défilement par pages.
; Par défaut, Emacs place le curseur en début ou fin d’écran
; selon le sens du défilement.
;————————————————————————————————–

;(setq scroll-preserve-screen-position t)

;————————————————————————————————–
;; Use box cursor for overwrite-mode, and red cursor for quail active input.
;;thanks to http://www.jurta.org/en/emacs/dotemacs
;————————————————————————————————–
(defun my-change-cursor ()
“Change cursor color and type depending on insertion mode and input method.”
(set-cursor-color
(cond (current-input-method “red3”) ; “AntiqueWhite4”
((eq (frame-parameter (selected-frame) ‘background-mode) ‘dark)
“DarkGrey”)
(t “black”)))
(setq default-cursor-type ;; set-cursor-type
(cond (overwrite-mode ‘box)
(t ‘bar))))

;;###########################################################################################################
;; Title bar
;;###########################################################################################################

(setq frame-title-format ‘(buffer-file-name “Emacs: %b (%f)” “Emacs: %b”)) ;CHEMIN COMPLET DANS LA BARRE DE TITRE

;————————————————————————————————–
;; de jolis noms pour les buffers sur un meme *nom* de fichier
;————————————————————————————————–
(require ‘uniquify)
(setq uniquify-buffer-name-style ‘post-forward-angle-brackets)

Here is the setup for fullscreen mode, the mouse, the cursor, the title.

;;##################################################################################################
;;Writing
;;##################################################################################################

;——————————————————————————-
;; Complétion automatique
;;Work in progress
;;see http://www.dr-qubit.org/emacs.php
;——————————————————————————-
;—————————————————————–
(abbrev-mode t) ; completion automatique
(global-set-key (quote [tab]) (quote dabbrev-expand))

(setq default-abbrev-mode t)
(define-abbrev-table ‘global-abbrev-table ‘(
(“\.\.\.” “\ldots” nil)
(“letat” “l’État” nil)
(“comeur” “Commission Européenne” t 4)
(“coneur””Conseil Européen” nil)
))

;; ;——————————————————————
;; ;to enable or disable completion-ui, comment or uncomment the following lines
(require ‘completion-ui)
(auto-completion-mode)
;(global-set-key [?\M-/] ‘complete-dabbrev)

;; ;——————————————————————-
;; ;auto-complete-mode

;; (setq dabbrev-case-replace nil)
;; (require ‘auto-complete-config)
;; (auto-complete-mode)
;; (ac-config-default)

;; ;(require ‘auto-complete)
;; ;(setq ac-auto-start 1)
;; ;(require ‘auto-complete-config)
;; (require ‘popup)
;; ;(require ‘fuzzy)
;; (global-auto-complete-mode t)
;; (setq ac-auto-start t)

;; ;————————————————————————
;predictive
;; predictive install location
;; ;; dictionary locations
;; (require ‘predictive)
;; “Turn on Predictive Completion Mode.” t)

Here is the setup for autocompletion. You will notice that there are several ways to get autocompletion with Emacs. The first, really great (though all features that I discussed here might be great), is the abbrev mode. So if you often type a word, define an abbreviation. Say, a french word, “l’État”. Writing l’État is painful with an azerty keyboard : you have to press l”‘”, then the caps lock key, then press “é”, then again caps lock key, and then “tat”. Defining letat allow you to get l’État when typing space after to have writen letat. Really great.

Completion-ui is another really great completion utility for emacs. For more details, look at the Emacs wiki. The other ways of completion, such as “predictive mode”, are also well explained in the Emacs wiki, therefore I won’t describe them.

;——————————————————————————-
;; SUPPRIME TOUS LES ESPACES EN FIN DE LIGNE
;——————————————————————————-

;——————————————————————————-
;Wrap Long Lines By Word Boundary
;——————————————————————————-
(global-visual-line-mode 1) ; 1 for on, 0 for off.

;——————————————————————————-
; TEXT AND AUTO FILL MODE
;——————————————————————————-

(setq default-major-mode ‘text-mode)

;——————————————————————————-
;; PARENTHESE MATCHING, PERMET DE VERIFIER AU FUR ET À MESURE DE LA FRAPPE QUE
;; L’ON FERME BIEN CE QUE L’ON OUVRE, AUSSI BIEN POUR LES PARENTHÈSES QUE LES
;——————————————————————————-

(require ‘paren)
(show-paren-mode 1)
(setq-default hilight-paren-expression t)

Here are some useful settings for editing, like the feature to automatically format your text, insert the closing parenthesis when you have inserted the opening one, etc.

;——————————————————————————-
;;TIME STAMPS
;;thanks to http://www.djcbsoftware.nl/dot-emacs.html
;——————————————————————————-
;;Emacs permet d’insérer automatiquement des time stamps, typiquement
;;pour indiquer la date de dernière modification d’un fichier.
;;Pour utiliser les time stamps, indiquer dans les 8 premières lignes d’un fichier ceci :
;;Time-stamp:
(setq ;; when there’s “Time-stamp: ” in the first 10 lines of the file
time-stamp-active t ; do enable time-stamps
time-stamp-line-limit 10 ; check first 10 buffer lines for Time-stamp:
time-stamp-format “%04y-%02m-%02d %02H:%02M:%02S (%u)”) ; date format
(add-hook ‘write-file-hooks ‘time-stamp) ; update when saving

If you want to have the time displayed at the beginning of your file, insert “Time-stamp: “, and save your file. It will add automatically the date.

;;################################################################################
;; File browser
;;################################################################################

(defun my-dired-mode-init ()
(hl-line-mode 1)
(setq truncate-lines t))
;; Image viewer.
(when (require ‘image-mode nil)
(defun my-image-next-by-number ()
(interactive)
(let ((file-name (buffer-file-name))
base num suffix
num-width fmt)
(unless (string-match
“^\$$.*[^0-9-]\$$?\$$?:[0-9]+-\$$?\$$[0-9]+\$$\$$\\.[^.]+\$$?$” file-name) (error “Improper file name”)) (setq base (match-string 1 file-name)) (setq num (match-string 2 file-name)) (setq suffix (match-string 3 file-name)) (setq num-width (length num)) (setq fmt (format “%%s%%0%dd%%s” num-width)) (setq num (1+ (string-to-number num))) (setq file-name (format fmt base num suffix)) (unless (file-exists-p file-name) (setq fmt (format “%%s%%0%dd-*%%s” num-width)) (setq file-name (format fmt base num suffix)) (setq file-name (file-expand-wildcards file-name)) (if file-name (setq file-name (car file-name)) (error “No more files”))) (find-alternate-file file-name))) (defun my-image-scroll-up-or-next-by-number () (interactive) (let* ((image (image-get-display-property)) (edges (window-inside-edges)) (win-height (- (nth 3 edges) (nth 1 edges))) (img-height (ceiling (cdr (image-size image))))) (if (= (window-end) (point-max)) (goto-char (point-max)) (View-scroll-page-forward-set-page-size)))) (define-key view-mode-map [(meta up)] (lambda () (interactive) (if (<= (window-start) (point-min)) (goto-char (point-min)) (View-scroll-page-backward-set-page-size)))) ;; qv http://thread.gmane.org/gmane.emacs.devel/111117/focus=112357 (defadvice View-scroll-line-forward (after my-View-scroll-line-forward activate) "Fix point position to be at the bottom line." (move-to-window-line -1) (beginning-of-line)) )) ;;; doc-view ;——————————————————————————- (eval-after-load "doc-view" '(progn ;; Shift-Space to scroll back. (define-key doc-view-mode-map [?\S- ] 'doc-view-scroll-down-or-previous-page) )) ;;; image ;——————————————————————————- ;; This is now in image-dired-cmd-create-standard-thumbnail-command' ;; (used by C-t C-t' in Dired). (defun my-make-thumbnail (file) (let* ((image-file (concat "file://" (expand-file-name file))) (thumb-file (expand-file-name (concat "~/.thumbnails/normal/" (md5 image-file) ".png"))) (file-attrs (file-attributes file)) (modif-time (float-time (nth 5 file-attrs)))) (unless (file-exists-p thumb-file) (shell-command (mapconcat 'identity (list "convert" (format "\"%s\"" file) ;; "-size 128×128" (format "-set \"Description\" \"Thumbnail of %s\"" image-file) (format "-set \"Software\" \"ImageMagick, GNU Emacs %s\"" emacs-version) (format "-set \"Thumb::URI\" \"%s\"" image-file) (format "-set \"Thumb::MTime\" \"%.0f\"" modif-time) "-set \"Thumb::Size\" \"%b\"" "-set \"Thumb::Image::Width\" \"%w\"" "-set \"Thumb::Image::Height\" \"%h\"" "-set \"Thumb::Image::Mimetype\" \"image/jpeg\"" "-resize 128×128" ;; "-resize 64×64" "+profile \"*\"" "-type TrueColorMatte" ;; "-sharpen 11" ; TRY THIS (format "png:\"%s\"" thumb-file)) " "))) thumb-file)) ;;; thumbs ;——————————————————————————- (defadvice thumbs-mode (after my-thumbs-mode activate) (toggle-truncate-lines -1)) ;;; dired ;——————————————————————————- (require 'dired-x) ;; HINT: the following expression is useful for M-(' dired-mark-sexp' ;; to mark files by their type: ;; (string-match "perl" (shell-command-to-string (concat "file " name))) ;; Uses editor/viewer info from /usr/bin/run-mailcap (defun my-dired-run-find-file () "My view file for dired." (interactive) (let* ((file (dired-get-filename))) (cond ((let* ((command (and (functionp 'mm-mime-info) (mm-mime-info (mm-extension-to-mime (file-name-extension file)))))) (if (and command (stringp command)) ;; always return t' for cond' (or (ignore (shell-command (concat (format command file) "&"))) t)))) ;; ((string-match "\\.html?$" file) (w3-open-local file))
((string-match "\\.html?$" file) (cond ((fboundp 'w3m-goto-url-new-session) (w3m-find-file-new-session file)) ((fboundp 'browse-url) (browse-url file)))) ((string-match "\\.elc?$" file)
((string-match "\\.info?$" file) (info file)) (;; (or (string-match "\\.jpe?g$" file)
;; (string-match "\\.gif$" file) ;; (string-match "\\.pdf$" file))
(let* ((file-list (list (dired-get-filename)))
(command (dired-guess-default file-list)))
(if (listp command)
(setq command (car command)))
(if command
(shell-command
(dired-shell-stuff-it command file-list nil 0)))))
(t
(message file)))))

(define-key dired-mode-map [(control return)] 'my-dired-run-find-file)

;; Add different directory sorting keys
;——————————————————————————-
(mapc (lambda (elt)
(define-key dired-mode-map (car elt)
(lambda ()
(interactive)
'(([(control f3)] "" "by name")
([(control f4)] " -X" "by extension")
([(control f5)] " -t" "by date")
([(control f6)] " -S" "by size")
([(control shift f3)] " -r" "by reverse name")
([(control shift f4)] " -rX" "by reverse extension")
([(control shift f5)] " -rt" "by reverse date")
([(control shift f6)] " -rS" "by reverse size")))

;; The following two bindings allow to open file for editing by [f4],
;; and return back to dired without killing the buffer.
;;——————————————————————————–
(define-key dired-mode-map [f3] 'dired-find-file) ;; 'dired-view-file
(define-key global-map [f3] 'dired-jump)

(define-key dired-mode-map [(shift f4)] 'dired-count-sizes)

Some settings for the dired mode (to display the mode, press alt+x in emacs and write dired in the bottom).

;;##################################################################################################
;highlighting
;;##################################################################################################
;;——————————————————————————–
;; Syntaxe highlighting pour tout
;;——————————————————————————–

(require ‘font-lock)
(setq initial-major-mode
(lambda ()
(text-mode)
(font-lock-mode)))
(setq font-lock-mode-maximum-decoration t
font-lock-use-default-fonts t
font-lock-use-default-colors t)

;;——————————————————————————–
;; hl-line: highlight the current line
;;(thanks to http://www.djcbsoftware.nl/dot-emacs.html)
;;——————————————————————————–
(when (fboundp ‘global-hl-line-mode)
(global-hl-line-mode t)) ;; turn it on for all modes by default

;;——————————————————————————–
;; ACTIVER LA COLORATION SYNTAXIQUE
;;——————————————————————————–
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)
(setq font-lock-maximum-size nil)
;;——————————————————————————–
;; SURLIGNAGE D’UNE RÉGION SÉLECTIONNÉE ET EFFACER
;;——————————————————————————–

(transient-mark-mode 1) ; highlight text selection
(delete-selection-mode 1) ; delete seleted text when typing

Here are settings for highlighting. You will notice that the line where your cursor is is highlighted. I prefer to highlight a line than to get an annoying blincking cursor.

;;##################################################################################################
;;Sauvegardes, bookmarks, etc
;;##################################################################################################
;;——————————————————————————–
;; bookmarks
;;——————————————————————————–
(setq bookmark-default-file “~/.emacs.d/data/bookmarks” ;; bookmarks
bookmark-save-flag 1) ;; autosave each change

;;——————————————————————————–
;; saveplace: save location in file when saving files
;;——————————————————————————–
(setq save-place-file “~/.emacs.d/cache/saveplace”)
(setq-default save-place t) ;; activate it for all buffers
(require ‘saveplace) ;; get the package

;;——————————————————————————–
;; savehist: save some history
;;——————————————————————————–
‘(search ring regexp-search-ring) ;; … my search entries
savehist-autosave-interval 60 ;; save every minute (default: 5 min)
savehist-file “~/.emacs.d/cache/savehist”) ;; keep my home clean
(savehist-mode t) ;; do customization before activation

;;——————————————————————————–
;; Save/restore sessions on exit/startup.
;;——————————————————————————–

; (desktop-save-mode 1)

;;——————————————————————————–
;; POUR ENREGISTRER AUTOMATIQUEMENT LA POSITION DU CURSEUR QUAND ON QUITTE UN
;; FICHIER, ET Y RETOURNER AUTOMATIQUEMENT À LA RÉOUVERTURE
;;——————————————————————————–

(require ‘saveplace)
(setq-default save-place t)

;;——————————————————————————–
;; backups
;;——————————————————————————–
(setq make-backup-files t ;; do make backups
backup-by-copying t ;; and copy them here
backup-directory-alist ‘((“.” . “~/.emacs.d/backups”))
version-control t
kept-new-versions 2
kept-old-versions 5
delete-old-versions t)

Settings for backups. Nothing special.

;;##################################################################################################
;;APPEARENCE, etc
;;##################################################################################################
;————————————————————————————————–
;; Status bar
;————————————————————————————————–

(column-number-mode t) ;Affiche le numéro de ligne, de colonne
(line-number-mode t) ;Affiche le numéro de colonne

(size-indication-mode t) ;; show file size (emacs 22+)

(display-time) ;POUR AVOIR L’HEURE DANS LA BARRE D’ETAT
(setq display-time-24hr-format t) ;; Format 24 heures

Some settings to get the line and column number, the time, the size of your file in the status bar. Useful.

;————————————————————————————————–
; folding mode
;work in progress \o/
;————————————————————————————————–

;————————————————————————————————–
; show hide
;————————————————————————————————–

(defun toggle-selective-display (column)
(interactive “P”)
(set-selective-display
(or column
(unless selective-display
(1+ (current-column))))))

(defun toggle-hiding (column)
(interactive “P”)
(if hs-minor-mode
(if (condition-case nil
(hs-toggle-hiding)
(error t))
(hs-show-all))
(toggle-selective-display column)))

(global-set-key (kbd “C-+”) ‘toggle-hiding)
(global-set-key (kbd “C-\\”) ‘toggle-selective-display)

I tried to get the same settings I had with Vim, but without success. And since I won’t use Emacs anymore, I stopped my researches.

;————————————————————————————————–
;; tabulations
;; Comment changer la longueur des tabulations
;; pour un code écrit par
;; des sagouins.
;————————————————————————————————–

(defun tab4()
“Les tabulations vaudront 4 espaces”
(interactive “*”)
(setq tab-width 4)
)

(defun tab8()
“Les tabulations vaudront 8 espaces”
(interactive “*”)
(setq tab-width 8)
)

;————————————————————————————————–
;pour ne pas avoir de bandes verticales
;thanks to http://www.emacswiki.org/emacs/beginner.el
;————————————————————————————————–
;(set-fringe-mode 0)
;; don’t show tiny scroll bar in echo area
;(set-window-scroll-bars (minibuffer-window) nil)
;————————————————————————————————–
;Misc
;————————————————————————————————–

(setq visible-bell t) ;;警告音を消す

Some settings I have copy-pasted from somewhere a long time ago, for tabulations, scroll-bars and bell.

;;################################################################################
;;; ESS
;;################################################################################

;; (require ‘ess-site)
;; ;(require ‘ess-eldoc)

;; (ess-add-MM-keys) ;; notamment pour des “squelettes” de fonctions

;; “View *R* objects in a dire-like buffer.” t)

;; (setq-default ess-ask-for-ess-directory t) ;; demande le dossier de travail à chaque démarrage de R
;; (setq-default ess-directory “/media/ifremer/Analyses/R/”) ;; répertoire de travail proposé par défaut

;; ‘(lambda ()
;; (auto-fill-mode t)
;; ;;(flyspell-mode t)
;; (setq-default fill-column 100)
;; )
;; )

;; ;; Pour ajouter à la liste d’association les .Rhistory pour les traîter comme
;; ;; des fichiers sources R
;; (setq auto-mode-alist
;; (append
;; ‘((“\\.[rR]history\\'” . R-mode))
;; auto-mode-alist))

;; (define-key ess-mode-map [f6] ‘comint-dynamic-complete-filename)

;; ;; Montrer “au vol” les arguments de fonctions:

;; ;; ess-r-args-noargsmsg is printed, if no argument information could
;; ;; be found. You could set it to an empty string (“”) for no message.
;; (setq ess-r-args-noargsmsg “No args found.”)

;; ;; ess-r-args-show-as determines how (where) the information is
;; ;; displayed. Set it to “tooltip” for little tooltip windows or to
;; ;; nil (the default) which will use the echo area at the bottom of
;; ;; (setq ess-r-args-show-as “tooltip”)

;; ;; ess-r-args-show-prefix is a string that is printed in front of the
;; ;; arguments list. The default ist “ARGS: “.
;; (setq ess-r-args-show-prefix “ARGS: “)

;; (defun Rnw-mode ()
;; (require ‘ess-noweb)
;; (noweb-mode)
;; (if (fboundp ‘R-mode)
;; (setq noweb-default-code-mode ‘R-mode)))

;; (setq-default inferior-R-args “–no-restore-history –no-save “)

;; (defun my-ess-options ()
;; (ess-set-style ‘C++)
;; (column-number-mode t)
;; (lambda ()
;; (nuke-trailing-whitespace)))
;; (define-key ess-mode-map [(meta backspace)] ‘backward-kill-word))

;; (defun my-iess-keybindings ()
;; (define-key inferior-ess-mode-map [(control ?a)] ‘comint-bol)
;; (define-key inferior-ess-mode-map [home] ‘comint-bol))

Here are settings for ESS if yo plan to use it.

;;##################################################################################################

;;CUSTOMIZATION-FACE : FONT, COLOR
;; Modifications de l’apparence
;; font : aller dans Option –> Set default font ; pour sauvegarder : Option –> Save Options
;; color : pour tester les couleurs, aller dans le Menu –> Tools –> Color Themes
(require ‘color-theme)
‘(progn
(color-theme-initialize)
(color-theme-andreas)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (require ‘color-theme)
; (color-theme-initialize)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (color-theme-andreas)
;; pour color theme voir aussi dans dans Option –> Customize emacs –> Browse customization groups –> Group “Faces” –> Group “Color Theme”
;; pour LaTeX :
;; – \emph –> font-latex-italic-face
;; – \footnote –> font-lock-constant-face
;; – commandes (\emph, \textsc) –> font-lock-keyword-face

;;##################################################################################################

;————————————————————————————————–
;Default font
;thanks to http://www.emacswiki.org/emacs/XftGnuEmacs
;————————————————————————————————–
;; To me, the best fonts are as follow ; modify if you prefer Bitstream or another font :

;(set-default-font “Deja Vu Sans Mono 10”)

;————————————————————————————————–
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won’t work right.
‘(column-number-mode t)
‘(display-time-mode t)
‘(show-paren-mode t)
‘(size-indication-mode t))

Here are settings related to appearance. You will notice that you can easily change that with emacs, and that there are plainty of choices. But Vim’s color schemes are better (in my humble opinion).

;;##################################################################################################
;; MISCELLANEOUS
;;##################################################################################################
;————————————————————————————————–
;; do not show the startup message and other stuff
;; at http://www.djcbsoftware.nl/dot-emacs.html
;————————————————————————————————–

(put ‘narrow-to-region ‘disabled nil) ;; enable…
(put ‘erase-buffer ‘disabled nil) ;; … useful things

(setq inhibit-startup-message t ;; don’t show …
inhibit-startup-echo-area-message t) ;; … startup messages

;————————————————————————————————–
;; POUR NE PAS AVOIR À TAPER EN ENTIER LA RÉPONSE YES/NO
;————————————————————————————————–

(fset ‘yes-or-no-p ‘y-or-n-p)

;————————————————————————————————–
;; Fichiers annexes dans ~/.emacs.d/lisp
;————————————————————————————————–
;;stuff in separate files;; maybe use autoload?

;;inclusion de la gestion des couleurs
;(require ‘couleurs nil ‘noerror)
;—————————————-
;;inclusion du calendrier
;(require ‘calendrier nil ‘noerror)
;—————————————-
;;afficher les numéros de ligne
;(and (< emacs-major-version 20) (eval-when-compile (require 'cl)))
;—————————————-
;(require 'linum)

;display line numbers in margin (fringe). Emacs 23 only.
;(global-linum-mode 1) ; always show line numbers

Some settings such as “no startup message” (really useful if you are tired of this), and some others that you can enable or disable. But notice I have disable the option allowing you to get line numbers at the left. By the way, the display of line numbers with Vim is better, so if you want to get it, try to use Vim.

;————————————————————————————————–
;; THUMBS-MODE
;————————————————————————————————–
(autoload ‘thumbs “thumbs” “Preview images in a directory.” t)

;————————————————————————————————–
;Search and case sensitivity
;————————————————————————————————–

; (setq case-fold-search nil) ; make searches case sensitive
(setq case-fold-search t) ; make searches case insensitive

;————————————————————————————————–
;; Switch ispell dictionary locally.
;————————————————————————————————–
;;; Mode Ispell
;; (require ‘ispell)
;; (setq ispell-dictionary “francais”)

;; (global-set-key (kbd “C-c d e”)
;; (lambda () (interactive)
;; (ispell-change-dictionary “english”)))
;; (global-set-key (kbd “C-c d f”)
;; (lambda () (interactive)
;; (ispell-change-dictionary “francais”)))

;————————————————————————————————–
; Comment rafraîchir un fichier dans .emacs lorsqu’il
; a été modifié par un autre programme ?
; thanks to http://www.emacswiki.org/emacs/RevertBuffer
;————————————————————————————————–

(global-auto-revert-mode 1)

;———————————————————–
; a function to revert all buffers :
;———————————————————–
(defun revert-all-buffers ()
“Refreshes all open buffers from their respective files”
(interactive)
(let* ((list (buffer-list))
(buffer (car list)))
(while buffer
(when (buffer-file-name buffer)
(progn
(set-buffer buffer)
(revert-buffer t t t)))
(setq list (cdr list))
(setq buffer (car list))))
(message “Refreshing open files”))

;————————————————————————————————–
(defun my-info-refresh (&optional arg)
“Display some useful information in the echo area instead of the mode line.
With prefix arg, insert the current timestamp to the current buffer.”

;; §§ WORK IN PROGRESS §§ doesn’t work !

;————————————————————————————————–
(interactive “P”)
(cond
((equal arg ‘(4)) ; C-u f5
(insert (format-time-string “%Y%m%d” (current-time))))
((equal arg ‘(16)) ; C-u C-u f5
(insert (format-time-string “%Y-%m-%d” (current-time))))
(t (message “%s”
(concat
(format-time-string “%Y-%m-%d %H:%M:%S %z” (current-time)) ;; ISO
” ”
(aref calendar-day-abbrev-array (nth 6 (decode-time (current-time))))
” : ”
(or (buffer-file-name) default-directory))))))

;(define-key my-map [f5] ‘my-info-refresh)
;(define-key global-map [f5] ‘my-info-refresh)

;; open Word files with antiword
(autoload ‘no-word “no-word” “word to txt”)
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won’t work right.
‘(default ((t (:inherit nil :stipple nil :background “white” :foreground “black” :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 98 :width normal :foundry “unknown” :family “DejaVu Sans Mono”)))))

Finally, here are some settings which might be useful but nothing special, and others who are related to appearance.

In the future I will continue to use Vim. For this reason I will just make a short description of some useful commands with Emacs in the second part.

## Writing LaTeX files with GVim

In this post I will show some useful links, some tips and shortcuts I have set in my settings for Vim.

1. First, here are screenshots and videos you might find useful if you are a beginner :
• If you don’t know how GVim looks like, here is the screenshot taken from a video at youtube.com :

And here is how GVim looks like with my own settings :

• Here is a screencast which explains the basics of vim that you can find with youtube or google videos :

An other screencast with some explanations about basic but useful plugins available for Vim, which will save your time when you edit files (such as LaTeX files) :

Once you get the basic idea of what GVim is, here are some lessons :

2. Secondly, here are some explanations about plugins I use in GVim :
• MRU is a vim script which enable you to use the Most Recently Used files. If you use the settings I have put in my repository at Github, then press F8, and you will get files you closed recently :

• When I don’t have used a file recently and want to open one, I press F4 and I get the Vim Explorer

If you want to enter in a directory, move the cursor to this directory and press enter. If you want to move back, press Backspace. To open a file, place the cursor on this file and press enter.
You will also notice that all files are sorted according to the extension, a nice feature of the plugin.

• NerdTree is an other way to search files. When another file is already opened, NerdTree will be opened automatically in a small part of the window, on the left :

To open it, press Shift+F4. To switch from the buffer opened on the left to the main buffer, you will have to use the mouse, or to type twice ctrl+w, a keystroke which will move automatically the cursor to the main part of the window.

You can also look at this screencast showing you more about the NerdTree plugin :

• If you are editing a LaTeX file (it works with other sort of files), select the block you wish to comment, and then type “,ci”. It will comment it, thanks to the plugin NerdCommenter. To uncomment it, do the same thing. Here are screenshots showing you a selected block and then the same block commented after typing ,ci :

• Thanks to the AutoComplPop plugin, when you type a word, a popup will automatically be displayed, and will show you all words available in your dictionaries’ directory specified in the settings I have made (~/.vim/ftplugin/tex.vim) :

• Let us assume you wish to enter a section in your LaTeX file. With the plugin SnipMate, you will only have to type sec and press tab, and you will have everything expanded. Then when you will enter the title, it will automatically write the same for the label, and once you will have pressed tab again, the cursor will automatically jump to the place where you will have to begin your section. In this screenshot I enter sec :

Here is what I get when I press tab :

And while I am typing the title, it automatically type the label :

And then, pressing tab will make the cursor jump to the right place between the delimited space defined with the snippet (for Ubuntu users not aware of what a snippet is, basically let us say it is similar to a template).

Also, many other snippets are already defined, and I have defined others snippets by myself. If you want to get a try or to look at it, see the corresponding file in my repository at Github.

If you don’t get the idea of Snipmate, then look at this video :

• Let us assume you have multiple files (which we call in this case “buffer“) opened in the same window, and you wish to select one. With the plugin SelectBuffer, you will just have to press F10 and it will open a small area where you will can select the one you want. Once you get it, press F10 again and it will automatically close itself :

If you don’t understand what a buffer is, since it is important to understand the use of this plugin, look at this screencast :

• Let us assume the cursor is positioned on a bracket. Press % in normal mode, and your cursor will automatically jump to the other one, thanks to the matchit plugin. It might be useful for footnotes or other things in *.tex files.

The following screencast show an example at 8 min 01 s :

Let us assume you wish to get 2 files in the same screen. In normal mode, type ;bv and press enter, and the screen will split vertically thanks to the buffer explorer plugin :

You can try yourself other commands like ;be and ;bs if you are interested.

• Other plugins are also in my .vim directory. FuzzyFinder for example. If you type :FuzzyFile, you will get the following :

For more details, look at the documentation of the plugin or see this screencast.

• If you type :Calendar and press enter in normal mode, a calendar will be displayed thanks to the calendar plugin

• Other plugins may be interesting for you, such as the multiple search plugin, the align plugin and the time stamp plugin. But for these plugins, I will let you look by yourself the documentation.
If you don’t know how to look to the relevant documentation corresponding to the plugin, then do as follow. In normal mode, type :h Align and press enter, and you will get a new buffer displayed for the Align documentation :

3. Though it is not plugins, here are some other tips you need to know if you wish to use my settings :
• If you want to save a file, press F2.
• If you want to open a terminal, press shift+F2
• If you want to open nautilus, press Alt+F2. Notice that if you want to open another file manager, you will have to change it in THE settings. For this, look in the .vimrc file.
• If you want to close a buffer, that is to say a file, then press F3. If you want to close all buffers currently opened in a window, press shift+F3. And if you don’t want to save and want to exit, press Alt+F3.
• If you want to compile a *.tex file, press F11. It will also automatically start the viewer after finishing to compile. If you just want to compile, and don’t want to see the result, press Alt+F11. Notice that the default compiler is XeLaTeX, and not pdfLaTeX. If you want to change the compiler, you will have to change my settings, and to do so you will have to modify the tex.vim located in ~/.vim/ftplugin. And if you don’t understand how to modify it after looking at the tex.vim file, let a comment (though you should get a try to XeLaTeX).
• If you want to enable spell checking for french, press F12. If you want to disable it, press F12 again. If you want to enable spell checking for english, press Alt+F12. If you use most of the time english files, you might change the default mapping in .vimrc to replace the mapping for french by the mapping for english.
• When you want to copy a selected line, word, etc, press Ctrl+Insert. To cut a selected line, word or other, press Insert+Suppr. And to paste it, press Shift+Insert. If you are not familiar to these shortcuts, then learn to like it instead of changing it, because these shortcuts are also used in other programs.
• To search a word, type “/” in normal mode, and then enter your word. If several words exist, press enter and then type “n”, which means “next”. The cursor will jump to the next word each time you will press “n”. Once your searches are finished, enter Ctrl+n to cancel highlighting.
• To open a new tab, press Ctrl+t in normal mode. To move to the next tab, press Ctrl+”left arrow” or Ctrl+”right arrow” depending on what tab you want to select.
• To format a paragraph, press Shift+q in normal mode. But be aware that you should avoid it with my settings, which won’t let you get a correct formatting with LaTeX files.
• To emphasize a word, select it and press “,em” in normal mode. See other shortcuts in the latex-suite documentation. But notice that I have changed the default mapping. Instead of pressing  and the abbreviation, you will have to press “,” and the abbreviation (the reason of this mapping is that a comma is easier to type than a “” with a french keyboard). Here are some examples of shortcut :

Shortcuts LaTeX commands
,md \textmd{}
,tt \texttt{}
,sf \textsf{}
,up \textup{}
,bf \textbf{}
,sl \textsl{}
,sc \textsc{}
,it \textit{}
,em \emph{}
,a \alpha
,b \beta
,A \Alpha
,B \Beta
And so on
etc, etc
I won’t show you
all shortcut
for more details,
see the latex-suite
documentation

In any case this setting is for french keyboards, if you use another keyboard, change this in tex.vim if you want.
• If you want to search a word in google with firefox, then select the word, and press “f” in visual mode. If you want to search in Wikipedia instead of google, press “w” instead of “f” in visual mode.
4. Here is another tip with Vim, really useful. Let us assume you wish to enter a word or several words which are painful to typeset with your keyboard, and let us also assume that you often use this or these words. Then using abbreviations is a nice idea. My abbreviations are set in the tex.vim, see the line 33. Basically, an abbreviation is something you type and which will expand automatically to the word or the words you have set previously after you press the space key. So for example, since I have :

iab bcp beaucoup
iab qqn quelqu’un
iab qqc quelque chose

When I will write bcp, it will transform automatically in beaucoup when I will press the space bar.

Look here or here for further explanations.

5. With Vim, another thing really useful is imap (or nmap for normal mode, and vmap for visual map). Imaps are mappings set to work in insert mode. So for example, let us assume you wish to insert a bracket, say “(“. Since I have defined “imap ( ()” in my tex.vim, pressing ( will automatically load the other bracket. So writing ( will write automatically (). When you write “,ja”, it will automatically write {\ja }. Same thing for “…”, it will be replaced automatically by “\ldots”. For further details, see the vim documentation (in normal mode, type “:h imap”).
6. Don’t forget that Vim is not as bad as Microsoft Word, OpenOffice.org Writer and other similar text processors are. Let us take an example. If you have the following :
a b c
d e f
i j k
Could you insert a & between each letter in each lines easily ? No. But with Vim it is easy. With Word or other similar softwares, could you easily replace each letter or each word of the beginning of a line ? No. But with vim it is easy to do so. Therefore, if you are a beginner, don’t forget to search with google if something you need to do is painful, maybe there is an easy way with Vim to automatize your task and to achieve your goal.

Finally, here are some links which you could find useful :

Vim tips if you don’t want to use my settings, or are just curious
A course, “Vi : introduction”
The LaTeX suite documentation in html or in txt format (available in Vim)
A nice ref card of Vim in several formats (download the pdf file) and another one in html, maybe more clear
French speakers should also take a look here
In case you wish to ask a question, Google group is a good place.
Another Vim tutorial
If you are japanese, you could find this blog useful.
If you are french and want to use the bépo keyboard

## Installing and setting up the Vim text editor

To write LaTeX files, I use GVim which is basically Vim with a modern outlook. If you are interested to get a good text editor, use Vim or GVim with free Unix operating systems (that is to say operating systems which are under GPL or BSD license), MacVim with Mac OSX, and maybe GVim or Evim with Microsoft Windows operating systems (XP, Vista, Seven).

If you make some researches about text editors, you may notice that there is a stupid “war” between Emacs and Vim. Actually, both are excellent text editors, only the approach changes. Also, though comparing a text editor might be highly controversial and subjective, it might be right to say that Vim is one of the best text editors, available for all platforms.

If you wish to write LaTeX files, a well configured text editor like GVim will make your life easier, and will increase your efficiency in typesetting. Once you will have learned how to use Vim, you will also understand how ridiculous are Word processors like Microsoft Word or OpenOffice.org Writer compared to Vim or Emacs.

In this post I will explain, first, how to install Vim in GNU/Linux, FreeBSD, Microsoft Windows and Mac OSX, and secondly, I will write a short explanation of my setup.

1. For GNU/Linux To install GVim with GNU/Linux, the version of Vim with a modern interface, you have 2 choices. (1) To install it with your package manager. If you have Ubuntu, install Vim-gtk with Ubuntu Software Center :

(2) Th second choice is to install GVim from the official website, useful if you want the latest version of Vim (currently, 7.3) :
http://ftp.vim.org/pub/vim/unix/
Download the latest version, at the bottom of the page. Notice that to install it with Ubuntu, you will need some development libraries, such as libx11-dev, libgtk2.0-dev and another one but I don’t remember (look at the compilation errors, or the INSTALL* file). So if you are not familiar with command line and compilation errors, I recommend to use your package manager instead of the tarball file of the official website.
2. For FreeBSD To install GVim with FreeBSD, you could choose the second way I have described above for GNU/Linux, or to install it from ports (notice that the install process with ports is quite long thanks to patches) :
 su cd /usr/ports/editors/vim make WITH_GTK2=yes make install clean 
3. For Microsoft Windows Though I am not really aware of the install process with any version of Windows (I have never used Windows on my laptop), I suppose you will have to install and download it from the following url :
4. For Mac OSX I don’t have tried to install Vim on Mac OSX, but try the following link :
http://macvim.org/OSX/index.php

Secondly, you have to make Vim work like you want. Indeed, you won’t be efficient with Vim if you don’t have a good setup. Since I have already done the job (thanks to all informations I have gathered from the internet), you will just have to make a copy of my git repository. To do so, you will need to install git if you don’t have it. If you are not familiar with the command line and use Ubuntu, copy-paste the following in a terminal (to open a terminal, press “ctrl+alt+t”) :
 cd ~ sudo apt-get install git git https://alexandre-k@github.com/alexandre-k/repository_alexandre_krispin.git cp ~/repository_alexandre_krispin/configuration_files_for_text_editors/vim_configuration_files/.vim ~/.vim cp ~/repository_alexandre_krispin/configuration_files_for_text_editors/vim_configuration_files/.vimrc ~/.vimrc cp ~/repository_alexandre_krispin/configuration_files_for_text_editors/vim_configuration_files/.gvimrc ~/.gvimrc 
That’s all. Notice that I don’t have used my setup with Mac OSX and Windows, and I don’t know if I will be able to help you if you have any troubles with Windows.

Now I will explain my .vimrc, my .gvimrc and then my tex.vim (located in .vim/ftplugin/) :

1. First, my .vimrc (located in /home/your_username/.vimrc in free Unix operating systems like GNU/Linux and *BSD). You can take a look at it in my Github repository :

“————————————————————————-
” Basic settings for LaTeXsuite
http://vim-latex.sourceforge.net/documentation/latex-suite/recommended-settings.html
“————————————————————————-
” REQUIRED. This makes vim invoke Latex-Suite when you open a tex file.
filetype plugin on

This setting will allow you to get the right settings according to the file extension. In other words, it will load all settings used with LaTeX-suite.

” IMPORTANT: win32 users will need to have ‘shellslash’ set so that latex
” can be called correctly.
“set shellslash

” IMPORTANT: grep will sometimes skip displaying the file name if you
” search in a singe file. This will confuse Latex-Suite. Set your grep
” program to always generate a file-name.
set grepprg=grep\ -nH\ $* ” OPTIONAL: This enables automatic indentation as you type. filetype indent on ” OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to ” ‘plaintex’ instead of ‘tex’, which results in vim-latex not being loaded. ” The following changes the default filetype back to ‘tex’: let g:tex_flavor=’latex’ “To jump from a section to another one map ]s :/\\$$sub$$\{,2}section\s*{ :noh map [s :?\\$$sub$$\{,2}section\s*{ :noh This part is just a copy of the recommended settings from the official website of Latex-suite. “———————————————————————— ” General settings “———————————————————————— let b:loaded_tex_autoclose = 1 let g:autoclose = 1 set backspace=indent,eol,start “allow backspacing over everything in insert mode set textwidth=80 set title ” change the terminal’s title syntax on “switch on syntax highlight set undolevels=1000 “number of undos set history=1000” “sets how many lines of history VIM has to remember set complete+=k ” enable dictionary completion set clipboard+=unnamed ” yank and copy to X clipboard set showmatch “show pairs of brackets set hlsearch ” When there is a previous search pattern, highlight all ” its matches. set incsearch ” While typing a search command, show immediately where the ” so far typed pattern matches. set ignorecase ” Ignore case in search patterns. set smartcase ” Override the ‘ignorecase’ option if set wrapscan ” end of search has been achieved! set magic “regexp version magic set cursorline “highlight current line set cursorcolumn “highlight current column set wildmenu set wildignore=*.o,*~,*.cmo,*.cmi,*.a,*.cmx,*.cmxa,*.lo,*.log,*.aux,*.dvi,*.aut,*.aux,*.bbl,*.blg,*.dvi,*.fff,*.out,*.pdf,*.ps,*.toc,*.ttt set number “to show line number “set nocompatible “seems that setting Vim not to be compatible with Vi disables the setting bellow, whichwrap. “Therefore I disable it set whichwrap=b,s,,[,] ” Allow specified keys that move the cursor left/right ” to move to the previous/next line when the cursor is on the first/last character ” in the line. b (backspace), s (space) and the arrows. set nostartofline ” Do not place the cursor at the start of the line when using Page up/down. set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.out,.toc “for file names completion set hi=2000 ” remember last 2000 typed commands set autoread ” Set to auto read when a file is changed from the outside set enc=utf-8 set hidden ” It hides buffers instead of closing them. This means that you ” can have unwritten changes to a file and open a new file using :e, without being ” forced to write or undo your changes first. Also, undo buffers and marks are ” preserved while the buffer is open. set visualbell ” don’t beep set noerrorbells ” don’t beep set list ” Vim can highlight whitespaces for you in a convenient way: set listchars=tab:>.,trail:.,extends:#,nbsp:. set laststatus=2 “status bar set statusline=%n:\ %f%m%r%h%w\ [%Y,%{&fileencoding},%{&fileformat}]\ [%l-%L,%v][%p%%]\ [%{strftime(\”%l:%M:%S\ \%p,\ %a\ %b\ %d,\ %Y\”)}] set ruler set rulerformat=%25(%n%m%r:\ %Y\ [%l,%v]\ %p%%%) ” toujours afficher le mode courant set showcmd “show the command being typed Then come the general settings. Since they are well commented, I let you read by yourself. To sum up, I have put here some settings about the text width, the search, the cursor, the status line, and other stuff for convenience that you can find everywhere on the internet. “—————————————– ” change cursor colour depending upon mode if exists(‘&t_SI’) let &t_SI = “\]12;lightgoldenrod\x7” let &t_EI = “\]12;grey80\x7” endif “——————————– ” Backups “——————————– set nobackup set backupcopy=auto set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*test*,*temp*,*tmp*,*tst*,*~,*bak

“———————————–
“nice colors and fonts
“———————————–
colorscheme herald
colors herald
“set guifont=DejaVu\ Sans\ Mono\ 10
set guifont=Inconsolata\ 12 ” very nice, but leaves terrible artefacts with national (mostly russian) characters
“set guifont=Terminus\ 10 ” wonderful, yet smallish, and sucks at larger sizes
“———————————-
” GUI Options
“———————————-
“if has(“gui_running”)
” ” GUI cursor: no blinking

” ” no toolbar
” set guioptions-=T
” ” no autoselect
” set guioptions-=a

” ” Use console messages instead of GUI dialogs
” set guioptions+=c
“endif

The most important thing here is the settings for backups. Since backup files annoyed me, I have set it to “nobackup”. If you prefer to get backup, replace “set nobackup” by “set backup”. Also, the color scheme is “herald”, a nice one, and the font is inconsolata. If you prefer to get a more shiny or simply another color scheme you would like, check the demos at the following url :
Color sampler pack
Or this one :
Color samples with LaTeX files
Once you have chosen, replace the “herald” colorscheme by the one you want.

“——————
“formatting
“——————
set formatoptions=tcroqn ” see help
“set formatoptions=c,q,r,t ” This is a sequence of letters which describes how
” automatic formatting is to be done.

” letter meaning when present in ‘formatoptions’
” —— —————————————
” c Auto-wrap comments using textwidth, inserting
” the current comment leader automatically.
” q Allow formatting of comments with “gq”.
” r Automatically insert the current comment leader
” after hitting in Insert mode.
” t Auto-wrap text using textwidth (does not apply
“—————
set smartindent ” turn on smart indenting
set autoindent ” always set autoindenting on
set copyindent ” copy the previous indentation on autoindenting
set shiftwidth=4 ” number of spaces to use for autoindenting
set shiftround ” use multiple of shiftwidth when indenting with ‘<‘ and ‘>’
set smarttab ” insert tabs on the start of a line according to
” shiftwidth, not tabstop
“setlocal indentkeys+=},=\\item,=\\bibitem,=\\else,=\\fi,=\\or,=\\]

“————————–
” indentation automatique (à la Emacs)
“vnoremap =$“vnoremap = “nnoremap =$
“nnoremap mzvip=z

“let g:tex_indent_items = 1

Here are settings to make formatting work… But it doesn’t work well for LaTeX files, I am sorry for the inconvenience. Since I don’t really need to format LaTeX files (I write it correctly), I don’t really care of this. If one day I receive files badly formatted, then I will try to make it work. However, if you just plan to write LaTeX files, then the current settings might be sufficient.

“—————————-
“TAB BAR
“—————————-
” set up tab labels with tab number, buffer name, number of windows
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 tab number
let label .= tabpagenr().’: ‘

” Append the buffer name
let name = bufname(bufnrlist[tabpagewinnr(v:lnum) – 1])
if name == ”
” give a name to no-name documents
if &buftype==’quickfix’
let name = ‘[Quickfix List]’
else
let name = ‘[Not yet saved]’
endif
else
” get only the file name
let name = fnamemodify(name,”:t”)
endif
let label .= name

” Append the number of windows in the tab page
let wincount = tabpagewinnr(v:lnum, ‘$’) return label . ‘ [‘ . wincount . ‘]’ endfunction ” set up tab tooltips with every buffer name function! GuiTabToolTip() let tip = ” let bufnrlist = tabpagebuflist(v:lnum) for bufnr in bufnrlist ” separate buffer entries if tip!=” let tip .= ‘ | ‘ endif ” Add name of buffer let name=bufname(bufnr) if name == ” ” give a name to no name documents if getbufvar(bufnr,’&buftype’)==’quickfix’ let name = ‘[Quickfix List]’ else let name = ‘[Not yet saved]’ endif endif let tip.=name ” add modified/modifiable flags if getbufvar(bufnr, “&modified”) let tip .= ‘ [+]’ endif if getbufvar(bufnr, “&modifiable”)==0 let tip .= ‘ [-]’ endif endfor return tip endfunction set guitablabel=%!GuiTabLabel() set guitabtooltip=%!GuiTabToolTip() Here are settings for the tab bar. Notice that for some Vim users, it seems to be a kind of pride an joy, but you can get tab bars with Emacs, Kile, and other softwares. “————– “spelling… “————– “to enable spell checking by default, uncomment the following line, “set spell ” automatic spell checking in your language for .txt et .tex. Replace “fr” by your default ” language, “en” if english : “augroup filetypedetect “au BufNewFile,BufRead *.txt setlocal spell spelllang=fr “au BufNewFile,BufRead *.tex setlocal spell spelllang=fr “augroup END “———————————— ” painless spell checking ” for French, you’ll need ” wget http://ftp.vim.org/pub/vim/runtime/spell/fr.utf-8.sug ” wget http://ftp.vim.org/pub/vim/runtime/spell/fr.utf-8.spl ” which you may move into ~/.vim/spell “————————————- function s:spell_fr() if !exists(“s:spell_check”) || s:spell_check == 0 echo “Spell checking activated (french)” let s:spell_check = 1 setlocal spell spelllang=fr else echo “Spell checking canceled” let s:spell_check = 0 setlocal spell spelllang= endif endfunction ” for English function s:spell_en() if !exists(“s:spell_check”) || s:spell_check == 0 echo “Spell checking activated (english)” let s:spell_check = 1 setlocal spell spelllang=en else echo “Spell checking canceled” let s:spell_check = 0 setlocal spell spelllang= endif endfunction “See mapping for spell checking in the relevant section, l. 361 “——–Another trick for spell checking is the following line : “uncomment if you want to use it, type “,C” if you want to enable it, “and replace aspell by any other dictionary you use (ispell, hunspell) “map ,C :w:!aspell -c %:e %” Here are settings for spell checking. If you want to enable spell checking by default, there are several ways. One is to uncomment the lines : ""augroup filetypedetect "au BufNewFile,BufRead *.txt setlocal spell spelllang=fr "au BufNewFile,BufRead *.tex setlocal spell spelllang=fr "augroup END" and to replace “fr” by “en” or any other abbreviation depending on the language you use. “————————— “For tags, but doesn’t work let tlist_tex_settings = ‘latex;s:sections;g:graphics;l:labels’ let tlist_make_settings = ‘make;m:makros;t:targets’ Here was a rest of the period when I tried to set up tags for LaTeX files, but didn’t get it successfully working. And since I don’t care and don’t have time for it, I let it for better days. “———————————————————————— ” MAPPING “———————————————————————— “—————————- “Saving “————————— map :w imap :w “—————————— ” Terminal “—————————— map :!gnome-terminal & imap :!gnome-terminal & “——————————- ” Graphical file manager “——————————– map :!nautilus & map :!nautilus & “—————————- “Exit “—————————- “exit map :q imap :q “exit all map :qall imap :qall “force Exit map :qall! imap :qall! “—————————- “Mapping to activate file explorer “of the specified directory “—————————- “To display NERDTree nnoremap :NERDTree /home/freeman/ ” To display VimExplorer nmap :VE %:p:h “—————————- “Mapping to explorer of recent file, “Most recently used files “—————————- map :Mru imap :Mru “————- “SelectBuf “————- nmap SelectBuf noremap SelBufHelpKey “—————————– “Compiling and viewing its .tex file “with XeLaTeX and evince (set in tex.vim) “—————————– “Compile and start viewer map ;ll ;lv imap ;ll ;lv “Compile only map ;ll imap ;ll “————————– “To enable spell checking for french : noremap :call spell_fr() inoremap :call spell_fr() vnoremap :call spell_fr() ” and for english : noremap :call spell_en() inoremap :call spell_en() vnoremap :call spell_en() Here are settings related to F* keys. I will explain their use latter, though you might be able to undestand it easily by yourself thanks to comments. Notice that if you don’t use gnome-terminal as terminal and nautilus as file manager, you will have to change the settings (if you don’t understand what I am talking about and use Ubuntu, then don’t worry and don’t change anything). “——————————— “Ctrl+Insert to copy into clipboard “Shift+Insert to paste from clipboard “Shift+Delete to cut into clipboard “Ctrl+a to select all “—————————- nmap “+gP imap i vmap “+y map ggVG map “+x “—————————- “Mapping to desactivate highligting “of search results “—————————- nnoremap :noh “——————————– ” firefox like shorcuts “——————————– map :tabnew map :tabnext map :tabprevious map :e “——————————– ” Quickly edit/reload the vimrc file “——————————- nmap ev :e$MYVIMRC
nmap sv :so $MYVIMRC “——————————– ” Use Q for formatting the current paragraph (or selection) “——————————– vmap Q gq nmap Q gqap “——————————– “If you like long lines with line wrapping enabled “——————————– nnoremap j gj nnoremap k gk “——————————– ” unmap arrows/pgdn/pgup so you learn to use hjkl map \ map \ map \ map \ map \ map \ imap imap imap imap imap imap “——————————– “Tired of clearing highlighted searches ? “——————————– nmap ,/ :nohlsearch “——————————– “Will search the word in firefox where “the cursor is when typing g in visual mode “big thanks to http://la.firme.perso.esil.univmed.fr/website/article.php3?id_article=70 vmap f :!firefox “http://www.google.fr/search?hl=fr&q=&btnG=Recherche+Google&meta=&#8221; >& /dev/null “A similar behaviour but for Wikipedia vmap w :!firefox “http://en.wikipedia.org/wiki/&#8221; >& /dev/null “——————————– “For qwerty keyboards : instead of “pressing “shift”+”;”, you will just “have to press ;, and say w to save. “——————————- “nnoremap ; : “——————————– “when you forgot to sudo before editing a file that requires root privileges “(typically /etc/hosts). This lets you use w!! to do that after you opened the “file already “——————————– cmap w!! w !sudo tee % >/dev/null Here are other settings to easily copy, paste, etc. Notice that I have disable arrow keys to force beginners to use hjkl keys. “—————————————————————— ” MiSCELLANOUS “—————————————————————— “——————————————————– ” Go back where I left off autocmd BufReadPost * call RestoreCursorPos() autocmd BufWinEnter * call OpenFoldOnRestore() ” Restore my cursor position function! RestoreCursorPos() if expand(“:p:h”) !=?$TEMP
if line(“‘\””) > 1 && line(“‘\””) <= line(“$”) let line_num = line(“‘\””) let b:doopenfold = 1 if (foldlevel(line_num) > foldlevel(line_num – 1)) let line_num = line_num – 1 let b:doopenfold = 2 endif execute line_num endif endif endfunction ” Open the fold if restoring cursor position function! OpenFoldOnRestore() if exists(“b:doopenfold”) execute “normal zv” if(b:doopenfold > 1) execute “+”.1 endif unlet b:doopenfold endif endfunction “————————- ” 日本語入力に関する設定: if has(‘multi_byte_ime’) || has(‘xim’) ” IME ON時のカーソルの色を設定(設定例:紫) highlight CursorIM guibg=Purple guifg=NONE ” 挿入モード・検索モードでのデフォルトのIME状態設定 set iminsert=0 imsearch=0 if has(‘xim’) && has(‘GUI_GTK’) ” XIMの入力開始キーを設定: ” 下記の s-space はShift+Spaceの意味でkinput2+canna用設定 “set imactivatekey=s-space endif ” 挿入モードでのIME状態を記憶させない場合、次行のコメントを解除 “inoremap :set iminsert=0 endif ” 日本語入力用のkeymapの設定例 (コメントアウト) “if has(‘keymap’) ” ” ローマ字仮名のkeymap ” “silent! set keymap=japanese set iminsert=0 imsearch=0 ” 入力時の初期状態 = IME OFF “endif Finally, here are settings to restore the position when you open again your file, and some settings to use ibus with japanese. Unfortunatly, it seems ibus conflicts with Latex-suite, and I don’t have time to search where does the problem come from. Since I don’t expect to write japanese files at the moment, I won’t search a solution until I have time. But if you can use ibus with GVim, then comments are welcome. 2. Secondly, here are my settings for .gvimrc. You can find it in my repository at Github : ” ウインドウの幅 set columns=200 ” ウインドウの高さ set lines=150 “set guioptions+=c ” use console dialogs, not the gui ones set guioptions-=T ” don’t show the toolbar set guioptions-=m ” don’t show the menu set guioptions-=r ” don’t need right scrollbar set guioptions-=L ” don’t show left scrollbars Basically, it will allow you to get a bigger window at startup than the default one, and it will disable useless things like scrollbars. 3. Thirdly, I will present my tex.vim file, that you can also find in my repository at Github : “————————————————————————– ” General settings “————————————————————————– “let g:autoclose = 1 “let g:Tex_SmartKeyQuote = 1 setlocal efm+=%E%f:%l:\ %m let g:Tex_DefaultTargetFormat=’pdf’ let g:Tex_CompileRule_pdf=’/usr/local/texlive/2010/bin/i386-linux/xelatex$*’

let g:Tex_ViewRule_dvi = ‘xdvi’
let g:Tex_ViewRule_ps = ‘gv’
let g:Tex_ViewRule_pdf = ‘evince’

Here are some settings to make Vim call the correct software related to the corresponding output. So for *.dvi files, I use xdvi, for *.ps files, gv, and for *.pdf files, evince. If you use other softwares, then replace the settings accordingly. If you use Ubuntu, then don’t do anything.

“———————————
“Enhanced Vim formatting of LaTeX files
“———————————
“map \gq ?^$\\|^\s*$$\\begin\\|\\end\\|\\label\\|\\documentclass\\|\\usepackage\\|\\paragraph\\item$$?1gq//+1 “omap lp ?^$\\|^\s*$$\\begin\\|\\end\\|\\label$$?1//-1.

“”To format LaTeX files,

“———————
“Dictionaries
autocmd Filetype tex,latex :set dictionary=~/.vim/ftplugin/latex-suite/dictionaries/dictionary,/home/linux/.vim/spell

Here are other rests from the period when I tried to setup a correct formatting with Vim for LaTeX files. Also, there is the settings for dictionaries, which are located in my home directory, ~/ (the abbreviation of /home/your_username).

“———————————————————————-
” Abbreviations
“———————————————————————-
iab ds dans
iab bcp beaucoup
iab qqn quelqu’un
iab qqc quelque chose
iab pol politique
iab leurope l’Europe
iab tv télévision
iab ceca CECA
iab ue Union Européenne
iab CE Commission Européenne
iab AL Amérique Latine
iab letat l’État
iab socio sociologie
iab éco économie
iab math mathématique
iab xelatex \XeLaTeX
iab latex \LaTeX
iab ak Alexandre Krispin

Here are settings for abbreviations. Remove them if you don’t use it. Also, notice that since the abbreviations are in the file “tex.vim” (~/.vim/ftplugin/tex.vim), they won’t be available for other files. If you want to make your abbreviations available for all files (.txt, .tex, .sty, etc), then copy your’s in the file .vimrc.

“—————————————————————————
” MAPPING
“—————————————————————————

“——————————–
“Change the mapleader from \ to ,

“——————————–
“fixing of é letter :
imap it
Tex_InsertItemOnThisLine
imap
Tex_MathBF
imap
Tex_MathCal
imap
Tex_LeftRight

“—————————————
“Another shortcut for placeholders.
“The default one is ctrl+j, really
“annoying. Pressing shift+tab is easier
imap
IMAP_JumpForward

“—————————————
“useful imaps
imap ,ja {\ja
“the above imap is intended to work with
“my setup for japanese in my templates compiled
“with XeLaTeX. For more details, look at my
“blog : https://alexkrispin.wordpress.com/
imap … \ldots

“———————————
“autoclose brackets
“Actually you can get a similar
“behavior with snippets : just type (,
“and then press the tab key. In case
“you prefer snippets, comment the
“following 3 lines
imap { {}
imap ( ()
imap [ []

“—————————————
“With XeLaTeX, these imaps are no longer
“required since you compile with
“unicode. In case you use pdfLaTeX to
“compile, enable the following :
“imap « \og
“imap » \fg
“imap € \EUR
“imap ~ \$\sim\
“imap ” \textquotedblleft
“imap ¢ \textquotedblright\

“————————————–
“If you have a french keyboard, this setting
“will let you easily put, let say bf.
“Instead of inserting bf in normal mode
“you will just have to insert ,bf (therefore,
“no need of the Alt Gr key)
vmap , 

Finally, I have set up my mappings :

• since I use an azerty keyboard, I have changed the map leader (“\”) to “;”. If you have another type of keyboard, then set the map leader to any other key you want.
• Also, if you don’t need to write the “é”, remove this setting.
• Notice that I have made another setting to move the cursor to the placeholder (“<++>”), I prefer to type shift+tab rather than “ctrl+j”, but remove it if you want.
• Since one day I will use Vim to write in japanese and maybe in arabic or persian (who knows) I have set the command “,ja” to write automatically “{\ja }” in LaTeX files. Further informations in the second part of my post about Vim.
• An other thing which might be worth to say is that if you write “…” in a LaTeX file, it will be automatically replaced by “\ldots”. If you don’t use XeLaTeX but LaTeX, you might find useful to uncomment lines like “imap € \EUR.
• lastly, notice that I have change the “” to “,” (more easy to type with french keyboard). So if you want to enter, let say, \textbf{}, then press “,bf” instead of the usual “`bf”.