Vim

From 43FoldersWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 21:49, 29 July 2005 (edit)
DavidDouthitt (Talk | contribs)
(Editing files that use non-Unix end-of-line characters)
← Previous diff
Current revision (15:20, 5 February 2008) (edit) (undo)
Drw (Talk | contribs)
(Vim Tips RSS feed)
 
(12 intermediate revisions not shown.)
Line 18: Line 18:
==Hacks== ==Hacks==
-=== Editing files that use non-Unix end-of-line characters ===+=== making outlines with vim ===
-Sometimes, you open a text file and the line formatting is all wrong and there are loads of annoying '^M' characters spread all throughout it. If you're using vim on a Mac, you are likely to encounter this problem a lot because it is caused when a Mac-formatted text file is opened in vim because vim prefers text files that are Unix-formatted. You could also run into similar problems with Windows-formatted text files. Luckily, this is an easy thing to deal with in vim.+
- +
-Actually, in current versions of vim, it will read and edit files like these just fine. You should never see those extra '^M' characters any longer. The editor should come up with a buffer status line message that says <tt>[dos]</tt> letting you know what format the file is in. However, the file ''will not change formats'' unless you use solution #1 below. vim has ''no trouble'' using solution #1 that I know of.+
-'''Solution #1:''' Type <tt>:set fileformat unix</tt> and hit enter while in edit (not insert) mode. This should reformat the file for you and solve the problem.+[[VimOutliner]]
- +
-'''Solution #2:''' Sometimes solution #1 doesn't work. So it is not recommended that you use it. Instead, use global search and replace to fix the files. While in edit mode, type <tt>:%s/\r/\r/g</tt> and hit enter. This will replace all Mac-formatted carriage returns with unix-formatted newlines. This seems counter-intuitive since you're telling the editor to replace carriage returns with carriage returns, but it works because of how vim interprets a carriage return command. Using the same fix to change a Windows file to a Unix file would require a different pattern, like this: <tt>:%s/^M//g</tt> (be sure to use ctrl-M when typing the ^M in the pattern, don't type a '^' character followed by a 'M' character).+
- +
-If typing that pattern in every time you need it seems a bit much, just map it to a key command. For example, put the following lines in your .vimrc file in your home directory: +
- +
- nnoremap M :%s/\r/\r/g <CR>+
- vnoremap M :%s/\r/\r/g <CR>+
- nnoremap W :%s/^M//g <CR> # Remember to type the ^M with ctrl-M and not with '^' followed by 'M'+
- vnoremap W :%s/^M//g <CR> +
- +
-Now the command to convert Mac text files into Unix text files is mapped to the uppercase 'M' in edit mode, so you can just type that command the instant you load the file and see that it's broken. Similarly, the command to convert Windows text files to Unix files is mapped to the uppercase 'W'. Additionally, if you use the commands while you have selected text in the file, the changes will only occur to that portion of the file that you have selected.+
- +
-If you want to better understand these commands, use vim's built-in help with these commands:+
- +
- :help mapping+
- :help substitute+
- :help pattern+
=== Using text files as a proto-Wiki === === Using text files as a proto-Wiki ===
Line 55: Line 35:
Now if you <tt>gf</tt> on a word that doesn't have a file yet, vim will create a buffer that will save to that file name - just like a wiki, essentially. Now if you <tt>gf</tt> on a word that doesn't have a file yet, vim will create a buffer that will save to that file name - just like a wiki, essentially.
 +
 +
 +See also
 +[[WikiAsPim]]
 +http://c2.com/cgi/wiki?VimKi
 +http://c2.com/cgi/wiki?VimAsPim
 +
 +==== * quickly Get Files in your Environment ====
 +
 +Abstract: what are some quick ways to access files? Environment variables
 +and the gf command. See this [http://www.vim.org/tips/tip.php?tip_id=985 vim tip] written by 43folders [[User:Gochess]].
 +
 +
 +
 +=== Editing files that use non-Unix end-of-line characters ===
 +
 +See our dedicated page to this topic at [[Vim/char-EOL]].
 +
 +=== Using Syntax Coloring ===
 +
 +A nice way to have your task list (and whatever else) easier to read is to use syntax coloring.
 +
 +Put
 + vim:set filetype=plan:
 +as a modeline (last line of the file, see :help modeline). And then put a file named plan.vim in your ~/.vim/syntax/ (or on windows ~/vimfiles/syntax/ with for instance contends
 +
 + syntax keyword Directory Goal Milestone Target Task
 + syntax match Directory "Category of Goal"
 + syntax match Special "^ [1-4]-[:a-zA-Z]*"
 + syntax match Special "[A-Z][a-z]\+ [-9]\+ [A-Z][a-z]\+$"
 + syntax match Special "\*\+"
 + syntax match NonText "^#"
 + syntax match NonText "^##"
 + syntax match NonText "^## [A-Za-z ]\+"
 + syntax match NonText "^###"
 +
 +For an explanation of these commands (and how you customize) see :help syntax. Don't forget to turn on syntax coloring by :synt on (or syntax enable in your .vimrc (on windows _vimrc)).
==See Also== ==See Also==
 +
 +* [http://www.vim.org/ vim.org]
 +* [http://en.wikipedia.org/wiki/Vi wikipedia: vi]
 +* [http://en.wikibooks.org/wiki/Vi wikibooks: Learning the vi editor]
 +* [http://vimoutliner.org VimOutliner]
 +* [http://users.tkk.fi/~thyle/vi_opas.html vi - quick tutorial]
 +* [http://www.fprintf.net/vimCheatSheet.html vim Cheat Sheet]
 +* [http://www.vi-improved.org/ vi-improved.org, home of #vim irc]
 +* [http://www.vi-improved.org/tutorial.php Quick vim tutorial in the form of an IRC conversation]
 +* [http://www.geocities.com/volontir/ vim regular expressions 101]
* [http://vimdoc.sourceforge.net/cgi-bin/vimfaq2html3.pl Vim FAQs] * [http://vimdoc.sourceforge.net/cgi-bin/vimfaq2html3.pl Vim FAQs]
* [http://vim.sourceforge.net/tips/tip_search_results.php?order_by=rating Best of Vim Tips] * [http://vim.sourceforge.net/tips/tip_search_results.php?order_by=rating Best of Vim Tips]
 +* [http://www.pinkjuice.com/howto/vimxml vim as XML editor]
* [http://www.macvim.org/ Mac Vim] features binaries for OS X and Classic * [http://www.macvim.org/ Mac Vim] features binaries for OS X and Classic
* [http://www.43folders.com/2005/03/remainders_vim_.html 43F comments thread full of good Vim tips] * [http://www.43folders.com/2005/03/remainders_vim_.html 43F comments thread full of good Vim tips]
 +* [http://www.zinkwazi.com/unix/notes/tricks.vim.html tricks.vim.html]
* [[Viki]] * [[Viki]]
-* [http://www.cafepress.com/shop/geeks/browse/Ne-25_N-3807_bt-2_pv-geekcheat.11507711 vi reference mug]+* [http://www.vim.org/scripts/script.php?script_id=1318 SnippetsEmu] - An attempt to emulate the Snippets feature from TextMate
 +* [http://www.vim.org/scripts/script.php?script_id=69 Project.tar.gz] - IDE like project file management. Could surely be used for maintaining GTD lists.
 + 
 +=== The Vim Cookbook ===
 + 
 +* [http://www.oualline.com/vim-cook.html vim Cookbook] covers topics like:
 +** Sorting a section (Visual Method)
 +** Dealing with Makefile and other SOB files
 +** Removing carriage returns from MS-DOS file
 +** Oops, I left the file write protected
 +** Changing "Last, First" to "First Last"
 +** How to edit all the files containing a given word using the built-in grep
-=== Join the Mailing List ===+=== Mailing List ===
# subscribe to the list by sending a message to vim-subscribe@vim.org # subscribe to the list by sending a message to vim-subscribe@vim.org
# read the [http://groups.yahoo.com/group/vim/messages archives] # read the [http://groups.yahoo.com/group/vim/messages archives]
 +=== Vim Tips RSS feed ===
 +* For the recent Vim Tips: '''(feed currently experiencing difficulties)''' -- incredible gems show up from time to time! And please share [http://www.vim.org/tips/add_tip.php your own tip here].
-[[Category: Cross-Platform Software]] [[Category:Text Editors]] [[Category: Open Source]]+[[Category: Cross-Platform Software]] [[Category: Console Interface]] [[Category:Text Editors]] [[Category: Open Source]]

Current revision

Vim
Platform: many
License: Charityware
Cost: $0
Download Size:  ??
Site: http://www.vim.org/

Contents

[edit] Description

Vim, or "vi improved" is a text editor by Bram Moolenaar. It is an enhanced version of "the unix text editor," vi, which is in turn based on ed and ex.

[edit] Testimonials

The Linux Journal magazine in its annual Readers' Choice Award selected vim as favorite text editor four years in a row!

[edit] Hacks

[edit] making outlines with vim

VimOutliner

[edit] Using text files as a proto-Wiki

Have you ever tried the gf command? It parses whatever word is under the cursor and tries to open that file in a new buffer. You don't need to use WikiCase for jump words, but it might be helpful. (On *nixes this operation will be case sensitive, I'm guessing on Windows it would be case insensitive.)

By way of example, this allows one to have a "todo" file containing text like projects/foo - Foo, the generic project. If you have your cursor over projects/foo and hit gf in command mode, the foo file in the projects directory will open in a new buffer. To navigate the jump history, use Tab or Ctrl-I to go forward and Ctrl-O to move backwards. Your todo file can now link to related files without any actual link markup! Maximum laziness. Of course, you don't need to organize them in subdirectories, either.

Since vim 6.x can also open directory listings, if you have a bunch of files in the projects directory and wish to link to a list of them, just use projects/!

For further wiki-like behavior, add this mapping to your .vimrc: (See the vim help on gf)

:map gf :e <cfile><CR>

Now if you gf on a word that doesn't have a file yet, vim will create a buffer that will save to that file name - just like a wiki, essentially.


See also WikiAsPim http://c2.com/cgi/wiki?VimKi http://c2.com/cgi/wiki?VimAsPim

[edit] * quickly Get Files in your Environment

Abstract: what are some quick ways to access files? Environment variables and the gf command. See this vim tip written by 43folders User:Gochess.


[edit] Editing files that use non-Unix end-of-line characters

See our dedicated page to this topic at Vim/char-EOL.

[edit] Using Syntax Coloring

A nice way to have your task list (and whatever else) easier to read is to use syntax coloring.

Put

 vim:set filetype=plan:

as a modeline (last line of the file, see :help modeline). And then put a file named plan.vim in your ~/.vim/syntax/ (or on windows ~/vimfiles/syntax/ with for instance contends

 syntax keyword Directory Goal Milestone Target Task
 syntax match Directory "Category of Goal"
 syntax match Special "^  [1-4]-[:a-zA-Z]*"
 syntax match Special "[A-Z][a-z]\+ [-9]\+ [A-Z][a-z]\+$"
 syntax match Special "\*\+"
 syntax match NonText "^#"
 syntax match NonText "^##"
 syntax match NonText "^## [A-Za-z ]\+"
 syntax match NonText "^###"

For an explanation of these commands (and how you customize) see :help syntax. Don't forget to turn on syntax coloring by :synt on (or syntax enable in your .vimrc (on windows _vimrc)).

[edit] See Also

[edit] The Vim Cookbook

  • vim Cookbook covers topics like:
    • Sorting a section (Visual Method)
    • Dealing with Makefile and other SOB files
    • Removing carriage returns from MS-DOS file
    • Oops, I left the file write protected
    • Changing "Last, First" to "First Last"
    • How to edit all the files containing a given word using the built-in grep

[edit] Mailing List

  1. subscribe to the list by sending a message to vim-subscribe@vim.org
  2. read the archives

[edit] Vim Tips RSS feed

  • For the recent Vim Tips: (feed currently experiencing difficulties) -- incredible gems show up from time to time! And please share your own tip here.
Personal tools