1, Opening files Go to top
Open several files in tabs:
gvim -p [file1] [file2]
If you run this command again, with different files, you will get a new gvim window.
To open other files in the existing gvim window, in new tabs:
gvim --remote-tab-silent [file3] [file4]
I created a bash alias to do this. See Bash aliases.
Because error output is suppressed with the -silent suffix on the
--remote-tab-silent flag, this flag can be used instead of the -p flag to open a
new window when one doesn't already exist. In other words, just use this last
example and don't bother using the first.
If you run gvim multilpe times so you have many gvim windows, you can send files
to a specific window by using the --servername option. The title of the window
will give the servername, e.g. GVIM, GVIM1, etc.
gvim --servername GVIM1 --remote-tab-silent [file3] [file4]
2, Tabs and buffers Go to top
Key bindingAction
:tabnewOpen a new tab
:tabnew [filename]Open [filename] in a new tab
:tabf [filename]Search for [filename] in your current path and open it in
a new tab
:bnNext buffer
:bpPrevious buffer
:lsList buffers
:b[n]Open buffer [n]
:bdClose buffer
ctrl-w wSwitch viewport
3, Editing and Navigation Go to top
I have a graphical cheatsheet printed out and stuck in from of my monitor. There
are loads available - just search for 'vim cheatsheet' in your favourite search
engine (the one I use is from Graphical vi-vim Cheat Sheet and Tutorial). The
list below contains some of the less commonly listed shortcuts and combinations
- ones that aren't explicitly on the cheatsheet or those that I'm most likely to
forget.
From insert mode, hit escape then the key binding.
Key bindingAction
$Go to end of line.
f[char]Move forward to the next occurence of [char]. A semicolon ; repeats
the command.
F[char]Move backward to the previous occurence of [char]. A semicolon ;
repeats the command.
y$Copy, i.e. yank, the text from the cursor to the end of the line. Paste
with p.
ywCopy a word.
:tabdo [action]Perform an [action] across files in all tabs. e.g. :tabdo
%s/foo/bar/g to replace foo with bar in all files.
ctrl-rRedo
[[Go to top of file
]]Go to bottom of file
:[n],[m]dDelete from line [n] to line [m]
[n],[m]ddDelete from line [n] to line [n]+[m]
ctrl-fPage up (forward)
ctrl-bPage down (backward)
ctrl-u1/2 page up
ctrl-d1/2 page down
%Jump from an open brace to its matching closing brace, or vice versa
[{Jump to the "{" at the start of the current code block
]}jump to the "}" at the end of the current code block
q[char]Start recording macro [char]
qStop recording macro
@[char]Playback macro [char]
@@Repeat macro playback
m[char]Create a mark [char]
y'[char]Yank from mark [char] to current cursor position (operations other
than yank can also be performed)
"+yYank to clipboard so that you can paste into an external application
(operations other than yank can also be performed)
"+pPaste from clipboard (also see "+y above)
"[char]yYank to buffer named [char] (operations other than yank can also
be performed)
"[char]pPaste from buffer named [char] (also see "[char]y above)
:.,$ s/[old]/[new]/gReplace all occurrences of [old] with [new], between
the current line and the end of file. Note that the .,$ is the range,
where . is the current line and $ is the EOF.
:.,.+[n] s/[old]/[new]/gReplace all occurrences of [old] with [new],
between the current line and the current line plus [n] lines. Note that
.,.+[n] is the range, where . is the current line and .+[n] is the current
line plus [n] lines. e.g. .,.+3 is the current line and the next 3 lines.
4, Command history Go to top
You can view and navigate a list of previously entered commands.
Type q: to open the command history in a small viewport (note that you can edit
the history as you would any other document). Navigate to a command and hit
enter to execute it. Typing : again will place you back in the command mode, so
you can execute a command like q to close the command history or [num] to
quickly jump to command number [num].
5,Completion and intelligent completion with Omni-completion Go to top
Vim comes with a set of completion configuration scripts for a variety of
languages. For Vim 7 on Gentoo Linux they are in /usr/share/vim/vim70/autoload/.
These scripts allow you to start typing the beginning of a language's word, like
the lines and have
To disable text width, set it to 0:
:set textwidth=0
Show invisible characters - tabs as ^I and end of line as $.
:set list
7, rc files Go to top
Most vim options can be set in either /etc/vim/vimrc to apply the options to all
users, or in /home/[username]/.vimrc to apply the options for the user
[username].
You can add comments to the rc file using the " (double quote) character.
For example, I added the following to the end of my /etc/vim/vimrc file to set
various search and formatting options.
set ignorecase
set incsearch " Highlight search terms as you type.
set hlsearch " Highlight all matched search terms.
set nolbr " No line break.
set wrap
set number
8, Ruby on Rails Go to top
There are a number of helper scripts that can be used to aid development of Ruby
or Ruby on Rails applications.
First, check out HowtoUseVimWithRails. Of the suggestions in this article, I
only use the rails.vim so far. See my page on vim with the rails.vim plugin for
further information.
9, Diff and merge Go to top
You can use vim as a diff and merge tool. See Diff and merge using vim (or gvim)
10, References Go to top
Vim online
Vim documentation: options
Efficient Editing With Vim
Graphical vi-vim Cheat Sheet and Tutorial
VIM Useful Commands
Omni completion. Vim documentation: Version 7
Tip #14: Highlighting all the search pattern matches : vim online
HowtoUseVimWithRails
rails.vim
Linux.com Vim tips: Using tabs
Linux.com Vim tips
Best of VIM Tips, gVIM's Key Features
C editing with VIM HOWTO: 4. Auto-Completing Words
Tip #312: Copy, Cut, and Paste : vim online
Vim documentation: gui_x11
Vim Regular Expressions 101
December 2002 Linux Productivity Magazine: VI and Vim
http://mindspill.net/computing/linux-notes/vim-and-gvim.html#top
没有评论:
发表评论