Vim Tips Wiki
(archive)
(Archive of new edition, repeats 200806,07.)
 
(8 intermediate revisions by 4 users not shown)
Line 2: Line 2:
 
<big>'''This is an archive of the ''Did you know?'' section on the [[Vim Tips Wiki|home page]]'''</big>
 
<big>'''This is an archive of the ''Did you know?'' section on the [[Vim Tips Wiki|home page]]'''</big>
   
Every few weeks, the section on the [[Vim Tips Wiki|home page]] will be replaced. Old items will be moved here so anyone interested can browse them.
+
We occasionally replace the DYK section on the [[Vim Tips Wiki|home page]], and items are copied to here so anyone interested can browse them.
   
 
'''To discuss suggestions for new items, please edit the [[Talk:Did you know|talk page]].'''
 
'''To discuss suggestions for new items, please edit the [[Talk:Did you know|talk page]].'''
   
==December 2009==
+
==July 2012==
  +
*The [http://vimhelp.appspot.com/vim_faq.txt.html Vim FAQ] is online.
*[http://www.derekwyatt.org/vim/vim-tutorial-videos/ Vim tutorials] has videos illustrating simple and advanced topics.
 
  +
*There are several methods to [[VimTip224|change the indentation of a block of lines]].
*Searching with <tt>/\%>80v.\+</tt> finds the next [[VimTip810|line longer than 80 characters]] (after expanding tabs).
 
  +
*A mapping can change the Home key to [[VimTip315|move to the first character, or the first that is nonblank]].
*Mapping a key to execute <tt>:update</tt> makes it easy to [[VimTip897|save the current file]], if changed.
 
  +
*Filtering and redirection can [[VimTip374|capture output from Vim or external programs]].
*If a file from a Mac is garbled, reload it with [[VimTip1585|<tt>:e ++ff=mac</tt>]].
 
  +
*It's easy to [[VimTip431|change between backslash and forward slash]] in a file path.
*The command <tt>:set et|retab</tt> [[VimTip1592|expands all tab indents]] to use spaces.
 
  +
*If you create your own tags file, you can [[VimTip601|jump to the correct line ''and'' column]].
*Typing <tt>"+P</tt> pastes the clipboard before the cursor and [[VimTip1593|sets mark <tt>`[</tt>]] to the beginning of the pasted text, and mark <tt>`]</tt> to the end.
 
  +
*If you work with many files, it's easy to [[VimTip652|save them all with <tt>:wa</tt> or <tt>:xa</tt>]].
*With the cursor on an http link, pressing Ctrl-W Ctrl-F uses netrw to [[VimTip1596|open the html source]] in a new window.
 
  +
*Simple substitutes or a Perl script can [[VimTip1005|convert text using HTML entities like <tt>&amp;gt;</tt>]].
*The search <tt>/hello/e</tt> finds "hello" (like <tt>/hello</tt>), but puts the [[VimTip1597|cursor at the end of the match]].
 
  +
*The command <tt>:g/^/exe ".w ".line(".").".txt"</tt> [[VimTip1059|saves each line in the buffer to a separate file]].
*Some mappings or a substitute will help [[VimTip1602|convert PHP variables]] from <tt>$this_variable_style</tt> to <tt>$thisVariableStyle</tt>.
 
  +
*<tt>:g//</tt> [[VimTip1063|lists all lines containing the last search pattern]], and :redir will capture the results.
*You can use the [[VimTip1614|git version control system]] from Vim.
 
  +
*With <tt>set browsedir=buffer</tt> the File, Open dialog [[VimTip753|defaults to the current file's directory]].
*We have an [[VimTip1628|example of a simple vimrc]] with suggestions for configuring Vim.
 
   
==November 2009==
+
==May 2010==
  +
*<tt>@:</tt> will [[VimTip990|repeat a colon (Ex) command]] (and <tt>@@</tt> will repeat again).
*[http://www.derekwyatt.org/vim/vim-tutorial-videos/ Vim tutorials] has videos illustrating simple and advanced topics.
 
  +
*You can use <tt>:g/^\s*$/;//-1sort</tt> to [[VimTip1118|sort each block of lines in a file]].
*On Windows, when [[VimTip503|using PuTTY]] to execute Vim, you should disable application keypad mode.
 
  +
*It's useful to <tt>map . .`[</tt> to [[VimTip1142|repeat the last command and put the cursor at start of change]].
*Enter <tt>:scriptnames</tt> to [[VimTip515|list all scripts run]] by Vim.
 
  +
*You can [[VimTip306|open a web browser with the URL in the current line]].
*Using <tt>:execute</tt> allows '<tt>|</tt>' to [[VimTip767|separate multiple commands]], even those that that eat '<tt>|</tt>'.
 
  +
*With <tt>--remote-send</tt> you can [[VimTip309|close a Vim you left open remotely]].
*Entering <tt>:m'}-1</tt> [[VimTip1463|moves the current line]] to the end of the current paragraph.
 
  +
*If you're used to Perl regex, you can [[VimTip393|use Perl compatible regular expressions]].
*You can see [[VimTip1526|what script defined a mapping]] (say for comma) with <tt>:verbose map ,</tt>.
 
  +
*In insert mode, Ctrl-Y inserts the character above. You can [[VimTip428|make it insert the word above]].
*Using <tt>:noautocmd vimgrep ...</tt> will [[VimTip1543|speed up <tt>vimgrep</tt>]].
 
  +
*A user-defined command can [[VimTip1235|evaluate <tt>:Calc sin(pi/2)</tt>]].
*Under Windows, enter <tt>:!start calc</tt> to [[VimTip1549|asynchronously execute a GUI program]] (say calc.exe).
 
  +
*It's sometimes better to [[VimTip406|''not'' use the slash delimiter for <tt>:s/old/new/</tt>]].
*In a script, [[VimTip1556|execute normal-mode commands]] with a bang (example: <tt>normal! gqip</tt>) to avoid mappings.
 
  +
*You can [[VimTip413|drag & drop one or more files into gvim]].
*Scripts can use <tt>filereadable()</tt> to check if a file exists and can be read ([[VimTip1569|example]]).
 
*Scripts can use <tt>readfile()</tt> to read all lines from a file ([[VimTip1569|same example]]).
 
   
==October 2009==
+
==April 2010==
  +
*<tt>zz</tt> scrolls the current line to the [[VimTip182|middle of the screen]]; scrolloff can keep it there.
*[http://vim.runpaint.org/ '''''Vim Recipes'''''] is a new and free cookbook in PDF and HTML.
 
  +
*Vim can do calculations using [[VimTip1235|Python]], [[VimTip1359|Perl]] or [[VimTip1349|bc]].
*Using <tt>:set splitright</tt> causes a [[VimTip34|new split window]] to be on the right.
 
  +
*You can wrap long lines while moving the cursor by [[VimTip38|screen lines]].
*Using <tt>:set lines=50 columns=100</tt> in your [[vimrc]] sets the [[VimTip88|initial window size]].
 
  +
*A tricky search can [[VimTip220|find text that does ''not'' match]].
*Press <tt>I</tt> to [[VimTip194|insert text in multiple lines]] in a visual block.
 
  +
*Pressing <tt>%</tt> [[VimTip6|jumps to a matching bracket]], and <tt>matchit.vim</tt> can match much more.
*Setting <tt>'guifont'</tt> in your vimrc can set the [[VimTip632|font used]] in gvim.
 
  +
*The <tt>shortmess</tt> and <tt>cmdheight</tt> options allow you to [[VimTip16|avoid "Hit Enter to continue" prompts]].
*Clever scripts can [[VimTip634|show what colors are available]] for use in Vim.
 
  +
*An option controls [[VimTip17|how backspace and other delete keys work in insert mode]].
*A command like <tt>:e ++enc=cp850</tt> [[VimTip690|reloads the file using a different encoding]].
 
  +
*You can [[VimTip19|display line numbers and change the width of the number column]].
*Enter <tt>:windo wincmd K</tt> to [[VimTip862|change a "horizontal list" of windows]] to a "vertical list".
 
  +
*It's easy to [[VimTip49|change text between lowercase and UPPERCASE]].
*We have some ideas for [[VimTip1016|moving through camelCaseWords]].
 
  +
*The command history allows you to [[VimTip45|repeat several commands, possibly after editing them]].
*Changing the [[VimTip1287|status line color]] helps to show whether you are in insert or normal mode.
 
*Many <tt>cindent</tt> options can be configured with <tt>'cinoptions'</tt>, including [[VimTip1626|continuation lines]].
 
   
==September 2009==
+
==March 2010==
*[http://vim.runpaint.org/ '''''Vim Recipes'''''] is a new and free cookbook in PDF and HTML.
+
*[http://www.derekwyatt.org/vim/vim-tutorial-videos/ Vim tutorials] has videos illustrating simple and advanced topics.
  +
*Use <tt>%</tt> to jump to the [[VimTip6|matching bracket]], and more.
*You can enter a command like <tt>:set ft=python</tt> to [[VimTip130|set the filetype]] for a new buffer.
 
*Typing <tt>_</tt> or <tt>g_</tt> [[VimTip278|moves]] to the first or last non-blank character of the current line.
+
*Use <tt>:lcd %:p:h</tt> to [[VimTip64|change directory]] to the file in the current window.
  +
*<tt>ga</tt> shows the [[VimTip67|ascii value]] of the current character.
*Use <tt>:verbose set ai? cin? cink? cino? si? inde? indk?</tt> to [[VimTip330|see the current indent settings]] and where they were set.
 
  +
*You can [[VimTip1300|list changes]] to the current file, even old changes.
*A great [[VimTip341|one page summary of color schemes]] is available.
 
 
*Use <tt>za</tt> to [[VimTip1330|toggle folds open/closed]].
*Typing <tt>gwap</tt> [[VimTip347|formats the paragraph]] ''without'' changing the cursor position.
 
  +
*The status line can show your [[VimTip735|fileencoding and bomb]].
*A search (<tt>/ \+\ze\t</tt>) can [[VimTip396|highlight spaces]] that occur before a tab.
 
  +
*In a program, you can [[VimTip7|jump to the beginning or end of a code block]].
*Perl subs [[VimTip419|can be folded]] if enabled with <tt>:let perl_fold = 1</tt> in your vimrc.
 
  +
*With two related files in a vertical split, you can [[VimTip52|scroll both windows together]].
*The command <tt>:%s/\%Vold/new/g</tt> changes "old" to "new" in the [[VimTip438|last visual selection]].
 
  +
*It's easy to [[VimTip689|count the words in a file or block]].
*A format option like <tt>:setl fo=aw2tq</tt> can [[VimTip440|reflow paragraphs]] while you type.
 
  +
*You can even make a frequency table [[VimTip1531|counting the occurrences of each word]]!
*Using Ctrl-o in an <tt>:imap</tt> can [[VimTip459|execute a normal mode command]] and stay in insert mode.
 
   
==August 2009==
+
==February 2010==
*[http://vim.runpaint.org/ '''''Vim Recipes'''''] is a new and free cookbook in PDF and HTML.
+
*[http://www.derekwyatt.org/vim/vim-tutorial-videos/ Vim tutorials] has videos illustrating simple and advanced topics.
  +
*You can press <tt>*</tt> to [[VimTip1|search for the current word]].
*Your syntax files may have [[VimTip1534|configurable options]].
 
  +
*Ctrl-A can [[VimTip30|increment numbers]].
*With <tt>au FileType qf ...</tt> you can adjust the [[VimTip1536|quickfix window height]].
 
  +
*After typing a couple of characters, you can [[VimTip4|complete a word]] with Ctrl-N or Ctrl-P.
*With <tt>au CursorHoldI * ...</tt> you can exit insert mode [[VimTip1540|when idle]].
 
  +
*[[VimTip882|Vim's help]] use prefixes like <tt>v_</tt> (visual mode) to show the context.
*A sweet regex can [[VimTip1539|exchange adjacent words]] regardless of separator.
 
  +
*The [[VimTip1520|<tt>:let</tt> command]] can set registers and options as well as variables.
*Typing <tt>ci(</tt> changes text from anywhere inside parentheses ([[VimTip1555|a text object]]).
 
  +
*The command <tt>:42</tt> [[VimTip751|jumps to line 42]], as does typing <tt>42G</tt>.
*Type <tt>:v/pattern/d</tt> to delete all lines [[VimTip1557|not matching ''pattern'']].
 
  +
*The <tt>shortmess</tt> and <tt>cmdheight</tt> options allow you to [[VimTip16|avoid "Hit Enter to continue" prompts]].
*Make your own [[VimTip1567|dynamic template]] with <tt>eval()</tt>.
 
 
*The <tt>'backspace'</tt> option controls [[VimTip17|how backspace and other delete keys work in insert mode]].
*Temporarily mapping <tt>j</tt> and <tt>k</tt> to Ctrl-e and Ctrl-y (and more) makes [[VimTip1571|scrolling text]] easy.
 
  +
*The <tt>'number'</tt> and <tt>'numberwidth'</tt> options control the [[VimTip19|display of line numbers]].
*Using <tt>:set statusline+=%{MyFunction()}</tt> can [[VimTip1573|show the syntax highlight group]] in the statusline.
 
  +
*It's easy to [[VimTip49|change text between lowercase and UPPERCASE]].
*You can use the [[VimTip1576|Vim color schemes in PuTTY]].
 
   
==July 2009==
+
==January 2010==
*[http://vim.runpaint.org/ '''''Vim Recipes'''''] is a new and free cookbook in PDF and HTML.
+
*[http://www.derekwyatt.org/vim/vim-tutorial-videos/ Vim tutorials] has videos illustrating simple and advanced topics.
  +
*We have an explanation for how <tt>:g/^/m0</tt> [[VimTip29|reverses all lines]].
*An [[VimTip1589|environment variable]] can be displayed, for example <tt>:echo $PATH</tt>.
 
  +
*In a search pattern, <tt>\_s</tt> [[VimTip242|matches]] a space or tab or newline character.
*The '<tt>opfunc</tt>' option can be used to [[VimTip1570|define your own operator]].
 
  +
*A script can use a test like <tt>&buftype == "quickfix"</tt> to check if it is operating in the [[VimTip536|quickfix window]].
*A temporary change to the '<tt>grepprg</tt>' option allows [[VimTip1262|<tt>git grep</tt>]] in Vim.
 
  +
*Typing <tt>=i{</tt> reindents the "inner block" ([[VimTip597|code inside braces]]).
*<tt>:pedit myfile</tt> [[VimTip867|opens a file in the preview window]]; useful for pydoc.
 
  +
*Using <tt>'smartindent'</tt> means that typing <tt>#</tt> may [[VimTip644|remove an indent]] before the <tt>#</tt>.
*Use <tt>:wa</tt> to [[VimTip803|save all modified files]] (no save if no change).
 
  +
*The <tt>'winaltkeys'</tt> option controls whether [[VimTip645|Vim handles Alt keys]].
*Use <tt>:e ..</tt> to [[VimTip1182|list files]] in the parent directory.
 
  +
*If you would prefer Y to be consistent with C, use [[VimTip979|<tt>:nnoremap Y y$</tt>]].
*Use <tt>:set showcmd</tt> to [[VimTip859|show the size]] of the visually-selected area.
 
  +
*A plugin should set its "loaded" variable to [[VimTip1559|show its version]], for example <tt>let&nbsp;g:loaded_dbext&nbsp;=&nbsp;503</tt>.
*Press Ctrl-w then <tt>o</tt> to [[VimTip999|show only the current window]] (close others).
 
  +
*We have a short [[VimTip1582|FAQ for new users]] concerning common issues raised at #vim.
*Windows users should use the [[VimTip416|GnuWin32 diff package]].
 
  +
*You can use <tt>:cnoremap</tt> to map a key to <tt><C-\>e(...)<CR></tt> which will [[VimTip1594|replace the command line]] with the <tt>(...)</tt> expression.
*You can [[VimTip389|search only unfolded text]] with <tt>:set fdo-=search</tt>.
 
 
==June 2009==
 
*[http://vim.runpaint.org/ '''''Vim Recipes'''''] is a new and free cookbook in PDF and HTML
 
*The command <tt>:cabbrev</tt> can expand commands and [[VimTip22|fix your frequent typos]].
 
*In insert mode, typing <tt><C-R>=strftime("%c")</tt> [[VimTip97|inserts the current date and time]].
 
*You can [[VimTip108|toggle folds open/closed]] with <tt>za</tt>.
 
*<tt>perldoc</tt> can be used to [[VimTip461|open a Perl module from its module name]].
 
*A plugin allows [[VimTip588|sorting lines based on a visually-selected column]].
 
*Under Windows, you can have [[VimTip638|<tt>pl2bat</tt> scripts detected as Perl filetype]].
 
*Some mappings allow easy [[VimTip646|move up/down of current line]].
 
*Use <tt>:set wildchar=<Tab> wildmenu wildmode=full</tt> for a menu to [[VimTip686|complete buffer/file names]].
 
*In some terminals, [[VimTip738|meta keys are sent as escape sequences]] which can exit insert mode.
 
*The command <tt>:set cursorline</tt> [[VimTip769|highlights the current line]].
 
 
==May 2009==
 
*Type <tt>gd</tt> to [[VimTip9|jump to the definition]] of a local variable, or <tt>gD</tt> for a global variable.
 
*Sort and remove duplicate lines with <tt>:sort u</tt> ([[VimTip648|"unique"]]).
 
*Some code is needed for [[VimTip1148|unique sorting]] in a script.
 
*Map the Enter key to Esc to [[VimTip783|quickly exit insert mode]].
 
*And map Enter to [[VimTip982|insert a newline]] from normal mode.
 
*A mapping can search for the [[VimTip798|current word]] in a new window.
 
*It can be easy to [[VimTip873|cycle through buffers]] including hidden buffers.
 
*The <tt>pastetoggle</tt> option should be used when [[VimTip906|pasting into a terminal]].
 
*Commands like <tt>:set wrap! wrap?</tt> are useful when [[VimTip920|toggling boolean options]].
 
*Use <tt>\V</tt> to make a regex "[[VimTip1237|very nomagic]]", or use <tt>:sno</tt> for a "very nomagic" substitute.
 
 
==April 2009==
 
*[http://www.swaroopch.com/notes/Vim '''''A Byte of Vim''''' is a free ebook on Vim]
 
*[http://www.vim.org/ Vim 7.2 has been released]
 
*Press <tt>[</tt> then the Tab key to [[VimTip9|jump to the first line]] containing the current keyword.
 
*The 'pastetoggle' option should be used when [[VimTip906|pasting into console Vim]].
 
*Using <tt>:set wrap! wrap?</tt> is handy to [[VimTip920|toggle an option]] and see its value.
 
*A simple <tt>map <CR> o<Esc></tt> can [[VimTip982|insert a newline]] in normal mode.
 
*Using <tt>nr2char()</tt> helps convert from [[VimTip1012|"quoted printable"]] to plain text.
 
*In a regex, \v is [[VimTip1237|"very magic"]] (all characters except a-zA-Z0-9_ have special meaning).
 
*The '<tt>binary</tt>' and '<tt>eol</tt>' options can help [[VimTip1369|preserve a missing final end-of-line]].
 
*Using the <tt>ftplugin</tt> directory helps [[VimTip1510|keep your vimrc clean]].
 
*The command <tt>:scriptnames</tt> lists all scripts that have been sourced ([[VimTip1522|more]]).
 
*[[VimTip1533|Vim Doclet]] is a Doclet for Java that generates documentation in Vim Help format.
 
 
==March 2009==
 
*[http://www.swaroopch.com/notes/Vim '''''A Byte of Vim''''' is a free ebook on Vim]
 
*[http://www.vim.org/ Vim 7.2 has been released]
 
*Press <tt>[I</tt> to [[VimTip9|display all lines]] containing the current variable.
 
*Press <tt>gF</tt> to [[VimTip487|jump to a specified line number in a file]].
 
*A mapping allows [[VimTip489|jumping sections]] in Latex documents.
 
*Using a mapping (with <tt>:update</tt>) allows [[VimTip582|quick saves]] of the current buffer, if changed.
 
*It's easy to [[VimTip605|replace the current word]] with the last yanked text.
 
*A keymap allows [[VimTip619|entry of characters]] that are not available on your keyboard.
 
*The command <tt>:e $MYVIMRC</tt> will [[VimTip626|edit your vimrc]] file.
 
*You can add a [[VimTip724|dashed line]] under a title.
 
*Some scripting allows [[VimTip760|fast changes to your font size]].
 
*Using <tt>:set foldlevel=20</tt> means [[VimTip797|all folds are open when a file is opened]].
 
 
==February 2009==
 
*[http://www.swaroopch.com/notes/Vim '''''A Byte of Vim''''' is a free ebook on Vim]
 
*[http://www.vim.org/ Vim 7.2 has been released]
 
*Type <tt>[i</tt> to [[VimTip9|display the definition]] of the current variable, or <tt>[d</tt> for a macro.
 
*The <tt>:set hlsearch</tt> command [[VimTip14|highlights all search hits]]; use <tt>:noh</tt> to temporarily switch off.
 
*You may be able to [[VimTip50|recover lost text]] if the power fails while you are editing.
 
*Use digraphs to [[VimTip51|enter special characters]]: in insert mode, press Ctrl-K then <tt>Co</tt> for <tt>©</tt>, or Ctrl-K then <tt>Pd</tt> for <tt>£</tt>.
 
*The quickfix list can be used to [[VimTip76|fold away lines]] with no errors/matches.
 
*The '<tt>whichwrap</tt>' option controls whether the backspace and cursor keys [[VimTip137|wrap to the previous/next line]].
 
*Manual [[VimTip241|fold markers can be hidden]] using the Ignore highlighting group.
 
*Some mappings allow [[VimTip294|Ctrl-S to save the current file]], or a new file.
 
*It's useful to map a key for [[VimTip398|quicker access to recorded macros]].
 
 
==January 2009==
 
*[http://www.swaroopch.com/notes/Vim '''''A Byte of Vim''''' is a free ebook on Vim]
 
*[http://www.vim.org/ Vim 7.2 has been released]
 
*You can keep your window layout by [[VimTip165|deleting a buffer without closing the window]].
 
*A script makes it easy to [[VimTip191|move lines up or down]].
 
*We have lots of opinions on the [[VimTip914|perfect programming font]].
 
*<tt>gg"+yG</tt> is one way to [[VimTip960|copy the entire buffer to the clipboard]].
 
*It is possible to [[VimTip972|run native-Windows Vim from cygwin without a wrapper]].
 
*Some mappings allow you to [[VimTip1066|quickly add or delete empty lines]].
 
*A <tt>FocusLost</tt> autocommand is one way to [[VimTip1160|auto-save files when the focus is lost]].
 
*We have an extensive tutorial on [[VimTip1516|mapping keys]].
 
*With a suitable definition for <tt>b:match_words</tt>, you can [[VimTip1321|fold a C# region]].
 
   
 
==Previous years==
 
==Previous years==
  +
*[[/2009|2009 ''Did you know'']]
 
*[[/2008|2008 ''Did you know'']]
 
*[[/2008|2008 ''Did you know'']]
  +
  +
[[Category:VimInformation]]

Latest revision as of 10:23, 26 June 2012

This is an archive of the Did you know? section on the home page

We occasionally replace the DYK section on the home page, and items are copied to here so anyone interested can browse them.

To discuss suggestions for new items, please edit the talk page.

July 2012

May 2010

April 2010

March 2010

February 2010

January 2010

Previous years