|
[ Source ]
vim
Created: 2007-11-28 23:19:00
Modified: 2009-06-06 23:53:00 Categories: tools text_editor programming Keywords: vim programmers editor Description: Some vim tips and a little vim reference. This document is here to duplicate the useful ':help' information. Just a nice quick shortcut reference. Table Of ContentsIntroductionSome notes about
A thing that i can suggest to new users of You should also need to tweak your If you plan to tryout ModesWhile you use
Remember, to go in, normal mode, press escape, it's better to press several times escape when you not know in which mode you are. The normal mode is the default mode. From the normal mode, you can easy go to the other 2 modes. To go in Then you usually enter all your text like your used to do with all other text editors. To go in visual mode, press the 'v' key. Remember to first press esc twice. To go out of the previous mode. Once in visual mode; you can use the arrow keys to move and select some text. The visual mode is useful for selecting block, parts of text and perform somethings on it. Say re-formate the paragraph, copy and pasting some stuff, delete the selected text ... The most frustrating thing for the new user are these modes. Because each action is depending on the mode. You will see below too, there are some keyboard shortcuts noted. But these depend highly on the mode you are in. Read been the additional comments. Some needs to be are executed in visual mode and not in normal mode. When you see somethings like There are some more modes to. Need to write more about it. Navigation keysIn normal mode press these keys to navigate into the text. To go in navigation
mode or be sure that you are in these mode press the
Sure, you can use the arrow keys of the keyboard to navigate. Some keys need to knowThere are some keys you need to know. Like exiting a file without saving the modification. Probably you may mess up some things while experimenting. In normal mode:w write (save)
:w FILENAME write to FILENAME
:wall write all files
:q quit
:q! quit without saving
:qall! quit all without saving
:wq write & quit
:wqall Write and quit all
:e! Restore to last save state
:E Open the build in explorer so you can
browse and open whatever file
:Explorer idem
:e . idem
ZZ Write file and quit
ctrl-c To go out of inserte mode and go back to normal mode
2k move 2 lines up
4h move 4 characters to the left
:verbose command show you all commands and which script defined them
:command shows you command names
:verbose command E Will list the source of all
commands starting with E
x Delete a character at the cursor
position
i Insert text (Go in insert mode)
I Insert at the begin of the line.
A Append text at the end of the line.
a!!!<esc> Append the text '!!!' to the end of the line
a Append text after the cursor
possition.
gl
o Open a line below the current cursor
position.
O Open a line above the current cursor
position.
o This is append<esc> Append 'This is append'
d delete
d2 delete 2 chars. Can use any decimal
number
dw Delete word.
daw Delete word.
das Delete a sentence.
dap Delete a paragraphe.
d$ Delete from cursor position to the
end of the line
dd Delete whole line (Can also '2dd'
to delete 2 lines).
de Delete to the end of the current
word, INCLUDING the last character.
p put or the last deleted line
yy Copy the whole line.
7yy Copy 7 lines.
p Paste current buffer.
J Joining 2 lines
16G Jump to line 16 works on any other integer
Movinge Move to the end of the word, next end
of word if already on the end
w Move to the next word
2w Move 2 words forwards
3e Move the cursor to the end of the
third word forward.
0 (zero) Move to the begin of the line
C-e Scrolling down with leaving the cursor
in position
C-y Scrolling up with leaving the cursor in
position
Undo/redou undo previous action U undo all the changes on a line CTRL+R redo (undo the undo) CTRL+r idem Foldingzi (N) Enable/disable folds zo Open one fold of N if provided zc (N) Close one fold of N if provided zO Open all folds. zC Close all folds zv View Cursor Line zMzX View Cursor Line only zm Close more folds zM Close all folds zr Open more folds zR Unfold all zd Delete Fold zD Delete All Folds :set fdm=marker Set type of fold marker :set foldmethod=indent For python :set foldenable :help :folding For help about folding. Change the case~ Toggle the case gU Upercase the selection gu Lowercase the selection Spell:set spell Activate spell :set nospell Desactivate spell :set spl=en spell Set english spell checking ]s Next error [s Previous error z= Suggest Corrections :spellrepall Repeat correction zg To put word under cursor to the own word list zw To put the word in the bad list, if it was in the good word list zW Like zw, but put it in the internal word list Identing text:> Indent to right. >> Indent to right. :< Indent to left. << Indent to left. Window manipulating:split Horizontal split :vsplit Vertical split ctrl+w + Grow window ctrl+w - Shrink window ctrl+w _ Shink the window to the maximum ctrl+w w Jump to other window :close Close the current window Patching:set patchmode=.orig Not classified stuff:tabedit thatfile
# Need to execute the commands in normal mode
:make Make
:cl List Errors
:cl! List Messages
:cn Next Error
:cp Previous Error
:cold Older List
:cnew Newer List
r Replace characters
cw Change word
c$ Change to the end of the line
:CTRL-g Show location in the file and status
:shift-G Go to the bottom of the file
:x schift-G where x is a number to go
:!COMMAND to execute an external command. ex. :!ls
#,# w FILENAME To save a part of a file
where the first # is the line number of
the top and
the second # is the bottom number.
CTRL-g to view line number
:r FILENAME To insert the content of a extern file.
R To replace more than one word, go Replace
Mode.
~ Change case of the letter if lower set
upper and versa.
:set To view the active parameters.
:set all To view all the parameters. Verry usefull !!!
:synatax on or off to enable/disable syntaxhighlighting.
:help w To find help about w.
:help c_
In Visual moded Delete selected text y Yank (copy) selected text ~ Reverse case of selected text gq Reformat the text to the textwith variable Searching:/KEYWORD To search a keyword
press 'n' to go next
press 'shift-n' to go back
% To find the next ),] or } usefull for debugging
you must set the cursor on the first ex. (,[,{
:set ic To ignore case (no case sensitive while search)
:set hls is hlsearch and incsearch (highlighting and incasesensitif)
:nohlsearch Remove highlighting.
# To highlight all words matching the word the cursor is on,
press the # key (altgr+#)
Patern matching:s/old/new/ Change the first word 'old' by 'new' of the line.
:s/old/new/g Change all words 'old' by 'new' on the line.
:s/\./!/ Replace the dot with an exclamation mark. And example
how to escape some special character.
:s/^- //g Replace all lines starting with '- ' with '' (empty).
:s/foo/bar/gc Replace all words foo by bar on the whole line and confirm
:%s/word1/word2/gc Replace all words 'word1' with word2, and ask
each time a confirmation (% for all lines, g
for all occurences, and c for confirmation.
:g/^#/d Delete all line that start with #
:g/^$/d Delete all empty line
Setting the width of textvim: set ft=text80: Change case of textgUw Change the word to uppercase g~w Switch the case of the word. guw Change the word to lowercase. gUw Change the word to uppercase ~ Change the case. Copy somethingsY Copy the current line to the temp buffer.
yy Same as 'Y'.
ye Copy a word to the temporary buffer.
yw Same as 'ye'.
y$ Copy from cursor position to the end
of the line.
J Join the previous line to the current line.
gJ Same as 'J' but without a space(vim).
:j! Same as 'J'.
:!command To run a command. ex ':!ls'
:!! Repeat the lastest system command
(usefull to repeat...)
Paste somethingsp Paste the deleted or yanked text.
gp Same as 'p' but leave the cursor
position (vim)
]p Same as 'p' but match the current
indention. (vim)
[p
P
gP
Commenting a line# With commenting, i mean putting a "#" in begin of a line :m,ns/^/# Where m is the starting line and n the end # Or in visual block mode (ctrl+v), select some line and then: I#<esc> Folding textAn example, put The following in a new file, save and exit. Reopen it. Automatic folding# This should be folded {{{
This is some hidden stuff in the fold.
#}}}
# vim:foldmethod=marker expandtab
And you should get somethings like this when you reopen the file: +-- 5 lines: This should be folded -------------------------------------- # vim:foldmethod=marker expandtab Increasing numbersIf you have some number, say Command line rangesIf you want to delete all the lines after :102,$d For more info see: :help cmdline-ranges or better: :he 10.3 Othergl
o Open a line below the current cursor position.
O Open a line above the current cursor position.
Commands that work in 'Insert Mode':
Ctrl+W Delete previous word (vim).
Ctrl-A Repeat the lastest insertion (vim).
Ctrl-U Delete the current line.
Ctrl-[ Terminate the 'Insert Mode' and go in 'Visual Mode'.
The previous given commands are set by 'ssty', so it's
possible that some command differ. Look at the settings of 'ssty'.
cw
cc Change the line.
c$ Change the text form the current position
to the end of a line.
C Same as 'c$'.
dd Delete the current line.
d$ Delete the remainder og the line.
D Same as 'd$'
4dd Delete 4 lines, replace the number with
you're choice.
dw Delete a whole word.
d} Delete the current paragraph.
d{ Delete the previous paragraph.
d^ Delete all
dL
dG Delete all from the possition to the EOF.
2dw Delete the next 2 words
Nice plug-insminibufferexplorerSee http://www.vim.org/scripts/script.php?script_id=159 SetupCopy the plug-in in your Usage# There are 3 different keybindins for the same result # To change of buffer, then we can press tab or move # with up, down, left, right ctrl+W ctrl+w k ctrl+w w # Or with the mouse enabled, we can double click on a buffer pydictionPython auto completion feature Really good! You can easy add some more syntax highlighting. See http://www.vim.org/scripts/script.php?script_id=850 Usage#Note: We use it in insert mode! ctrl+n complete next ctrl+p complete previous TaglistSee http://www.vim.org/scripts/script.php?script_id=273. SetupDownload the compressed file. Extract the compressed file. Copy Then the first time we use taglist, Usage:TlistToggle Open/close the taglist :help taglist For more help tagexplorerSee the website http://www.vim.org/scripts/script.php?script_id=483 for more informations. List files in a new screen. SetupDownload the stuff, place the file in Usage:TagExplorer Open/close the tag explorer
# In the TagExplorer
o on a selected file show/hidden all
functions/classes
+ on a selected file show all
funtions/classes
- To collapse
c To collapse
s Sort functions/classes
u Update the list of tags
g To select to jump to which directory
? To get all shortcute keys the options
We can select a funtion/classe in the TagExplore when
we have make use of the 'o' option and and show it on
on that possition in the file. Very useful!
When selecting a function/classe in the TagExplorer,
we can press the space bar to get the prototype of the
tag (the arguments options of the funtion/classe).
pydocEasy get informations of pydoc in vim. See website for more info. SetupGet the stuff, and place 'pydoc.vim' in Usage:Pydoc foo.bar.baz Split screen an show pydoc info
about foo.bar.baz
:Pydoc math Split screen and show pydoc math
:PydocSearch math Search all stuff concerning math
vimtipsShow tips each time you start vim. See http://www.vim.org/scripts/script.php?script_id=88 for more info. SetupGet the files. Extract the stuff. Move the content of the doc to Usage:TipOfTheDay Split screen an show the tip of the day. Other interesting pluginsResources
Comments leaved by users (total: 0)
Add a comment[ Toggle on/off history ] Item History:
|
|
||||||||||||||||||||||||||||||||