Wikia

Vim Tips Wiki

Changes: Vim Tips Wiki:Featured Tip/2008

Edit

Back to page

(archive 2008)
 
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 2: Line 2:
   
 
===[[VimTip1568|December 2008]]===
 
===[[VimTip1568|December 2008]]===
When in an editing session, another process (perhaps from a shell command) may modify or delete a file in one of Vim's buffers. The <tt>FileChangedShell</tt> autocommand event can be used to control Vim's response.
+
When in an editing session, another process (perhaps from a shell command) may modify or delete a file in one of Vim's buffers. The <code>FileChangedShell</code> autocommand event can be used to control Vim's response.
   
 
It's easy for a script to [[VimTip1568|mark the buffer of a deleted file as ''modified'']] so you don't accidentally abandon a buffer that could be used to restore a deleted file.
 
It's easy for a script to [[VimTip1568|mark the buffer of a deleted file as ''modified'']] so you don't accidentally abandon a buffer that could be used to restore a deleted file.
   
Because <tt>FileChangedShell</tt> is used, the script has to handle each reason that the event may be invoked (file deleted, or contents changed, or other reason).
+
Because <code>FileChangedShell</code> is used, the script has to handle each reason that the event may be invoked (file deleted, or contents changed, or other reason).
   
 
===[[VimTip810|November 2008]]===
 
===[[VimTip810|November 2008]]===
Line 13: Line 13:
 
It's easy to search, match, or use syntax highlighting to [[VimTip810|highlight long lines]].
 
It's easy to search, match, or use syntax highlighting to [[VimTip810|highlight long lines]].
   
A search like <tt>/\%>80v.\+</tt> with search highlighting (<tt>:set hlsearch</tt>) will highlight any text after column 80.
+
A search like <code>/\%>80v.\+</code> with search highlighting (<code>:set hlsearch</code>) will highlight any text after column 80.
   
A simpler pattern such as <tt>\%81v.*</tt> fails to highlight text past the limit if there is no character in virtual column 81, and can give an erroneous highlight of column 81 on lines of exactly 80 characters.
+
A simpler pattern such as <code>\%81v.*</code> fails to highlight text past the limit if there is no character in virtual column 81, and can give an erroneous highlight of column 81 on lines of exactly 80 characters.
   
 
===[[VimTip396|October 2008]]===
 
===[[VimTip396|October 2008]]===
 
Programmers, and other careful editors, often work hard to maintain consistent use of whitespace characters (space and tab). Perhaps you want to avoid using spaces before tabs or at the end of a line. Or, you may want to see where tabs occur, or see only the tabs that are not used for indenting.
 
Programmers, and other careful editors, often work hard to maintain consistent use of whitespace characters (space and tab). Perhaps you want to avoid using spaces before tabs or at the end of a line. Or, you may want to see where tabs occur, or see only the tabs that are not used for indenting.
   
Good news! There are several ways to [[VimTip396|highlight unwanted whitespace]]. Try a simple search, or match or syntax highlighting. There's also the <tt>'list'</tt> option, and your filetype may support showing syntax space errors.
+
Good news! There are several ways to [[VimTip396|highlight unwanted whitespace]]. Try a simple search, or match or syntax highlighting. There's also the <code>'list'</code> option, and your filetype may support showing syntax space errors.
   
 
===[[VimTip45|September 2008]]===
 
===[[VimTip45|September 2008]]===
Line 30: Line 30:
 
It's easy to work with CSV files (comma-separated values), if you have the right tools! You can highlight all text in any column, navigate from cell to cell (up/down and left/right), search for text in a specific column, and more.
 
It's easy to work with CSV files (comma-separated values), if you have the right tools! You can highlight all text in any column, navigate from cell to cell (up/down and left/right), search for text in a specific column, and more.
   
All you need is Vim and [[VimTip667|this month's hot tip]]! Be sure to check it out if you need to sort csv data by column, or if your brain needs some regex exercise. Marvel at the magic of <tt>matchadd()</tt> (Vim 7.1.040 and later), with fallback to <tt>:2match</tt> for earlier versions.
+
All you need is Vim and [[VimTip667|this month's hot tip]]! Be sure to check it out if you need to sort csv data by column, or if your brain needs some regex exercise. Marvel at the magic of <code>matchadd()</code> (Vim 7.1.040 and later), with fallback to <code>:2match</code> for earlier versions.
   
 
===[[VimTip1|July 2008]]===
 
===[[VimTip1|July 2008]]===
Searching is simple: starting in normal mode, press <tt>/</tt> then type what you want to find, and press Enter. But in Vim there's always more to learn!
+
Searching is simple: starting in normal mode, press <code>/</code> then type what you want to find, and press Enter. But in Vim there's always more to learn!
   
This month's featured tip improves your searching skills, starting with use of <tt>*</tt> to [[VimTip1|search for the current word]], and continuing with more suggestions for successful searching. Remember to check the "see also" for more search tips.
+
This month's featured tip improves your searching skills, starting with use of <code>*</code> to [[VimTip1|search for the current word]], and continuing with more suggestions for successful searching. Remember to check the "see also" for more search tips.
   
 
===[[VimTip1376|June 2008]]===
 
===[[VimTip1376|June 2008]]===
Folding is frequently used to provide an easy overview of a program or document. A folded section is displayed as a single line that [[VimTip1093|can easily be expanded]]. When supported by a syntax file, it is usually best to use <tt>setlocal&nbsp;foldmethod=syntax</tt>.
+
Folding is frequently used to provide an easy overview of a program or document. A folded section is displayed as a single line that [[VimTip1093|can easily be expanded]]. When supported by a syntax file, it is usually best to use <code>setlocal foldmethod=syntax</code>.
   
This month's featured tip explains how to enhance [[VimTip1376|syntax folding of Vim scripts]] by using <tt>syn region</tt> commands in an <tt>after/syntax/vim.vim</tt> file. The tip provides valuable information for advanced users who may want to add to, or override, syntax rules for any file type.
+
This month's featured tip explains how to enhance [[VimTip1376|syntax folding of Vim scripts]] by using <code>syn region</code> commands in an <code>after/syntax/vim.vim</code> file. The tip provides valuable information for advanced users who may want to add to, or override, syntax rules for any file type.
   
 
===[[VimTip1285|May 2008]]===
 
===[[VimTip1285|May 2008]]===
 
Many Vim users prefer working with commands rather than complex key sequences, because commands can be remembered. A frequently-used command can be [[VimTip1516|mapped to any key you like]].
 
Many Vim users prefer working with commands rather than complex key sequences, because commands can be remembered. A frequently-used command can be [[VimTip1516|mapped to any key you like]].
   
You can create user-defined commands, but each must start with an uppercase letter. So how do you replace a built-in command with a user-defined command? Here is a clever but simple technique to [[VimTip1285|replace built-in commands, while avoiding accidental <tt>cabbrev</tt> expansions]].
+
You can create user-defined commands, but each must start with an uppercase letter. So how do you replace a built-in command with a user-defined command? Here is a clever but simple technique to [[VimTip1285|replace built-in commands, while avoiding accidental <code>cabbrev</code> expansions]].
   
 
===[[VimTip1440|April 2008]]===
 
===[[VimTip1440|April 2008]]===
 
Many text editors launch new files in tabs, rather than showing a separate window for each file. Here's how to make Vim behave that way under Microsoft Windows.
 
Many text editors launch new files in tabs, rather than showing a separate window for each file. Here's how to make Vim behave that way under Microsoft Windows.
   
At command prompt, use <tt>ftype</tt> to define the open command to run gvim with the <tt>--remote-tab-silent</tt> option. Use <tt>assoc</tt> to define which file extensions will be associated with the <tt>ftype</tt> open command. You can specify the <tt>--servername</tt> option so files with one type open in one instance of Vim, while files of another type open in another. See [[VimTip1440|tip 1440 ''Launch files in new tabs under Windows'']] for details.
+
At command prompt, use <code>ftype</code> to define the open command to run gvim with the <code>--remote-tab-silent</code> option. Use <code>assoc</code> to define which file extensions will be associated with the <code>ftype</code> open command. You can specify the <code>--servername</code> option so files with one type open in one instance of Vim, while files of another type open in another. See [[VimTip1440|tip 1440 ''Launch files in new tabs under Windows'']] for details.
   
 
===[[VimTip1543|March 2008]]===
 
===[[VimTip1543|March 2008]]===
We know how to use <tt>/pattern</tt> to search the current file for the regular expression ''pattern''.
+
We know how to use <code>/pattern</code> to search the current file for the regular expression ''pattern''.
   
You can also use a command like <tt>:vimgrep&nbsp;pattern&nbsp;*.txt</tt> to search all .txt files in the current directory for pattern, or <tt>:vimgrep&nbsp;pattern&nbsp;**/*.txt</tt> to search in the current directory and all its subdirectories. Using forward slashes for the file path works on Unix-based and Windows systems.
+
You can also use a command like <code>:vimgrep pattern *.txt</code> to search all .txt files in the current directory for pattern, or <code>:vimgrep pattern **/*.txt</code> to search in the current directory and all its subdirectories. Using forward slashes for the file path works on Unix-based and Windows systems.
   
 
Would you like to press a key to search for the current word in all files in and under the current directory? See [[VimTip1543|tip 1543 ''Find in files within Vim'']] for details.
 
Would you like to press a key to search for the current word in all files in and under the current directory? See [[VimTip1543|tip 1543 ''Find in files within Vim'']] for details.
   
 
===[[VimTip438|February 2008]]===
 
===[[VimTip438|February 2008]]===
Visual selection is useful for operating on a selected area: <tt>v</tt> for characters, <tt>V</tt> for lines, <tt>Ctrl-V</tt> (<tt>Ctrl-Q</tt> on Windows) for a block. You can extend the selection with normal commands such as '''<tt>j</tt>''' to move down, or '''<tt>w</tt>''' to move by a word, or '''<tt>/</tt>''' to search. Marks are automatically defined that specify the start and end of the visual selection.
+
Visual selection is useful for operating on a selected area: <code>v</code> for characters, <code>V</code> for lines, <code>Ctrl-V</code> (<code>Ctrl-Q</code> on Windows) for a block. You can extend the selection with normal commands such as '''<code>j</code>''' to move down, or '''<code>w</code>''' to move by a word, or '''<code>/</code>''' to search. Marks are automatically defined that specify the start and end of the visual selection.
   
It's easy to search and replace within a visual selection &ndash; just type the normal <tt>:s/old/new/g</tt> command while in visual mode.
+
It's easy to search and replace within a visual selection &ndash; just type the normal <code>:s/old/new/g</code> command while in visual mode.
   
You can also search the area that was visually selected &ndash; press Esc to exit visual mode, and start the search with <tt>/\%V</tt> rather than <tt>/</tt>. See [[VimTip438|tip 438 ''Search and replace in a visual selection'']] for details.
+
You can also search the area that was visually selected &ndash; press Esc to exit visual mode, and start the search with <code>/\%V</code> rather than <code>/</code>. See [[VimTip438|tip 438 ''Search and replace in a visual selection'']] for details.
   
 
==Comments==
 
==Comments==

Latest revision as of 08:33, July 15, 2012

This is an archive of the Featured tip section on the Main Page for 2008 (started in February 2008).

December 2008Edit

When in an editing session, another process (perhaps from a shell command) may modify or delete a file in one of Vim's buffers. The FileChangedShell autocommand event can be used to control Vim's response.

It's easy for a script to mark the buffer of a deleted file as modified so you don't accidentally abandon a buffer that could be used to restore a deleted file.

Because FileChangedShell is used, the script has to handle each reason that the event may be invoked (file deleted, or contents changed, or other reason).

November 2008Edit

Programmers often need to know when source lines exceed a certain length. For example, your team's coding standards may require that lines never exceed 80 columns.

It's easy to search, match, or use syntax highlighting to highlight long lines.

A search like /\%>80v.\+ with search highlighting (:set hlsearch) will highlight any text after column 80.

A simpler pattern such as \%81v.* fails to highlight text past the limit if there is no character in virtual column 81, and can give an erroneous highlight of column 81 on lines of exactly 80 characters.

October 2008Edit

Programmers, and other careful editors, often work hard to maintain consistent use of whitespace characters (space and tab). Perhaps you want to avoid using spaces before tabs or at the end of a line. Or, you may want to see where tabs occur, or see only the tabs that are not used for indenting.

Good news! There are several ways to highlight unwanted whitespace. Try a simple search, or match or syntax highlighting. There's also the 'list' option, and your filetype may support showing syntax space errors.

September 2008Edit

Vim's command and search history are extremely helpful. Perhaps you use history, but are frustrated from editing the command line with the primitive arrow, backspace and delete keys.

Now you can smile while editing history with all Vim's power in the command-line window. Read how to easily copy some previously-entered commands so you can apply them while editing another file.

August 2008Edit

It's easy to work with CSV files (comma-separated values), if you have the right tools! You can highlight all text in any column, navigate from cell to cell (up/down and left/right), search for text in a specific column, and more.

All you need is Vim and this month's hot tip! Be sure to check it out if you need to sort csv data by column, or if your brain needs some regex exercise. Marvel at the magic of matchadd() (Vim 7.1.040 and later), with fallback to :2match for earlier versions.

July 2008Edit

Searching is simple: starting in normal mode, press / then type what you want to find, and press Enter. But in Vim there's always more to learn!

This month's featured tip improves your searching skills, starting with use of * to search for the current word, and continuing with more suggestions for successful searching. Remember to check the "see also" for more search tips.

June 2008Edit

Folding is frequently used to provide an easy overview of a program or document. A folded section is displayed as a single line that can easily be expanded. When supported by a syntax file, it is usually best to use setlocal foldmethod=syntax.

This month's featured tip explains how to enhance syntax folding of Vim scripts by using syn region commands in an after/syntax/vim.vim file. The tip provides valuable information for advanced users who may want to add to, or override, syntax rules for any file type.

May 2008Edit

Many Vim users prefer working with commands rather than complex key sequences, because commands can be remembered. A frequently-used command can be mapped to any key you like.

You can create user-defined commands, but each must start with an uppercase letter. So how do you replace a built-in command with a user-defined command? Here is a clever but simple technique to replace built-in commands, while avoiding accidental cabbrev expansions.

April 2008Edit

Many text editors launch new files in tabs, rather than showing a separate window for each file. Here's how to make Vim behave that way under Microsoft Windows.

At command prompt, use ftype to define the open command to run gvim with the --remote-tab-silent option. Use assoc to define which file extensions will be associated with the ftype open command. You can specify the --servername option so files with one type open in one instance of Vim, while files of another type open in another. See tip 1440 Launch files in new tabs under Windows for details.

March 2008Edit

We know how to use /pattern to search the current file for the regular expression pattern.

You can also use a command like :vimgrep pattern *.txt to search all .txt files in the current directory for pattern, or :vimgrep pattern **/*.txt to search in the current directory and all its subdirectories. Using forward slashes for the file path works on Unix-based and Windows systems.

Would you like to press a key to search for the current word in all files in and under the current directory? See tip 1543 Find in files within Vim for details.

February 2008Edit

Visual selection is useful for operating on a selected area: v for characters, V for lines, Ctrl-V (Ctrl-Q on Windows) for a block. You can extend the selection with normal commands such as j to move down, or w to move by a word, or / to search. Marks are automatically defined that specify the start and end of the visual selection.

It's easy to search and replace within a visual selection – just type the normal :s/old/new/g command while in visual mode.

You can also search the area that was visually selected – press Esc to exit visual mode, and start the search with /\%V rather than /. See tip 438 Search and replace in a visual selection for details.

CommentsEdit

Around Wikia's network

Random Wiki