Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 404 lines (296 sloc) 14.842 kb
e8d2572 @MarcWeber sample vimrc is a guide - of course you should only copy paste what y…
authored
1 " minimal useful unbiased recommended .vimrc:
2 " http://vim.wikia.com/wiki/Example_vimrc
3 " or
4 " :h vimrc_example.vim
5 "
6 " more useful info for new users:
7 " http://vim.wikia.com/wiki/Category:Getting_started
7a8342d @MarcWeber complete all directories found on disk
authored
8
9
9be2011 @MarcWeber adding sample .vimrc file
authored
10 " kept recoding the same things over and over again.
11 " So I write what I think is useful to you here.
12 "
13 " How to use?
e8d2572 @MarcWeber sample vimrc is a guide - of course you should only copy paste what y…
authored
14 " Skim it - then copy paste the lines you like into your personal .vimrc file.
15 " Its a rough guide giving you hints about what can be done rather than
16 " what should be done
9be2011 @MarcWeber adding sample .vimrc file
authored
17
18
19 " these markers { { { enable folding. see modeline at the bottom
20 " You don't have to close them if you append the folding level.
21
e751d31 @MarcWeber bug fix + vimpyre alternative
authored
22 " set nocompatible should be default. This is done automatically if a .vimrc
23 " or .gvimrc exists. Explicitly listing it here for completness.
9be2011 @MarcWeber adding sample .vimrc file
authored
24 set nocompatible
25
26
27 " You should have this in your .vimrc:
28 " (The {{ { starts a fold.
29 " type zR to open all or za to open one fold only
30 " zM folds everything again
31
32 " enable filetype, plugin and syntax support {{{1
33 " This means
34 filetype indent plugin on | syn on
35
36 " allow buffers to go in background without saving etc.
37 set hidden
38
39 " useful mappings: {{{1
40
41 " open this file fast so that you can take notes below the line "finish" and
42 " add more mappings:
43 noremap \c :e ~/.vimrc<cr>
44
45 " :w! is always bad to type. So create your own mapping for it. Example:
46 noremap \w :w!<cr>
47
48 " you may want to remove the <c-d> if you have many files opened
49 " This switches buffers
50 " Note: :b foo will also select some-foo-text.txt file if it was opened :)
51 noremap \b :b<space><c-d>
52
53 " being able to open the help fast is always fine.
54 " note that you can use tab / shift -tab to select next / previous match
55 " also glob patterns are allowed. Eg :h com*func<tab>
56 noremap \h :h<space>
57
58 " open one file, use tab and shift-tab again if there are multiple files
59 " after using this mapping the command line should have started showing
60 " :e **/* . Eg use :e **/*fil*txt to match file.txt in any subdir
61 noremap \e :e<space>**/*
62
63 " open multiple files at once. Eg add .txt to open all .txt files
64 " Using :bn @: you can cycle them all
65 " :bn = :bnext @: repeats last command
66 noremap \n :n<space>**/*
67
d475eb6 @MarcWeber adding another important line to demo .vimrc
authored
68 " open a filetype file. Those files are sourced by Vim to setup filetype
4a34a3f @MarcWeber url online pointer to documentation to make it clickable (requested b…
authored
69 " specific mappings. Eg use it for defining commands / mappings which apply
70 " for python or perl files only
71 " eg command -buffer DoStuff call DoStuff()
72 " or map <buffer> \dostuff :call DoStuff()<cr>
5e8dba7 @MarcWeber use --depth 1, after in sample rc (ft)
authored
73 noremap \ft :exec 'e ~/.vim/after/ftplugin/'.&filetype.'_you.vim'<cr>
d475eb6 @MarcWeber adding another important line to demo .vimrc
authored
74
a2d4981 @MarcWeber fix searching by number, add \ip as sample
authored
75 " when pasting code you may want to enable paste option so that Vim doesn't
76 " treat the pasted text like typed text. Typed text casues vim to to repeating
77 " comments and change indentation - when pasting you don't want this.
78 noremap \ip :set invpaste<bar>echo &paste ? 'pasting is on' : 'pasting is off'
79
1802302 @MarcWeber q tip and glob open using tlibs List function
authored
80 " for windows: make backspace work. Doesn't hurt on linux. This should be
81 " default!
e751d31 @MarcWeber bug fix + vimpyre alternative
authored
82 set bs=indent,eol,star
83 " (deprecated:) set bs=2
1802302 @MarcWeber q tip and glob open using tlibs List function
authored
84
9be2011 @MarcWeber adding sample .vimrc file
authored
85 " foreign plugin vim-addon-manager {{{1
86
87 " commenting this code because I assume you already have it in your ~/.vimrc:
88
89 " tell Vim where to find the autoload function:
90 " set runtimepath+=~/vim-plugins/vim-addon-manager
91
92 " Activate the addons called 'JSON', 'name1', 'name2'
93 " This adds them to runtimepath and ensures that plugin/* and after/plugin/*
94 " files are sourced. JSON is not that important. It highlights the
95 " NAME-addon-info.txt files. Probably you want to substitude nameN by plugins
96 " such as snipMate, tlib etc.
5ae1943 @MarcWeber adding testcase
authored
97
e7f8fde @Silex Renamed scriptmanager to vam.
Silex authored
98 " call vam#ActivateAddons(['JSON',"tmru","matchit.zip","vim-dev-plugin","name1","name2"])
c374390 @MarcWeber update sample .rc file
authored
99 " JSON: syntax highlighting for the *info* files
100 " tmru: list of most recentely used files
101 " matchit.zip: make % (match to mathing items such as opening closing parenthesis) even smarter
102 " vim-dev-plugin: smarter omni completion and goto autoload function for VimL scripts
9be2011 @MarcWeber adding sample .vimrc file
authored
103
104 " foreign plugins tlib {{{1
105
106 " this is from tlib. I highly recommend having a look at that library.
c374390 @MarcWeber update sample .rc file
authored
107 " Eg its plugin tmru (most recently used files) provides the command
108 " TRecentlyUsedFiles you can map to easily:
9be2011 @MarcWeber adding sample .vimrc file
authored
109 noremap \r :TRecentlyUsedFiles<cr>
e8d2572 @MarcWeber sample vimrc is a guide - of course you should only copy paste what y…
authored
110 " the most simple alternative built into vim is the :oldfiles command
111 " however it may not work that wel if you use many vim instances at the same
112 " time
c374390 @MarcWeber update sample .rc file
authored
113
1802302 @MarcWeber q tip and glob open using tlibs List function
authored
114 " simple glob open based on tlib's List function (similar to TCommand or fuzzy
115 " plugin etc)
2be358a @MarcWeber make glob open faster, add au! (samplerc)
authored
116
117 " don't ask me why glob() from Vim is that slow .. :(
deb39ad @MarcWeber document ways how to add your own plugins to the pool and how to set …
authored
118 " one reason is that it doesn't follow symlinks (unless you pass -L to find)
2be358a @MarcWeber make glob open faster, add au! (samplerc)
authored
119 fun! FastGlob(glob)
deb39ad @MarcWeber document ways how to add your own plugins to the pool and how to set …
authored
120 let g = '^'.a:glob.'$'
e751d31 @MarcWeber bug fix + vimpyre alternative
authored
121 let replace = {'**': '.*','*': '[^/\\]*','.': '\.'}
2be358a @MarcWeber make glob open faster, add au! (samplerc)
authored
122 let g = substitute(g, '\(\*\*\|\*\|\.\)', '\='.string(replace).'[submatch(1)]','g')
123 let cmd = 'find | grep -e '.shellescape(g)
124 " let exclude = a:exclude_pattern == ''? '' : ' | grep -v -e '.shellescape(a:exclude_pattern)
125 " let cmd .= exclude
126 return system(cmd)
127 endf
128 noremap \go :exec 'e '. fnameescape(tlib#input#List('s','select file', split(FastGlob(input('glob pattern, curr dir:','**/*')),"\n") ))<cr>
9be2011 @MarcWeber adding sample .vimrc file
authored
129
02662a8 @MarcWeber people miss the gihtub:name/repo feature. Make it easier to find
authored
130 " sometimes when using tags the list is too long. filtering it by library or
131 " such can easily be achived by such code: {{{'
132 fun! SelectTag(regex)
133 let tag = eval(tlib#input#List('s','select tag', map(taglist(a:regex), 'string([v:val.kind, v:val.filename, v:val.cmd])')))
134 exec 'e '.fnameescape(tag[1])
135 exec tag[2]
136 endf
137 command!-nargs=1 TJump call SelectTag(<f-args>)
138
139 " }}}
93a63b3 @MarcWeber implement full update report telling user which plugins were updated,…
authored
140 " select a buffer from list
2be358a @MarcWeber make glob open faster, add au! (samplerc)
authored
141 command! SelectBuf exec 'b '.matchstr( tlib#input#List('s', 'select buffer', tlib#cmd#OutputAsList('ls')), '^\s*\zs\d\+\ze')
93a63b3 @MarcWeber implement full update report telling user which plugins were updated,…
authored
142 noremap! \sb :SelectBuf<cr>
02662a8 @MarcWeber people miss the gihtub:name/repo feature. Make it easier to find
authored
143
9be2011 @MarcWeber adding sample .vimrc file
authored
144 " dummy func to enabling you to load this file after adding the top level {{{1
145 " dir to runtimepath using :set runtimpeth+=ROOT
146 fun! sample_vimrc_for_new_users#Load()
147 " no code. If this function is called this file is sourced
adf817f @MarcWeber move pointers to getting started top & paying attention to ZyX's advice
authored
148 " As alternative this can be used:
149 " runtime autoload/sample_vimrc_for_new_users.vim
9be2011 @MarcWeber adding sample .vimrc file
authored
150 endf
151
5e8dba7 @MarcWeber use --depth 1, after in sample rc (ft)
authored
152 " create directory for files before Vim tries writing them:
153 augroup CREATE_MISSING_DIR_ON_BUF_WRITE
2be358a @MarcWeber make glob open faster, add au! (samplerc)
authored
154 au!
5e8dba7 @MarcWeber use --depth 1, after in sample rc (ft)
authored
155 autocmd BufWritePre * if !isdirectory(expand('%:h')) | call mkdir(expand('%:h'),'p') | endif
156 augroup end
157
9ad22be @MarcWeber tidy up docs:
authored
158 finish
159 Vim is ignoring this text after finish.
160
161 DON'T MISS THESE {{{1
162
163 Each vim boolean setting can be off or on. You can invert by invNAME. Example:
164 enable setting: :set swap
165 disable setting: :set noswap
166 toggle setting: :set invswap
167 Settings can be found easily by :h '*chars*'<c-d>
168
169 == typing characters which are not on your keyboard ==
170 digraphs: type chars which are untypable, for example:
005f279 @MarcWeber fix renaming, describe design goal "declarative"
authored
171 c-k =e : types € (see :h digraph)
172
9ad22be @MarcWeber tidy up docs:
authored
173 == completions ==
c6745af @MarcWeber more tips for new users
authored
174 c-x c-f : file completion
175 c-x c-l : line completion
176 c-n : kind of keyword completion - completes everything found in all opened buffers.
177 So maybe even consider openining many files uing :n **/*.ext
20bbf0e @MarcWeber add more movements to sample rc and a visualization about them
authored
178 (if you're a nerd get vim-addon-completion and use the camel case buffer completion found in there)
c6745af @MarcWeber more tips for new users
authored
179 all: :h ins-completion
180
9ad22be @MarcWeber tidy up docs:
authored
181 == most important movement keys ==
20bbf0e @MarcWeber add more movements to sample rc and a visualization about them
authored
182 hjkl - as experienced user you'll notice that you don't use them that often.
9ad22be @MarcWeber tidy up docs:
authored
183 So you should at least know about the following and have a look at :h motion.txt
184 and create your own by mappings
c6745af @MarcWeber more tips for new users
authored
185
20bbf0e @MarcWeber add more movements to sample rc and a visualization about them
authored
186 how to reach insert mode:
187 | is cursor location
188
189 O
190 I i|a A
191 o
192
193 important movements and their relation:
c6745af @MarcWeber more tips for new users
authored
194
20bbf0e @MarcWeber add more movements to sample rc and a visualization about them
authored
195 gg
196 <c-u> H (top line window)
c6745af @MarcWeber more tips for new users
authored
197
20bbf0e @MarcWeber add more movements to sample rc and a visualization about them
authored
198 - k
199 0 h | l $ M
200 <cr> j
201 <c-v>
202 L
203 G
204
205
206 movements:
c6745af @MarcWeber more tips for new users
authored
207
208 use search / ? to place cursor. Remember that typing a word is not always the
209 most efficient way. Eg try /ys t this. And you'll get excatly
210 one match in the whole document.
211
212 c-o c-i : jump list history
213
214 g; : where did I edit last (current buffer) - you can repeat it
215
216 Learn about w vs W. Try it CURSOR_HERE.then.type.it (same for e,E)
217
218 f,F,t,T : move to char or just before it forward / backward current line. (A
219 must)
220
20bbf0e @MarcWeber add more movements to sample rc and a visualization about them
authored
221 be faster: delete then goto insert mode:
222 C: deletes till end of line
223 c a-movement-action: deletes characters visited while moving
224
225 more movements:
226 (, ): move by sentence
227 [[, ]], {, } : more blockwise movements which are often helpful
228 ...
229
1802302 @MarcWeber q tip and glob open using tlibs List function
authored
230 This script may also have its usage: Jump to charater location fast:
231 http://www.vim.org/scripts/script.php?script_id=3437
20bbf0e @MarcWeber add more movements to sample rc and a visualization about them
authored
232
c374390 @MarcWeber update sample .rc file
authored
233 How to get O(1) access to your files you're editing at the moment {{{1
c6745af @MarcWeber more tips for new users
authored
234
235 Yes :b name is fine, cause it matches HeHiname.ext. Still too much to type.
236 Usually you work with only a set of buffers. Open them in tabs. Add something
237 like this to your .vimrc so that you can switch buffers using m-1 m-2 etc:
238
239 " m-X key jump to tab X
240 for i in range(1,8)
241 exec 'map <m-'.i.'> '.i.'gt'
242 endfor
243
244 " faster novigation in windows:
245 for i in ["i","j","k","l","q"]
246 exec 'noremap <m-s-'.i.'> <c-w>'.i
247 endfor
248
249 The ways to optimize code navigation are endless. Watch yourself.
250 If you think something takes too long - optimize it.
251
22ed8b2 @MarcWeber reference emacscommandline plugin
authored
252 Bindings in command line are shitty?
253 yes - remap them - or use "emacscommandline" plugin which does this for you.
254 or use q: (normal mode) or c-f in commandline
255
c6745af @MarcWeber more tips for new users
authored
256
9ad22be @MarcWeber tidy up docs:
authored
257
258 == indentation, spaces, tabs ==
259 Tab: default behavior of vim is: add &tabstop spaces unless expandtab is not
260 set. You can always insert real tabs by <c-v><tab>. However tabstob should be
261 treated as display setting. Use sw setting and c-t, c-d instead.
262
263 c-t: increase indentation
264 c-d: decrease indentation
265 c-f: auto indent current line (requires indentation setup)
266 :setlocal sw=4: use 4 spacse for indentation
267 :setlocal expandtab: expand tab to spaces (default)
268 >3j . . increase indentation of 3 lines and repeat two times
269 :setlocal tabstop: a tab is viewed as how many spaces in a file?
270
271 :set list : displays spaces and tabs
272
273 project specific settings: see vim-addon-local-vimrc
274
275
276
9be2011 @MarcWeber adding sample .vimrc file
authored
277 MY COMMENTS ABOUT VIM AND ITS USAGE {{{1
278 ========================================
279
280
281 I like Vim cause its that fast and easy to extend.
282 I also learned that VimL is a nice language. It was ahead of time when it
283 was invented. However today it can be considered limiting in various ways.
284 Eg you don't want to write parsers in it. Its too slow for those use cases.
c374390 @MarcWeber update sample .rc file
authored
285 Yet its powerful enough to make everydays work easier - even competitive to
286 bloated IDEs. Example plugins you should know about:
9be2011 @MarcWeber adding sample .vimrc file
authored
287
3cc5120 @MarcWeber - on unix force unix line endings for Vim files because \r\n is causi…
authored
288 - tlib library (and all of Tom's plugins
9be2011 @MarcWeber adding sample .vimrc file
authored
289
290 - snipmate (or xptemplate): Insert text snippets. Its not only about speed.
291 Snippets are a nice way to organize your memos.
292
293 - matchit: match everything, eg matching xml tags, fun -> return -> endfun
294 statements (same for for, while etc)
295
296 - The_NERD_tree: directory tree in Vim. You can easily hit the limits of
297 Vim/VimL here whene opening large directories it takes a way too long :-(
298 Yet you may find it useful.
299
300 - commenting plugins
301
9ad22be @MarcWeber tidy up docs:
authored
302 - vim-addon-local-vimrc (project specific settings)
303
9be2011 @MarcWeber adding sample .vimrc file
authored
304 - ... (You want a plugin added here?)
305
306 What you should know about:
307 - :h motion.txt (skim it once)
9ad22be @MarcWeber tidy up docs:
authored
308 - Vim keeps history as tree. (g+ g- mappings)
9be2011 @MarcWeber adding sample .vimrc file
authored
309 - :h quickfix (load compiler output into an error list)
310 - how to use tags - because this (sometimes fuzzzy) thing
311 is still fast to setup and works very well for many use cases.
312 - Vim can assist you in spelling
313
314
315 most important mappings / commands:
316 g; = jump back in list of last edited locations
317 <c-o> <c-i> = jump back and forth in location list
318 <c-^> = toggle buffers
7ae1013 @MarcWeber replace &yes by ye&s because pressing y gets a habit. Users should no…
authored
319 c-w then one of v s w q t h j k l (z) : move cursor, split windows, quit buffer
9be2011 @MarcWeber adding sample .vimrc file
authored
320
321 q:, ?:, /: : Open mini buffer to browse or edit command or search history
322 You can open this from command line using <c-f>!
323 ... I could keep writing for 2 hours now at least.
324
325
326 I'm also aware of Emacs emulating most important editing features of Vim.
327 Eg there is the vimpulse plugin for Emacs. So I know that I should use the
328 tool which is best for a given task. This can be Vim for coding. But for debugging
329 you may prefer Emacs or a bloated IDE such as Eclipse, Netbeans, IDEA (which all have
330 vim like keybindgs!).
331
332 What are the limitations causing greatest impact to software developers using Vim?
333 - no async communication support unless you depend on client-server feature
334 which requires X. This means Vim will hang until an operation has finished
335 when interfacing with external tools.
336 Impact: People tried writing debugger features. But all solutions are kind
337 of doomed unless Vim gets a nice async communication interface.
514237c @MarcWeber document known ways to workaround missiing async / shell features in Vim
authored
338
339 Possible known ways to work around it?
340
3cc5120 @MarcWeber - on unix force unix line endings for Vim files because \r\n is causi…
authored
341 - vim-addon-async (depends on client-server but works very well)
342
514237c @MarcWeber document known ways to workaround missiing async / shell features in Vim
authored
343 - implement windows version of this patch
344 http://github.com/bartman/vim.git (which still can be improved a lot)
345 and make it it poll file handlers when not typing. Implement a shell
346 like interface. doc: http://github.com/bartman/vim/wiki/_pages
347
348 - There is a patch which let's you start a shell in Vim. I don't think
349 it got updated (which is linux only)
350 http://www.wana.at/vimshell/
351 (Maybe cygwin or such ?) - I never tried it.
352
353 - vimshell (www.vim.org). You have to get a dell or such. I think this
354 could satisfy you.
355 (vcs: http://github.com/Shougo/vimshell)
356
357 - screen (see other mail)
358 c-a S splits the window
359 c-a tab switches focus
360
361 if you run interpreter this way: tcl | tee log
362
363 you may have a chance getting errors into quickfix or such
364
365 (requires cygwin or such - I never tried it on Windows ?)
366
367 use Emacs and vimpulse (I hate to say it)
368
c374390 @MarcWeber update sample .rc file
authored
369
f03b9a3 @MarcWeber add more references to sample .vimrc
authored
370 - Many coding helpers should not have been written in VimL. They should have
9be2011 @MarcWeber adding sample .vimrc file
authored
371 been written in a proper language so that all open source editors can
372 benefit from their features. An Example is the broken PHP completion which
373 doesn't even complete static member functions like A::foo();
374
375 Examples how this can be done better:
376 * vim-addon-scion (Haskell development helper app is written in Haskell. Vim
377 is only a coding editor backend)
378 * codefellow (same for Scala).
9ad22be @MarcWeber tidy up docs:
authored
379 * eclim (Eclipse features exposed to Vim And Vim backend implementation)
9be2011 @MarcWeber adding sample .vimrc file
authored
380
c374390 @MarcWeber update sample .rc file
authored
381 Vim can be one of the fastest editors you'll start to love (and hate for some
382 of the shortcomings)
9be2011 @MarcWeber adding sample .vimrc file
authored
383
f03b9a3 @MarcWeber add more references to sample .vimrc
authored
384
385 " additional resources - how to continue learning about Vim? {{{1
386 The way to start learning Vim:
387 vimtutor
388
389 additional advanced info:
390 http://github.com/dahu/LearnVim
391
392 Vim Wiki:
393 http://vim.wikia.com
4a34a3f @MarcWeber url online pointer to documentation to make it clickable (requested b…
authored
394 Checkout its sample .vimrc: http://vim.wikia.com/wiki/Example_vimrc
f03b9a3 @MarcWeber add more references to sample .vimrc
authored
395
396 join #vim (irc.freenode.net)
397
398 join the mailinglist (www.vim.org -> community)
399
400 Tell me to add additional resources here
401
402
9be2011 @MarcWeber adding sample .vimrc file
authored
403 " this modeline tells vim to enable folding {{{1
Something went wrong with that request. Please try again.