Vim Tips Wiki
Register
(Add August archive + summary for next month)
(→‎Previously featured tips: archive current feature)
 
(38 intermediate revisions by 4 users not shown)
Line 1: Line 1:
'''Please discuss proposals for new Featured Tips on the [[Vim_Tips_Wiki_talk:Featured_Tip|talk page]]. Comments on the current featured tip can be added below (be bold!), or can be added to the comments section at the end.'''
+
*'''Please discuss proposals for new Featured Tips on the [[Vim_Tips_Wiki_talk:Featured_Tip|talk page]].'''
  +
*'''The [[Vim Tips Wiki|home page]] highlights the current featured tip.'''
  +
*'''Add comments on the current featured tip to the comments section on the current tip page.'''
 
----
 
----
   
 
==Now THAT's a Good Tip!==
 
==Now THAT's a Good Tip!==
While most of the tips on this wiki are very helpful, every now and then, you'll stumble on a tip that shines above all the rest. Such a tip is a tip that changes the way you do a basic task, a tip that you try immediately and then use all the time, a tip that makes Vim integrate SO much better with your setup, or a tip that you just ''wish'' somebody gave to you when you started using Vim. We here on the Vim Tips Wiki recognize this, and therefore will -- about once a month -- feature a new tip that we feel is among the best of the best. So keep an eye on this page for life-altering (or at least mildly interesting) tips to add to your ''repertoire''.
+
While most of the tips on this wiki are very helpful, every now and then, you'll stumble on a tip that shines above all the rest. Such a tip is a tip that changes the way you do a basic task, a tip that you try immediately and then use all the time, a tip that makes Vim integrate SO much better with your setup, or a tip that you just ''wish'' somebody gave to you when you started using Vim. We here on the Vim Tips Wiki recognize this, and therefore will on occasion feature a new tip that we feel is among the best of the best. So keep an eye on this page for life-altering (or at least mildly interesting) tips to add to your ''repertoire''.
 
==[[VimTip45|This month's feature]]==
 
The featured tip this time around is [[VimTip45|''Using command-line history'']].
 
 
This tip was first nominated by [[User:Fritzophrenic|Fritzophrenic]]. Thanks for finding this great tip!
 
 
===What's it about?===
 
Make sure you know how to use command and search history. Remember that Vim allows powerful editing commands – there's more to life than the primitive arrow, backspace and delete keys.
 
 
Now you can use all Vim's power in the command-line window to search, copy and edit previously-entered commands and searches.
 
 
See [[VimTip45|''Using command-line history'']] for details.
 
   
 
==Previously featured tips==
 
==Previously featured tips==
This is an archive of the ''Featured tip'' section on the [[Main Page]] (started in February 2008). We won't feature these tips again – however, they remain great tips!
+
This is an archive of the ''Featured tip'' section on the [[Vim Tips Wiki|home page]]. We may not feature these tips again, however they remain great tips!
 
===[[VimTip667|August 2008]]===
 
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.
 
 
===[[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!
 
 
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.
 
   
===[[VimTip1376|June 2008]]===
+
===[[VimTip630|June 2012]]===
  +
When writing a program it can be convenient if closing brackets are automatically inserted. For example, after typing <code>'''{'''</code> it can be handy if the closing <code>'''}'''</code> is added automatically.
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>.
 
   
  +
Our [[VimTip630|featured tip]] discusses solutions for this problem: some simple mappings are provided and their shortcomings outlined. More advanced solutions require a plugin, and a list of scripts for the automatic insertion of matching brackets is provided.
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.
 
   
===[[VimTip1285|May 2008]]===
+
===[[VimTip1662|June 2011]]===
  +
Vim can work with all the major [[File format|line-ending formats]] but sometimes does not load a file in the format you want. Usually this is because a different text editor saved a file with mixed line-ending styles. It can be very annoying to load a file in Vim, which reads in with a Unix file format, when only a few lines lack this carriage return. It is worse when you cannot modify it because of strict revision control.
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]].
 
   
  +
Our [[VimTip1662|featured tip]] automatically reloads such files using DOS format if any DOS-style line endings are found. This will automatically "correct" the file if you save it, so an enhanced version will also tell you how many line endings are in each style so you can decide for yourself which format to use on a save.
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]].
 
   
===[[VimTip1440|April 2008]]===
+
===[[VimTip246|April 2011]]===
  +
For a long time now, Vim has had the ability to work with files in a very large set of [[wikipedia:Character encoding|character encodings]]. Using a character encoding with a very large range of characters, such as the Unicode encodings, can provide many benefits to any Vim user. Whether you need to work with multiple languages, or just want to use fancy box-drawing characters and arrows in your 'listchars' option or a plugin, using a Unicode encoding can make editing in Vim even more pleasant than it already is.
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.
 
   
  +
There are a lot of options that impact encoding in Vim, and it can be intimidating to someone not familiar with them. (And who really is?) Our [[VimTip246|featured tip]] discusses the various options you will need to start using Unicode successfully. Use the included example as a starting point or a drop-in addition to your [[vimrc]] to start editing in Unicode today!
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.
 
   
===[[VimTip1543|March 2008]]===
+
===[[VimTip1369|February 2011]]===
  +
Vim is made to work well with other tools, which means that whenever Vim saves a file, it correctly adds a line ending of the [[File Format|correct format for your system]] to the end of every line. When the file already existed, this is usually done whether the original file had a line ending on the final line or not. Nevertheless, Vim does keep track of whether the file originally had a line ending on the last line in the {{help|prefix=no|'eol'}} option, so that when writing binary files Vim does not introduce any new bytes.
We know how to use <tt>/pattern</tt> to search the current file for the regular expression ''pattern''.
 
   
  +
Our [[VimTip1369|featured tip]] takes advantage of this 'eol' option, to preserve the missing end-of-line on the last line of files which are read in without one.
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.
 
   
  +
This can be useful if you work on a project with very strict policies against needless changes to files, or which specifically require no EOL on the final line.
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]]===
+
===[[VimTip1643|January 2011]]===
  +
The ability to undo mistakes and redo them if you change your mind is a basic feature of any advanced editing program. Vim expands on this, keeping track of ''every'' change made in one or more "undo branches", so that you can return to any state your buffer was in even after undoing those changes and making different changes. Vim 7.3 adds the "persistent undo" feature, which saves this undo tree between editing sessions to make it even more powerful.
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.
 
   
  +
Our [[VimTip1643|featured tip]] will introduce you to Vim's undo tree, and even show you some plugins that make it simple to use.
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.
 
   
  +
==Previous years==
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.
 
  +
*[[/2010|2010 ''Featured tips'']]
  +
*[[/2009|2009 ''Featured tips'']]
  +
*[[/2008|2008 ''Featured tips'']]
   
 
==Comments==
 
==Comments==
In February 2009, we will move the 2008 archive to a subpage, and put the January 2009 summary above.
 
<!-- Add comments here, separate with "----" -->
 

Latest revision as of 03:49, 7 November 2013

  • Please discuss proposals for new Featured Tips on the talk page.
  • The home page highlights the current featured tip.
  • Add comments on the current featured tip to the comments section on the current tip page.

Now THAT's a Good Tip![]

While most of the tips on this wiki are very helpful, every now and then, you'll stumble on a tip that shines above all the rest. Such a tip is a tip that changes the way you do a basic task, a tip that you try immediately and then use all the time, a tip that makes Vim integrate SO much better with your setup, or a tip that you just wish somebody gave to you when you started using Vim. We here on the Vim Tips Wiki recognize this, and therefore will on occasion feature a new tip that we feel is among the best of the best. So keep an eye on this page for life-altering (or at least mildly interesting) tips to add to your repertoire.

Previously featured tips[]

This is an archive of the Featured tip section on the home page. We may not feature these tips again, however they remain great tips!

June 2012[]

When writing a program it can be convenient if closing brackets are automatically inserted. For example, after typing { it can be handy if the closing } is added automatically.

Our featured tip discusses solutions for this problem: some simple mappings are provided and their shortcomings outlined. More advanced solutions require a plugin, and a list of scripts for the automatic insertion of matching brackets is provided.

June 2011[]

Vim can work with all the major line-ending formats but sometimes does not load a file in the format you want. Usually this is because a different text editor saved a file with mixed line-ending styles. It can be very annoying to load a file in Vim, which reads in with a Unix file format, when only a few lines lack this carriage return. It is worse when you cannot modify it because of strict revision control.

Our featured tip automatically reloads such files using DOS format if any DOS-style line endings are found. This will automatically "correct" the file if you save it, so an enhanced version will also tell you how many line endings are in each style so you can decide for yourself which format to use on a save.

April 2011[]

For a long time now, Vim has had the ability to work with files in a very large set of character encodings. Using a character encoding with a very large range of characters, such as the Unicode encodings, can provide many benefits to any Vim user. Whether you need to work with multiple languages, or just want to use fancy box-drawing characters and arrows in your 'listchars' option or a plugin, using a Unicode encoding can make editing in Vim even more pleasant than it already is.

There are a lot of options that impact encoding in Vim, and it can be intimidating to someone not familiar with them. (And who really is?) Our featured tip discusses the various options you will need to start using Unicode successfully. Use the included example as a starting point or a drop-in addition to your vimrc to start editing in Unicode today!

February 2011[]

Vim is made to work well with other tools, which means that whenever Vim saves a file, it correctly adds a line ending of the correct format for your system to the end of every line. When the file already existed, this is usually done whether the original file had a line ending on the final line or not. Nevertheless, Vim does keep track of whether the file originally had a line ending on the last line in the 'eol' option, so that when writing binary files Vim does not introduce any new bytes.

Our featured tip takes advantage of this 'eol' option, to preserve the missing end-of-line on the last line of files which are read in without one.

This can be useful if you work on a project with very strict policies against needless changes to files, or which specifically require no EOL on the final line.

January 2011[]

The ability to undo mistakes and redo them if you change your mind is a basic feature of any advanced editing program. Vim expands on this, keeping track of every change made in one or more "undo branches", so that you can return to any state your buffer was in even after undoing those changes and making different changes. Vim 7.3 adds the "persistent undo" feature, which saves this undo tree between editing sessions to make it even more powerful.

Our featured tip will introduce you to Vim's undo tree, and even show you some plugins that make it simple to use.

Previous years[]

Comments[]