Showing posts with label Vim. Show all posts
Showing posts with label Vim. Show all posts

Saturday, April 28, 2007

Basic vi Commands

Edit Commands
Text Object Change Delete Copy
1 word cw dw yw

2 words, not counting punctuation

2cW or c2W 2dW or d2W 2yW or y2W
3 words back 3cb or c3b 3db or d3b 3yb or y3b
1 line cc dd yy or Y
To end of line c$ or C d$ or D y$
To beginning of line c0 d0 y0
Single character r x or X yl or yh
Five characters 5s 5x 5yl

Movement
Movement Commands
<-,-v,-^, " src="../chars/rarr.gif">

h, j, k, l

To first character of next line +
To first character of previous line -
To end of word e or E
Forward by word w or W
Backward by word b or B
To end of line $
To beginning of line 0

Other Operations
Operations Commands
Place text from buffer P or p
Start vi, open file if specified vi file
Save edits, quit file ZZ
No saving of edits, quit file :q!

Text Creation and Manipulation Commands
Editing Action Command
Insert text at current position i
Insert text at beginning of line I
Append text at current position a
Append text at beginning of line A
Open new line below cursor for new text o
Open new line above cursor for new text O
Delete line and substitute text S
Overstrike existing characters with new text R
Join current and next line J
Toggle case ~
Repeat last action .
Undo last change u
Restore line to original state U

Hot Vim Plugins

See http://www.newsmth.net/bbscon.php?bid=731&id=24898&ftype=11 for details.

In Chinese!

Vim 实用技术

From: http://www.ibm.com/developerworks

Vim 实用技术,第 1 部分: 实用技巧

本系列文章分三部分详细阐述了 Vim 的使用技巧、插件、定制。第一部分主要是深入分析了 Vim 的使用。

Vim 实用技术,第 2 部分: 常用插件
第一部分介绍了一些基本的 Vim 使用技巧。掌握这些技巧可以很大地提高编辑效率,但是 Vim 的强大功能并不仅限于此。Vim 还可以通过“插件”来进行功能扩展。精确地说,是通过脚本来进行扩展,脚本类型有插件、语法加亮、配色方案、文件类型检测等多种。大部分的脚本都是由 Vim 的用户写的,解决了用户身边的问题,使 Vim 变得更加有用。本章将介绍最常用的一些脚本,其中除了一个属于“语法加亮”脚本外,其它都属于“插件”类型。关于如何写脚本的一些基础知识将在下一部分进行一些介绍。

Vim 实用技术,第 3 部分: 定制 Vim
前面两部分讲的都是如何使用现有的 Vim 系统,本部分则会通过实例来讲如何定制 Vim 的行为。良好的定制可以让使用 Vim 变得更为得心应手;同时,在掌握了基本的定制之后,也许你就会想进一步写一些自己的 Vim 脚本,从而真正地成为一个 Vim 专家。

[Please Click the links to see the details...]

Tips: Making Vim easy

Vim's flexibility and countless features are a major asset for experienced users, but a challenge for newbies. If you've always wanted to try Vim but were put off by your first attempts, you can start off gradually by getting to know Vim's GUI and easy mode. This article is a primer for those who haven't used Vim much and want to wade in gradually.

If you're new to Vim and vi-like editors, the Vim GUI is probably the best way to get started. You can perform the operations you're familiar with using Vim's keybindings, but when you get stuck, you can use the mouse and the gVim menus to get things done quickly and efficiently.

Even better, when there is a keybinding for a command, it's usually displayed in the gVim menu -- so if you keep performing the same operation, you'll probably pick up the keybinding through repetition and eventually be able to go mouseless -- if that's your goal, of course.

There's little, if anything, you can do using gVim that you can't do in the standard version of Vim, and many operations are easier or more intuitive when you have menus and icons to deal with.

Staring gVim

To start gVim, run gvim or vim -g. If you want to edit a file with gVim right away, you can launch gVim with gvim filename or vim -g filename .

As with Vim, you can also launch gVim with the +n option, where n is the line number you want to start on. So, for instance, gvim +10 filename will bring up gVim with filename loaded and the cursor on line 10.

Another trick is to load gVim at the first instance of a search term. Let's say you want to start editing at the first instance of the word foobar. Use:

gvim +/foobar filename

Once you start gVim, you'll notice that it looks more or less like any other GUI text editor. Like any other editor, it provides several menus, a scrollbar on the right-hand side of the window (which can be moved, or done away with, if desired), and a toolbar at the top of the window for quick access to common functions like Save, Undo, and Search.

Easy Vim

Vim also has an "easy" mode, which isn't touched on too often in Vim tutorials and docs, since it really goes against what most users are looking for from Vim. Vim, as you know if you've used it much, is a "modal" editor, based on Bill Joy's classic vi. Vim has an insert mode, a command mode, a visual mode, and (depending on whom you ask) a few additional modes. Once you get the hang of it, the modal nature of Vim is extremely useful. However, until you get used to it, Vim can be a hassle when trying to figure out simple operations like searching and replacing text.

Easy mode is actually a collection of various Vim options that tell Vim to act like any standard text editor. Instead of using y to "yank" (copy) text, and then pasting text using p or P in normal mode, Vim's easy mode lets you use the standard Ctrl-c to copy text and Ctrl-v to paste text. Anybody who has use Notepad or Microsoft Word for a week or two will be familiar with these shortcuts, and emulating them makes Vim more intuitive for the average user. Check Vim's help for more on easy mode to find out exactly what Vim's doing behind the scenes.

Why would you want to use Vim without access to its modes? Well, Vim still includes a number of spiffy tools and features that aren't dependant on its vi-like modes -- macros, syntax highlighting, sessions, and other Vim goodness that you might not find in an editor like Kate or gedit.

Easy mode also enables a context menu, which isn't present in standard Vim/gVim. When you right-click in the gVim window, you'll see a menu that will allow you to select text by the word, sentence, paragraph, line, or all text in the buffer. You can also use the context menu to copy, cut, delete, and paste text, and to undo operations.

If you like the context menu, but don't want to run Vim in easy mode, you can simply set the mouse behavior using this command:

:behave mswin

Then you'll have the context menu, even when you're not in easy mode.

By default, pressing Esc in easy mode will not put you in command mode. If you decide you want to start using gVim in regular mode, you can go to Edit -> Global Settings -> Toggle Insert Mode, which will put you into command mode. After running this, you'll be able to switch between easy mode and normal gVim/Vim modes. If you want to drop back exclusively to easy mode, toggle it with the menu or run :set im! in command mode.

The rest of this article will assume that you're using gVim in normal mode, but I wanted to point out the easy gVim mode for users who might like to get started with Vim is the friendliest manner possible.

By default, gVim will start with a conservative color scheme of black text on a white background. If you prefer something a bit more interesting, gVim has several color schemes available. Go to the Edit menu and select Color Scheme. You should see about a dozen choices, including blue, darkblue, and peachpuff.

Working in gVim

This probably goes without saying, but since gVim is designed as a GUI text editor, you can select text using the mouse in addition to Vim's usual text selection methods. This means that all you need to do to highlight a letter, word, or sentence is to grab the mouse and highlight the text that you'd like to select. You can also place the cursor anywhere on the screen just by moving the mouse. (You can also enable this in regular Vim running in an xterm or other terminal emulator, but it requires mouse support being built in and is not on by default.)

However, don't forget that the mouse is a clumsy tool compared to Vim's normal selection capabilities. Using v you can start the visual mode for selecting by character, V to select by lines, and Ctrl-v to select text blocks.

It's also worth noting that you have two clipboards in gVim. There's the current selection, which means any text that's highlighted, and there's text copied to the clipboard, which persists after you've selected new text. For example, if you use the mouse to select a sentence and then click the middle button, you'll paste the text that you just selected. But if you select text and use Vim's Edit menu to copy text, it will be stored in the clipboard even when you select new text. This can be useful if you have a string that you'll be pasting several times (say, a letter template) and need to use the standard selection method for other text.

I've written about Vim's viewports before, but viewports are much easier to manage in gVim. You can use the normal Vim keybindings to open a viewport, or you can just go to Window -> New to create a new viewport so you can edit a new file, Window -> Split to split the window using the same file that's already open, or Window -> Split Vertically to divide the viewport vertically instead of horizontally. Using Ctrl-w will move you from viewport to viewport, or you can use the Window menu to move to another viewport, or just click the left mouse button in the viewport you want the cursor to be in.

The really nice thing about viewports in gVim, though, is that you can easily resize them with the mouse. In standard Vim, you need to use Ctrl-w - and Ctrl-w + to resize the windows, but in gVim you can resize them using the mouse or the standard Vim keybindings, depending on which you find easier to use.

Even though gVim is a GUI-based program, the shell is never far away. To get to a shell from a gVim session, just :sh; type exit when you want to get out of the shell. Note that gVim's terminal emulation may leave something to be desired in terms of screen refresh, so you probably want to stick to a regular terminal emulator for most of your work.

gVim's file explorer

You can use gVim to edit remote files almost as easily as using Vim in a remote shell. I usually edit files on my server by using SSH to get a shell on the remote machine and then editing a file, but you can do the equivalent using gVim (or regular Vim) from your local session.

To open a remote file using secure copy (scp), do the following:

:e scp://user@remote.host.net/path/to/file

This will open a secure connection on the remote machine as the user specified. If you have an SSH key set up, you can log in without a password. If you don't have a key set up, you will be prompted for a password each time you save the file, which can be a bit of an annoyance.

Note that this will work with several protocols, so you could substitute sftp, ftp, rsync, and other methods. See the Vim help guide for the complete list.

What if you don't know the name of a remote file, or the exact path? Leave off the filename and you'll be dropped into Vim's file browser:

:e scp://user@remote.host.net/

You can browse through the directories and find whatever file you need to edit. Press Enter once the file you want is highlighted and start editing.

Finally, I would be remiss if I didn't mention gVim's spelling features. If you turn on behave mswin and turn on spellchecking, you can use the context menu to add a word to the dictionary, accept an alternate spelling, or ignore a word for spellchecking purposes. To turn on the spellcheck feature, go to Tools -> Spelling -> Spell Check On. You'll probably need to turn syntax highlighting off for the spellcheck to work properly; you can do that from the Syntax menu.

If you've never used Vim, or if you've used Vim and found it too difficult, try gVim for a few days. It has all of the amenities that you'd want from a boring old text editor, but with all of Vim's features lurking below the surface where you can unleash them at your leisure.

Friday, April 27, 2007

c.vim for VIM : C/C++ -IDE

created by
Fritz Mehner

description
** Statement oriented editing of C / C++ programs
** Speed up writing new code considerably.
** Write code und comments with a professional appearance from the beginning.
** Use code snippets

- insertion of various types of comments (file prologue, function descriptions, file section headers
keyword comments, date, time, ... )
- insertion of empty control statements (if-else, while, do-while, switch, ... )
- insertion of various preprocessor directives
- insertion of C-idioms (enum+typedef, loops, complete main, empty function, file open dialogs, ... )
- insertion of C++ -idioms ( frames for simple classes and template classes, try-catch blocks, file open dialogs, output manipulators, ios flags, ... )
- use and organize your own collection of code snippets
- compile / link / run support for one-file projects (without a makefile)
- run buffer through splint
- personalization of comments (name, email, ... )
- menus can be switched on and off (Tools menu)

Here are some screen shots : http://lug.fh-swf.de/vim/vim-c/screenshots-en.html

The help file online : http://lug.fh-swf.de/vim/vim-doc/csupport.html

Documentation
_____________
This plugin comes with a help file (csupport.txt). Read it with

:h csupport

install details
Copy the zip archive cvim.zip to $HOME/.vim/ and run
unzip cvim.zip
If you have already an older version of this plugin and you have modified the template files you may want to save your templates first or copy the files from the
archive by hand. See also the file README.csupport within the zip file.