]> git.cworth.org Git - notmuch-wiki/blob - vimtips.mdwn
News for release 0.38.3
[notmuch-wiki] / vimtips.mdwn
1 [[!img notmuch-logo.png alt="Notmuch logo" class="left"]]
2 # Tips and Tricks for using Notmuch with vim
3
4 Tips for using Notmuch with vim; these may be applicable when using vim with
5 [[notmuch-mutt]], [mutt-kz](https://github.com/karelzak/mutt-kz), or
6 [notmuch-vim](https://git.notmuchmail.org/git/notmuch/blob/HEAD:/vim/README).
7
8 [[!toc levels=2]]
9
10 ## Install the vim addon for Notmuch
11
12 Before you can run Notmuch within vim, you must install notmuch as a vim addon.
13
14 For example, if you have installed from the debian package:
15
16     $ sudo apt-get install notmuch-vim
17
18 then to install as an addon, run this command:
19
20     $ vim-addon-manager install notmuch
21
22 ## Run Notmuch within vim
23
24 Open vim and type
25
26     :Notmuch
27
28 and press ENTER. Voila.
29
30
31 Alternatively, you can invoke vim with the -c flag:
32
33     $ vim -c :Notmuch
34
35 ## Addressbook management and vim
36
37 There are some emacs tips over [[here|emacstips#index15h2]] that
38 explains how to configure emacs with an addressbook, but the few solutions were not fast enough
39 for me. And I never could test the vala-based code. So I updated the notmuch\_addresses code to
40 use a cache to be able to make better matches and still be lightning fast.
41
42 And finally, [I needed](http://i.got.nothing.to/blog/2013/03/20/how-i-learned-to-stop-worrying-and-love-the-mail/) to have a way to autocomplete my recipients' addresses
43 automagically from within `vim`. So that's why I created the [notmuch\_abook](https://github.com/guyzmo/notmuch-abook) code.
44 You can either install it as a plugin in vim, using vundle:
45
46         Vundle 'guyzmo/notmuch-abook'
47
48 Or if you're not using vim (which is objectively the best editor ever), you may
49 want to use it as standalone:
50
51         % pip install notmuch_abook
52
53 To configure the address book, append to `~/.notmuch-config` the following:
54
55         % cat >> ~/.notmuch-config << EOF
56
57         [addressbook]
58         path=/home/YOURUSERNAME/.notmuch-abook.db
59         backend=sqlite3
60
61         EOF
62
63 where YOURUSERNAME is your home directory. Then, you can sync the addressbook cache
64 by running. It will create the database file specified in configuration, and go through
65 all notmuch's indexed mails to get all addresses headers and cache them. It takes around
66 20 seconds on my 10000 mails index:
67
68         % notmuch_abook create
69
70 And you can query for addresses using the lookup command, which will match the beginning
71 of each word in the name and address, as follows:
72
73         % notmuch_abook lookup Foo
74         Foobar Bar <bar@bar.com>
75         Bar Foobar <bar@bar.com>
76         Bar Bar <foobar@bar.com>
77         Bar Bar <bar@foobar.com>
78         Bar Bar <bar@bar.foo>
79
80 If you're using vim, when you edit a mail having a filetype set to mail, you will be
81 able to open a completion menu when you do <C-x><C-u> at every address header.