Vim Tips Wiki
(Add July archive)
(Archive of new edition, repeats 200806,07.)
 
(34 intermediate revisions by 7 users not shown)
Line 1: Line 1:
  +
__NOEDITSECTION__
'''This is an archive of the ''Did you know?'' section on the [[Main Page]]'''
+
<big>'''This is an archive of the ''Did you know?'' section on the [[Vim Tips Wiki|home page]]'''</big>
   
The ''Did you know?'' section was started in February 2008. Every few weeks, the section on the [[Main 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]].'''
   
==July 2008==
+
==July 2012==
  +
*The [http://vimhelp.appspot.com/vim_faq.txt.html Vim FAQ] is online.
*Press <tt>gd</tt> or <tt>gD</tt> to [[VimTip8|jump to the declaration of a local or global variable]].
 
*Press Ctrl-o or Ctrl-i to [[VimTip10|jump to previously visited locations]] (older/newer).
 
*In gvim, <tt>'guioptions'</tt> can [[VimTip89|hide the toolbar and menu]].
 
*Programmers should [[VimTip94|learn to browse with tags]].
 
*Use <tt>'formatoptions'</tt> to control text formatting [[VimTip129|including the automatic insertion of comments]].
 
*The command <tt>:g/^\s*$/d</tt> will [[VimTip72|remove all blank lines]].
 
*The command <tt>:g//d</tt> will [[VimTip213|delete all lines containing the last search pattern]].
 
 
*There are several methods to [[VimTip224|change the indentation of a block of lines]].
 
*There are several methods to [[VimTip224|change the indentation of a block of lines]].
 
*A mapping can change the Home key to [[VimTip315|move to the first character, or the first that is nonblank]].
 
*A mapping can change the Home key to [[VimTip315|move to the first character, or the first that is nonblank]].
 
*Filtering and redirection can [[VimTip374|capture output from Vim or external programs]].
 
*Filtering and redirection can [[VimTip374|capture output from Vim or external programs]].
 
==June 2008==
 
*HTML sections in PHP can be [[VimTip1213|auto-indented]].
 
 
*It's easy to [[VimTip431|change between backslash and forward slash]] in a file path.
 
*It's easy to [[VimTip431|change between backslash and forward slash]] in a file path.
 
*If you create your own tags file, you can [[VimTip601|jump to the correct line ''and'' column]].
 
*If you create your own tags file, you can [[VimTip601|jump to the correct line ''and'' column]].
 
*If you work with many files, it's easy to [[VimTip652|save them all with <tt>:wa</tt> or <tt>:xa</tt>]].
 
*If you work with many files, it's easy to [[VimTip652|save them all with <tt>:wa</tt> or <tt>:xa</tt>]].
*Substituting with an expression allows a file to be [[VimTip800|sorted based on the number of words in each line]].
 
 
*Simple substitutes or a Perl script can [[VimTip1005|convert text using HTML entities like <tt>&amp;gt;</tt>]].
 
*Simple substitutes or a Perl script can [[VimTip1005|convert text using HTML entities like <tt>&amp;gt;</tt>]].
 
*The command <tt>:g/^/exe ".w ".line(".").".txt"</tt> [[VimTip1059|saves each line in the buffer to a separate file]].
 
*The command <tt>:g/^/exe ".w ".line(".").".txt"</tt> [[VimTip1059|saves each line in the buffer to a separate file]].
 
*<tt>:g//</tt> [[VimTip1063|lists all lines containing the last search pattern]], and :redir will capture the results.
 
*<tt>:g//</tt> [[VimTip1063|lists all lines containing the last search pattern]], and :redir will capture the results.
*Some menu commands make [[VimTip701|beautifying code easy]].
 
 
*With <tt>set browsedir=buffer</tt> the File, Open dialog [[VimTip753|defaults to the current file's directory]].
 
*With <tt>set browsedir=buffer</tt> the File, Open dialog [[VimTip753|defaults to the current file's directory]].
   
==May 2008==
+
==May 2010==
 
*<tt>@:</tt> will [[VimTip990|repeat a colon (Ex) command]] (and <tt>@@</tt> will repeat again).
*A user-defined command can [[VimTip1235|evaluate <tt>:Calc sin(pi/2)</tt>]].
 
 
*You can use <tt>:g/^\s*$/;//-1sort</tt> to [[VimTip1118|sort each block of lines in a file]].
*It's sometimes better to [[VimTip406|''not'' use the slash delimiter for <tt>:s/old/new/</tt>]].
 
 
*It's useful to <tt>map . .`[</tt> to [[VimTip1142|repeat the last command and put the cursor at start of change]].
 
*You can [[VimTip306|open a web browser with the URL in the current line]].
 
*With <tt>--remote-send</tt> you can [[VimTip309|close a Vim you left open remotely]].
 
*If you're used to Perl regex, you can [[VimTip393|use Perl compatible regular expressions]].
 
*In insert mode, Ctrl-Y inserts the character above. You can [[VimTip428|make it insert the word above]].
 
*A user-defined command can [[VimTip1235|evaluate <tt>:Calc sin(pi/2)</tt>]].
 
*It's sometimes better to [[VimTip406|''not'' use the slash delimiter for <tt>:s/old/new/</tt>]].
 
*You can [[VimTip413|drag & drop one or more files into gvim]].
 
*You can [[VimTip413|drag & drop one or more files into gvim]].
*Use register <tt>@/</tt> to [[VimTip509|execute commands without changing the search register]].
 
*You can map a key to <tt><Nop></tt> to [[VimTip643|disable an unwanted key]].
 
*When substituting, the [[VimTip755|replacement can be the result of an expression]].
 
*With a good regex, you can [[VimTip1513|change all HTML tags to lowercase]].
 
*input() can read an HTML tag to [[VimTip1495|wrap around a visual selection]].
 
*Use <tt>vat</tt> to select a tag block, [[VimTip1304|then <tt>da&gt;</tt> to delete the tags]].
 
*Vim can display [[VimTip576|a lot more than ASCII characters]]!
 
   
==April 2008==
+
==April 2010==
 
*<tt>zz</tt> scrolls the current line to the [[VimTip182|middle of the screen]]; scrolloff can keep it there.
*The <tt>shortmess</tt> and <tt>cmdheight</tt> options allow you to [[VimTip16|avoid "Hit Enter to continue" prompts]].
 
 
*Vim can do calculations using [[VimTip1235|Python]], [[VimTip1359|Perl]] or [[VimTip1349|bc]].
*An option controls [[VimTip17|how backspace and other delete keys work in insert mode]].
 
 
*You can wrap long lines while moving the cursor by [[VimTip38|screen lines]].
*You can [[VimTip19|display line numbers and change the width of the number column]].
 
 
*A tricky search can [[VimTip220|find text that does ''not'' match]].
*It's easy to [[VimTip49|change text between lowercase and UPPERCASE]].
 
 
*Pressing <tt>%</tt> [[VimTip6|jumps to a matching bracket]], and <tt>matchit.vim</tt> can match much more.
*The command history allows you to [[VimTip170|repeat several commands, possibly after editing them]].
 
  +
*The <tt>shortmess</tt> and <tt>cmdheight</tt> options allow you to [[VimTip16|avoid "Hit Enter to continue" prompts]].
*<tt>@:</tt> will [[VimTip990|repeat a colon (Ex) command]] (and <tt>@@</tt> will repeat again).
 
  +
*An option controls [[VimTip17|how backspace and other delete keys work in insert mode]].
*You can use <tt>:g/^\s*$/;//-1sort</tt> to [[VimTip1118|sort each block of lines in a file]].
 
 
*You can [[VimTip19|display line numbers and change the width of the number column]].
*It's useful to <tt>map . .`[</tt> to [[VimTip1142|repeat the last command and put the cursor at start of change]].
 
  +
*It's easy to [[VimTip49|change text between lowercase and UPPERCASE]].
*You can [[VimTip306|open a web browser with the URL in the current line]].
 
 
*The command history allows you to [[VimTip45|repeat several commands, possibly after editing them]].
*With <tt>--remote-send</tt> you can [[VimTip309|close a Vim you left open remotely]].
 
*If you're used to Perl regex, you can [[VimTip393|use Perl compatible regular expressions]].
 
*In insert mode, Ctrl-Y inserts the character above. You can [[VimTip428|make it insert the word above]].
 
   
==March 2008==
+
==March 2010==
  +
*[http://www.derekwyatt.org/vim/vim-tutorial-videos/ Vim tutorials] has videos illustrating simple and advanced topics.
*There are many ways to [[VimTip882|search the help files]].
 
  +
*Use <tt>%</tt> to jump to the [[VimTip6|matching bracket]], and more.
*You can modify the value of almost everything [[VimTip1520|with the 'let' command]].
 
 
*Use <tt>:lcd %:p:h</tt> to [[VimTip64|change directory]] to the file in the current window.
*The Best Vim Tips are in [[VimTip305|tip 305]].
 
 
*<tt>ga</tt> shows the [[VimTip67|ascii value]] of the current character.
 
*You can [[VimTip1300|list changes]] to the current file, even old changes.
 
*Use <tt>za</tt> to [[VimTip1330|toggle folds open/closed]].
 
*The status line can show your [[VimTip735|fileencoding and bomb]].
 
*The status line can show your [[VimTip735|fileencoding and bomb]].
*There is more than one way to [[VimTip751|jump to line 42]].
 
*A tricky search can [[VimTip220|find text that does ''not'' match]].
 
*After typing a couple of characters, you can [[VimTip4|complete a word]].
 
 
*In a program, you can [[VimTip7|jump to the beginning or end of a code block]].
 
*In a program, you can [[VimTip7|jump to the beginning or end of a code block]].
 
*With two related files in a vertical split, you can [[VimTip52|scroll both windows together]].
 
*With two related files in a vertical split, you can [[VimTip52|scroll both windows together]].
*A map using <tt>expand("%:p")</tt> can [[VimTip296|copy the current file path to the clipboard]].
 
 
*It's easy to [[VimTip689|count the words in a file or block]].
 
*It's easy to [[VimTip689|count the words in a file or block]].
 
*You can even make a frequency table [[VimTip1531|counting the occurrences of each word]]!
 
*You can even make a frequency table [[VimTip1531|counting the occurrences of each word]]!
   
==February 2008==
+
==February 2010==
  +
*[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]].
 
*You can press <tt>*</tt> to [[VimTip1|search for the current word]].
*To insert the [[VimTip11|next matching word]], press Ctrl-N.
 
*Use <tt>%</tt> to jump to the [[VimTip6|matching bracket]], and more.
 
 
*Ctrl-A can [[VimTip30|increment numbers]].
 
*Ctrl-A can [[VimTip30|increment numbers]].
 
*After typing a couple of characters, you can [[VimTip4|complete a word]] with Ctrl-N or Ctrl-P.
*You can wrap long lines while moving the cursor by [[VimTip38|screen lines]].
 
  +
*[[VimTip882|Vim's help]] use prefixes like <tt>v_</tt> (visual mode) to show the context.
*Use <tt>:lcd %:p:h</tt> to [[VimTip64|change directory]] to the file in the current window.
 
  +
*The [[VimTip1520|<tt>:let</tt> command]] can set registers and options as well as variables.
*<tt>ga</tt> shows the [[VimTip67|ascii value]] of the current character.
 
  +
*The command <tt>:42</tt> [[VimTip751|jumps to line 42]], as does typing <tt>42G</tt>.
*<tt>zz</tt> scrolls the current line to the [[VimTip281|middle of the screen]]; scrolloff can keep it there.
 
 
*The <tt>shortmess</tt> and <tt>cmdheight</tt> options allow you to [[VimTip16|avoid "Hit Enter to continue" prompts]].
*You can [[VimTip1300|list changes]] to the current file, even old changes.
 
 
*The <tt>'backspace'</tt> option controls [[VimTip17|how backspace and other delete keys work in insert mode]].
*[[VimTip1326|Non-US keyboards]] have lots of useful keys for normal-mode mappings.
 
  +
*The <tt>'number'</tt> and <tt>'numberwidth'</tt> options control the [[VimTip19|display of line numbers]].
*Use <tt>za</tt> to [[VimTip1330|toggle folds open/closed]].
 
 
*It's easy to [[VimTip49|change text between lowercase and UPPERCASE]].
*Vim can do calculations using [[VimTip1235|Python]], [[VimTip1359|Perl]] or [[VimTip1349|bc]].
 
  +
  +
==January 2010==
  +
*[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]].
  +
*In a search pattern, <tt>\_s</tt> [[VimTip242|matches]] a space or tab or newline character.
  +
*A script can use a test like <tt>&buftype == "quickfix"</tt> to check if it is operating in the [[VimTip536|quickfix window]].
  +
*Typing <tt>=i{</tt> reindents the "inner block" ([[VimTip597|code inside braces]]).
  +
*Using <tt>'smartindent'</tt> means that typing <tt>#</tt> may [[VimTip644|remove an indent]] before the <tt>#</tt>.
  +
*The <tt>'winaltkeys'</tt> option controls whether [[VimTip645|Vim handles Alt keys]].
  +
*If you would prefer Y to be consistent with C, use [[VimTip979|<tt>:nnoremap Y y$</tt>]].
  +
*A plugin should set its "loaded" variable to [[VimTip1559|show its version]], for example <tt>let&nbsp;g:loaded_dbext&nbsp;=&nbsp;503</tt>.
  +
*We have a short [[VimTip1582|FAQ for new users]] concerning common issues raised at #vim.
  +
*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.
  +
  +
==Previous years==
  +
*[[/2009|2009 ''Did you know'']]
  +
*[[/2008|2008 ''Did you know'']]
   
 
[[Category:VimInformation]]
 
[[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