-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTIPS
421 lines (306 loc) · 15.8 KB
/
TIPS
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
Those are some tips I have stumbled upon. This list will change and items will
be removed, so check the repository log for more.
in Bash, you can use C-X C-E to edit the current command line in $EDITOR and
execute it when it's saved. You can also use the fc builtin to edit the
previous command and execute it.
use :helpgrep, it's great. Finds lots of stuff that :help doesn't.
use q: and q/ and q? to quickly get one of the last commands or searches, then
press Enter to execute. You can also use <C-F> in command line mode to open the
command history.
use <C-^> to quickly switch to the alternate file.
<C-X><C-L> : Line complete SUPER USEFUL. see :help ins-completion for more
about the Ctrl-X mode.
:h slash<C-D><Tab> : type control-D and get a list all help topics containing
slash (plus use TAB for Help completion)
:h i_CTRL-R : help for <C-R> in insert mode
:h c_CTRL-R : help for <C-R> in command mode
:h v_CTRL-V : visual mode
:h 'ai : help on setting option 'autoindent'
:helpgrep x : grep help for x, then use quickfix commands
you can use :diffget and :diffput. Also in visual mode:
vmap \do :diffget<CR>
vmap \dp :diffput<CR>
quickfix commands - navigate quickfix list:
:cc [#] : display result #nr or last result
:cnext : next, prev result, next file, prev file
:cprev
:cnfile
:cpfile
location list commands - a different list independent of the quickfix list:
:ll [#]
:lnext
:lprev
:lnfile
:lcfile
See also the quickfixsigns plugin, which shows mark names and quickfix
locations in the left margin.
popup menu convenience bindings:
inoremap <expr> <Esc> pumvisible() ? "\<C-e>" : "\<Esc>"
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"
inoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<Down>"
inoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<Up>"
inoremap <expr> <C-d> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<C-d>"
inoremap <expr> <C-u> pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<C-u>"
:Ex : file explorer, note capital E
\be : show buffer explorer (requires plugin)
:ls : list of buffers
i_CTRL-R=5*5 : insert 25 into text
guu : lowercase line
gUU : uppercase line
~ : invert case (upper->lower; lower->upper) of current character
gf : open file name under cursor (SUPER)
'. : jump to last modification line (SUPER)
`. : jump to exact spot in last modification line
:ju(mps) : list of your movements {{help|jump-motions}}
:history : list of all your commands
:reg : display contents of all registers
:r!ls : reads in output of ls (use dir on Windows)
!1} sort : sorts paragraph; this is issued from normal mode!)
:bn : next buffer
:bp : previous buffer
:brew : rewind to first buffer in buffer list
:tabe : open new tab page (Ctrl-PgUp, Ctrl-PgDown for next/previous tab)
:tabm n : move tab to position n (0=leftmost position)
:args : display argument list
:sav module.py : Save current file as module.py and "move" to module.py
:help :Nread : use ftp/scp to edit remote files in Vim
gv : restores last visual range
Between lines with marks a and b (inclusive), append each line starting with
"Error" to a file:
:'a,'b g/^Error/ .w >> errors.txt
gq : formats the selected range
ls | vim - : edit a PIPE!
Pulling objects onto command/search line (SUPER)
CTRL-R CTRL-W : pull word under the cursor into a command line or search
CTRL-R CTRL-A : pull whole word including punctuation
CTRL-R - : pull small register
CTRL-R [0-9a-z] : pull named registers
CTRL-R % : pull file name (also # for alternative file name)
<C-X><C-F> :insert name of a file in current directory
<c-r>: : pull in last command line command
<c-r>/ : pull in last search command
/\C : make your search case-sensitive
/<!--\_p\{-}--> : search for multiple line comments
:%s/FILE/\=expand("%:t") : substitute any word (say FILE) by actual filename
check out the taglist plugin - navigate source code structure:
http://www.vim.org/scripts/script.php?script_id=273
#make sure to use pathogen for installing scripts:
#http://www.vim.org/scripts/script.php?script_id=2332
^^ no, use the much better vam instead!! it's included in this vimrc:
http://www.vim.org/scripts/script.php?script_id=2905
to use a terminal inside vim windows:
http://code.google.com/p/conque/wiki/Usage
or as an alternative:
http://www.wana.at/vimshell/
:set dictionary=/usr/share/dict/words
ctrl-x ctrl-k - dictionary completion
ctrl-w - erases word (insert mode...
ctrl-u - erases line ...or on command line)
g* - search for partial word under cursor
(repeat with n)
[I - show lines with matching word under cursor
Neat little thing. <leader>ff displays a list of occurrences of the word under point and asks which to jump to:
nmap <Leader>ff [I:let nr = input("Which one: ")<Bar>exe "normal " . nr ."[\t"<CR>
d'k - delete from current position to mark k
'a-z - marks in the same file
'A-Z - marks shared beteween files
ctrl-t, ctrl-d - indent current line forward, backwards
(insert mode)
:set pastetoggle=<f5>
V= - select text, then reformat with =
= - will correct alignment of code
== - one line;
gq - reformat paragraph
:help equalprg - external program for =.
regular expressions: \zs and \ze define the "actual match". So
therefore :s/aaa\zsxxxze/yyy/ is the same as :s/aaaxxx/aaayyy/.
You can use \0 to refer to the whole match. & is a shorthand for \0.
global actions: you can use g/re/s/^/str/ to insert text into matching lines.
You can also use g/re/normal Itext to do the same, and "text" will be indented.
select block, then :fold
zo - open
zc - close
See :help foldmethod for options, and use :mkview and :loadview to save and
restore the current window.
ctrl-w ctrl-w - move cursor to another window (cycle)
:hide - close current window
:only - keep only this window open
:ls - show current buffers
:b 2 - open buffer #2 in this window
:tag TAB - list the known tags
:tag function_name - jump to that function
ctrl-t - goes to previous spot where you called :tag
ctrl-] - calls :tag on the word under the cursor
:ptag - open tag in preview window (also ctrl-w })
:pclose - close preview window
:map <f9> :make - map the F9 key to run make
:set makeprg - change what :make does
:copen - open a mini-window with list of errors
- hit enter on an error to jump to line
:cclose - closes the mini-window
:cw - toggles the mini-window (if errors exist)
vmap <buffer> ;bo "zdi<B><c-r>z</B><esc> - puts bold html tags around
something you have visually selected.
nnoremap <F6> <C-W>w - ???
nnoremap <S-F6> <C-W>W - ???
map <C-L> :noh<CR>:redraw!<CR> - ???
:reg - show named registers and what's in them
qk - records edits into register k
(q again to stop recording)
@k - execute recorded edits (macro)
@@ - repeat last one
5@@ - repeat 5 times
"kp - print macro k
(e.g., to edit or add to .vimrc)
"kd - replace register k with what cursor is on
yanking, deleting, and pasting windows around to rearrange them:
http://www.gregsexton.org/2011/04/enhancing-window-movement-and-positioning-in-vim/
improving the display of folds:
http://www.gregsexton.org/2011/03/improving-the-text-displayed-in-a-fold/
-----------
motions:
w - word
s - sentence
p - paragraph
" - double-quoted string
' - single-quoted string
` - back-quoted string
) - parenthesized block
] - bracketed block
} - brace block
t - contents of an xml tag
> - definition of an xml tag (what is between < and >)
i - indent-level block (ai gets one line before the indent level starts, eg if)
for more info on motions (plugins for camel case motions and function arg
motions) see this page:
http://blog.carbonfive.com/2011/10/17/vim-text-objects-the-definitive-guide/
see http://vimgolf.com/ for lots of tips & tricks
Debugging startup time: you can do this: vim +q --startuptime ~/tmp/startuptime.txt
it will make a log of what happens during startup and how long it takes.
Ripped from Zesty:
" The following beast is something i didn't write... it will return the
" syntax highlighting group that the current "thing" under the cursor
" belongs to -- very useful for figuring out what to change as far as
" syntax highlighting goes.
nmap <silent> ,qq :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
----------------- Useful plugins:
----------------- Note, the below plugins are pasted in with their sales pitch;
----------------- only a few of the comments are my own opinion. Use your best
----------------- judgement.
CamelCaseComplete : Insert mode completion that expands CamelCaseWords and
underscore_words. E.g. expand asd -> AnotherStaticDescriptor,
air_shift_distance
buffet.vim : A fast, easy to use buffer list plugin for switching and managing
buffers. Useful for people with loads upon loads of buffers, tabs, and windows
open.
textobj-user : Support for user-defined text objects. Good for experimenting?
gf-diff : In diff output, go to the file being diffed when you press "gf".
viewdoc : Flexible viewer for any documentation (help/man/pydoc/perldoc/etc.)
ft_improved : improved f/t command (searches whole file, not just current line)
inline_edit.vim : Edit code that's embedded within other code. Opens the
inlined code in a new buffer.
slide show : A tool for viewing source code in a slide show fashion.
Threesome : A plugin for resolving conflicts during three-way merges. This is a
REALLY NICE, ide-style plugin for resolving merge conflicts. Very involved.
Uses mappings on the localleader.
diffwindow_movement : Movement over changes in a diff window. Defines movements
and text objects for diff files.
TVO: The Vim Outliner : a lot of people use it, but i still don't see its
power. Looks like it might be useful for knowledge organization or for work
planning.
code_complete : really cool completion plugin based on snippets; autogenerates
whole blocks of code and puts in placeholders for places where you want to type
things; tab jumps to those placeholders. Demo can be found at
http://files.myopera.com/mbbill/files/code_complete.gif
xptemplate: wow, nice! enter a snippet/template into your code and then press
tab to navigate the various places you can edit.
Align : Help folks to align text, eqns, declarations, tables, etc -- really
cool if you're into aligning multiple lines on equals signs, commas, and so on.
Mark : a little script to highlight several words in different colors
simultaneously -- could be useful if bindings to create marks are removed and
replaced with :Commands.
MultipleSearch2.vim : Improve Multiple search -- honorable mention. Great idea,
I want it to work, but it's buggy. The original version has the same bugs.
lookupfile : Lookup files using Vim7 ins-completion -- I know people like this
sort of thing, so here it is.
Command-T : Fast file navigation for VIM. Similar to lookupfile - search for
files and open them. I guess it's based on TextMate, having never used that
program.
FindFile : Open file quickly by using autocomplete. Again, similar to
lookupfile and Command-T.
horses and sheep : http://www.vim.org/scripts/script.php?script_id=1301 - see it
vim-easymotion : really cool, vim motions via text hints. The whole text is
grayed out and the hints stand out in bright red. Then type the hint to go
where the hint is. Not sure how it would integrate with my current bindings,
though.
PreciseJump : similar idea to vim-easymotion above, not as polished. Did not
work at all for me. Weird key bindings.
vimbuddy.vim : puts a smiley on your status bar. Smiley frowns on errors and
does other stuff.
vimsh.tar.gz : *almost great*. Needs to either strip or interpret ansi escape
codes; should be engaged via a command, and not via sourcing the script; the
plugin layout in the .zip could be better, it currently needs manual fixing if
you're using vam.
undo_tags : I can't figure out this plugin. Looks like it could be useful,
though. I'll have to figure it out one day.
unimpaired.vim : Pairs of handy bracket mappings -- honorable mention: great
idea with the square brackets doing actions that can work in pairs, but the
actions actually implemented are not things I would normally use.
narrow : Emulate Emacs' narrowing feature -- honorable mention: good idea, not
nearly complete execution. select a range, use :Narrow to only display and
execute commands on that part; the rest is inaccessible. Except here
"inaccessible" still just means folded-away, and the commands are in fact not
limited to the range you did :Narrow on.
Tumblr : Post to Tumblr
----------------- Useful programming language plugins:
----------------- Note, the below plugins are pasted in with their sales pitch;
----------------- only a few of the comments are my own opinion. Use your best
----------------- judgement.
tagport : Find and yank Python import statement for keyword under cursor.
Useful for Django!
https://github.com/klen/python-mode : python mode integrating pyflakes, rope,
and other general python-related stuff.
http://www.vim.org/scripts/script.php?script_id=3782 : a python syntax
definition (never used it)
Vimpy : Vimpy helps in Navigating through Python code easy. (ctags-ish)
pylint-mode : Pylint-mode is a vim mode that allows you to use the pylint
library in vim to provide features like python code looking for bugs.
SimpylFold : No-BS Python code folding
Superior Haskell Interaction Mode (SHIM) : GHCi integration for VIM. Attempts
to display a ghci with the current buffer loaded in a vim window. However
typing into the interpreter doesn't work for me.
scion: https://github.com/nominolo/scion#readme - Haskell IDE for vim
VimPdb : a totally integrated environment which allows you to do breakpoint
debugging in Vim with Pdb. Uses keyboard bindings which I don't like. Or use
this for setting breakpoints: https://dev.launchpad.net/UltimateVimPythonSetup
CRefVim : a C-reference manual especially designed for Vim -- get reference for
word under cursor with <Leader>cr
Pydiction : Tab-complete your Python code -- tab-completion that works without
actually parsing the modules, good for some things, though i don't like the
interface.
ZenCoding.vim : vim plugins for HTML and CSS hi-speed coding -- real cool!
DBGp client : a remote debugger interface to the DBGp protocol (tested only
with XDebug/PHP)
python_ifold : Improved version of python_fold. Uses folding expression for
python code.
vim-ref : tries to be some universal K support for a lot of different
languages. Supposedly you can make it work with haskell/hoogle.
PHP-correct-Indenting : A new indent script for php with many improvements
never seen before
jpythonfold.vim : A better python fold script
CCTree : would be amazing if it worked for Python, Haskell, etc. Only works for
C, but looks real cool.
idevim.tgz : Control Gdb from inside Vim
remote PHP debugger : remote debugger interface to DBGp protocol.
VimDebug : Visual debugger for Perl, Ruby, and Python (updated 03/2011)
Decho : Vim script internal debugger (output in separate window, tab, or remote
vim)
gdbvim.tar.gz : Watch in vim what you debug in gdb. And more.
Efficient python folding : Fold python code nicely and toggle with one
keystroke
pylint.vim : compiler plugin for python style checking tool
phpfolding.vim : Automatic folding of PHP functions, classes,.. (also folds
related PhpDoc)
To align columns in text, you can do the following. It will search for a string
called "Test", and insert spaces on the left of it, until "Test" starts on the
126th column: :'<,'>s/^\(.*\)\zeTest/\=printf("%-126s", submatch(1))/