summaryrefslogtreecommitdiffstats
path: root/software/vim.page
blob: 84db1214403352c7d872099ceb907ec4d6ae35b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
format: rst
toc: no
...

============
It's vim!
============

Typical .vimrc
------------------
Here's what a typical ``.vimrc`` looks like for me::

    if has('syntax') && (&t_Co > 2)
        syntax on
    endif

    set history=50
    set wildmode=list:longest,full
    set showmode
    set showcmd
    set smartcase
    set shiftwidth=4
    set tabstop=4
    set shiftround
    set expandtab
    set autoindent

    autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except, finally,def,class

Commands
-------------
Search and replace globally::

    :%s/before/after/g

Tricks
-------------
I often want to pull a particular gnarly line or two from another file; here's
the command I use to grab three lines of context around 'phrase'::

    :r!grep -A 3 'phrase' ../otherfile.txt

Pasting a lot of text with insert mode if very slow because vim redraws the
terminal for every single character entered (as you would want if you were
actually typing. To paste in the contents of the X11 clipboard you want to use::

    "*P

(aka quote, star, uppercase-P) in regular mode. This also solves the
autotabbing problem without ":set paste"! You need to have "+xterm_clipboard"
in your ``vim --version`` output for this to work; the ``vim-gtk`` package on
newer Ubuntus has been compiled with this flag (?).

Sometimes you really need tab characters instead of space indendation (eg, when
editing Makefiles). To use tabs when editing a file use::

	:set noexpandtab

If you accidently opened a file you can't write to, you can write out as root
using::

    :w !sudo tee %

Search for trailing whitespace, or just strip it all::

    /\s\+$
    :%s/\s\+$//

Shell Sessions
-------------------
(discovered via
http://www.ktaylor.name/2009/11/vim-screen-lisp-programming-environment.html)

The emacs embeded interpreter mode is very nice for interactively programming
with languages like scheme and python. A similar effect can be achieved with
the `ScreenShell plugin
<http://www.vim.org/scripts/script.php?script_id=2711>`_ and the following
bindings:

    vmap <C-c><C-c> :ScreenSend<CR>
    nmap <C-c><C-c> vip<C-c><C-c>
    nmap <C-x><C-e> :ScreenSend<CR>

`Slimv <http://www.vim.org/scripts/script.php?script_id=2531>`_ is a more
elaborate alternative (SLIME for vim).

Multi-Tab Setup
--------------------
TODO: document my current multi-window configuration, how to re-scale, etc.

``Ctrl-W =`` equalizes window sizes (``Ctrl-W`` is the vierport meta sequence).

Spellcheck
-------------
Do ``set spell`` to start spellchecking in "fly" mode (mispellings
highlighted); do ``set nospell`` to undo.

Hovering over a word in visual, do ``zg`` to add the word to your dictionary,
``z=`` to show suggestions, 

Links to more...
------------------

 - `vim anti-patterns <http://blog.sanctum.geek.nz/vim-anti-patterns/>`_