Penguin
Annotated edit history of VimNotes version 18, including all changes. View license author blame.
Rev Author # Line
5 DanielLawson 1 See also ViNotes
2
3 vim(1) -- potentially the most powerful editor unix users have access to, and one of the best things about it is in actual fact it's not restricted to unix users at all. Anybody can use vim, anywhere (more or less). Its only real drawback is that it's a little difficult to get to grips with at first. This page is not designed to cover basic editing. Rather, this page is a list of tips which will make your vim editing experience more enjoyable, particularly if vim is used as a programming editor.
10 BenStaz 4
12 AristotlePagaltzis 5 !! Indentation
10 BenStaz 6
7 [BenStaz] finds these settings very useful when using vim for coding (any language).
8
9 <verbatim>
17 BenStaz 10 set tabstop=8 " 4 places per tab character
11 set shiftwidth=8 " indent/outdent by 4 places
12 AristotlePagaltzis 12 set expandtab " convert hardtabs to the equivalent number of blanks
17 BenStaz 13 set softtabstop=8 " same value as 'tabstop' == no soft tabstops
12 AristotlePagaltzis 14 set autoindent " indent of new lines as appropriate
10 BenStaz 15 </verbatim>
16
12 AristotlePagaltzis 17 !! Syntax Highlighting
10 BenStaz 18
12 AristotlePagaltzis 19 vim, of course, supports syntax highlighting. Often this isn't on by default. The easiest way to turn this on is to type <tt>:syntax on</tt>. Voila. What's that? You're using a dark background and the highlighting looks terrible? No real problem. Try <tt>:set background=dark</tt>. If you just think it looks horrible, full stop, get a new colourscheme... they’re available from vim.org and go into your <tt>~~/.vim/colors</tt> directory (which you may have to create). Select a different colour scheme using the <tt>:colorscheme</tt> command (see <tt>:help colorscheme</tt>; note that TabCompletion after the command works as you’d expect).
10 BenStaz 20
12 AristotlePagaltzis 21 If you run vim in the terminal your colour schemes are by default limited to 16 colours. Some terminals such as xterm can be compiled with 256 color support. To enable vim to use these add the following lines to your .vimrc:
10 BenStaz 22
12 AristotlePagaltzis 23 <verbatim>
7 KurtGaastra 24 " Enable 256 colors
25 set t_Co=256
26 set t_AB=^[[48;5;%dm
27 set t_AF=^[[38;5;%dm
12 AristotlePagaltzis 28 </verbatim>
9 BenStaz 29
7 KurtGaastra 30 Note that the ^[ should be a literal escape character.
31
12 AristotlePagaltzis 32 Most vim colourschemes will need to be customised a little to look decent in this mode although some (such as xterm16) are designed for it.
9 BenStaz 33
34 You can automatically enable syntax highlighting when starting a new vim text. vim is smart and can automatically adjust the highlighting by looking at the extension of the file. For example, ''vim test.py'' will automatically have python syntax highlighting.
35
36 If you are already in a document and wish to enable syntax highlighting, then use this command.
37
38 *:set filetype=<language>
39
40 eg: for python highlighting:
41
42 *:set filetype=python
43
44 or bash Highlighting:
45
46 *:set filetype=sh
47
48 What syntax highlighting language is currently being used?
49
50 *:set filetype
51
7 KurtGaastra 52 --KurtGaastra
5 DanielLawson 53
6 JohnMcPherson 54 !!Compiling
5 DanielLawson 55
56 To build from within vim, simply use ":make". It's probably a good idea to set your current working directory to the same place as your makefile is located, which you can do with ":chdir <directory>". Vim will build your project, and hopefully jump intelligently to the right place whenever you encounter errors. If you need to set environment variables for your build, it's probably a good idea to set them on your :make line, eg ":make x=n"
57
6 JohnMcPherson 58 !!Buffer Movement
5 DanielLawson 59
60 Vim will support multiple buffers. You can switch between them using the menu in gvim, or if you prefer to use commands you can use the following:
8 IanMcDonald 61 <pre>
5 DanielLawson 62 :bn # next buffer
63 :bp # previous buffer
8 IanMcDonald 64 </pre>
5 DanielLawson 65
66 You can delete a buffer with
8 IanMcDonald 67 <pre>
5 DanielLawson 68 :bd
8 IanMcDonald 69 </pre>
5 DanielLawson 70 or
8 IanMcDonald 71 <pre>
5 DanielLawson 72 :bd n # where n is the number of a buffer
73 :bd % # current buffer
74 :bd # # previous buffer
8 IanMcDonald 75 </pre>
5 DanielLawson 76
77 I map these to keys to make them useful. My [.vimrc] has the following:
8 IanMcDonald 78 <pre>
5 DanielLawson 79 set autowrite
80 nmap <tab> :bn<cr>
81 nmap <s-tab> :bp<cr>
82 nmap <c-f4> :bn<CR>:bd #<CR>
8 IanMcDonald 83 </pre>
5 DanielLawson 84
85 Set autowrite tells vim to save the file when you change buffers. Vim wants to do this, its a bit annoying.
86 The above maps will map tab and shift tab to next and previous buffer, and ctrl-f4 to delete current buffer. ctrl-f4 will delete the current buffer in a way that will preserve any splits you have open, ie it'll move to the next buffer, then delete the previous one.
87
88 --DanielLawson
6 JohnMcPherson 89
90 !!Character Encoding/Unicode
91
12 AristotlePagaltzis 92 ''This section is partially wrong and needs some cleanup.'' —AristotlePagaltzis
93
94 Vim has several options to do with character encoding, and each does slightly different things.
95
96 <tt>encoding</tt>:
97 Used by vim internally for strings held in buffers, registers, expressions, etc.
98 <tt>termencoding</tt>:
99 Tells vim what encoding to display to the terminal, and it will convert text from its internal encoding to this encoding if necessary for display.
100 <tt>fileencoding</tt>:
101 The encoding that files are assumed to be encoded with on disk. Vim will try to auto-detect this; see the following:
102 <tt>fileencodings</tt>:
103 A list of encodings that vim will try, in the order given, when autodetecting the encoding of a file on load. If it can't detect the encoding, it falls back to latin1 (aka iso-8859-1).
104
105 If you want to be modern, and only use [UTF-8] everywhere, put the following in your <tt>.vimrc</tt> file:
106
107 <verbatim>
108 set encoding=utf-8
109 set termencoding=utf-8
110 set fileencoding=utf-8
111 </verbatim>
6 JohnMcPherson 112
113 If you might ever use vim to edit raw binary data, then it's a good idea to make
114 sure that vim doesn't try any conversation on file load:
8 IanMcDonald 115
12 AristotlePagaltzis 116 <verbatim>
117 " leave these as blank, so no conversation done?
118 set fileencoding=
119 set fileencodings=
120 </verbatim>
11 BenStaz 121
12 AristotlePagaltzis 122 !! Miscellaneous
5 DanielLawson 123
12 AristotlePagaltzis 124 Display invisible characters such as Tab and the end-of-line character :
125 <tt>:set list</tt>
13 BenStaz 126
127 Display man page inside vim for the word your cursor is currently over.
128 <tt>Shift + k</tt>
129
130 Display Function Prototype or variable type for the word your cursor is currently over.
14 BenStaz 131 <tt>[ then i</tt>
13 BenStaz 132
133 Move vim cursor to the matching closing symbol for the opening symbol your cursor is on.
134 <tt>%</tt>
135
14 BenStaz 136 Move vim cursor to a particular line.
137 <tt><line_no>G</tt>
13 BenStaz 138
15 BenStaz 139 Automatically create folds in a sensible way according to file type.
16 BenStaz 140 set foldmethod=syntax
5 DanielLawson 141
12 AristotlePagaltzis 142 !!! See also
5 DanielLawson 143
12 AristotlePagaltzis 144 * [Good vim reference guide | http://www.dc.turkuamk.fi/docs/soft/vim/vim.html]
18 AristotlePagaltzis 145
146 ----
147 InNeedOfRefactor

PHP Warning

lib/blame.php:177: Warning: Invalid argument supplied for foreach() (...repeated 4 times)