Help
- :help - vim help
- :help commandname - help on a particular command
- CTRL+] - jump to a highlighted topic
- CTRL+T - jump backwards
Motion
- :help left-right-motion
- j,k move up down
- h,l move left right
- b,w move previous or next word
- ctrl+b, ctrl+d move page up or page down
Undo redo
u
: undo last change (can be repeated to undo preceding commands)Ctrl-R
: Redo changes which were undone (undo the undos).- Compare to '
.
' to repeat a previous change, at the current cursor position. Ctrl-R will redo a previously undone change, wherever the change occurred.
Switch between navigation and editing mode
- A - move to the end of the line and switch to editing mode
- I - switch to editing mode at the current place
- Escape - switch to navigation mode
- alt+h alt+j alt+k alt+l - switch to navigation mode and move
- alt+: - switch to navigation mode and send a command
Search and replace characters
"/" to search, then n forward and N backwards
"*" to search for the word under the cursor (you can also create a mapping to search for a selected text)
Vim wiki on search and replace
:s/foo/bar/g
Find each occurrence of 'foo' (in the current line only), and replace it with 'bar'.-
:%s/foo/bar/g
Find each occurrence of 'foo' (in all lines), and replace it with 'bar'.
- %s/option value=".*"//g remove all beginnings of line. :%s/\option\n/, /g replace all end of line by comma + space. This cleans an html list of species for inclusion in a text.
Markdown
Display a list of first level header in a markdown document (found in quick markdown navigation/TOC)
:g/^# /#
Then enter the line number to jump to that line.Line numbers
Display line numbersDisable line numbers:set nu
:set nonu
Editing a whole line
- dd to delete a whole line
- yy to copy a whole line
- p to paste the copied or deleted text after the current line or
- P to paste the copied or deleted text before the current line
Copy, cut and paste
- Position the cursor where you want to begin cutting.
- Press v (or upper case V if you want to cut whole lines).
- Move the cursor to the end of what you want to cut.
- Press d to cut or y to copy.
- Move to where you would like to paste.
- Press P to paste before the cursor, or p to paste after.
Indentation
Indentation replaced by spaces, add this to the ~/.vimrc file
More details on vim indentation in the python wiki.set tabstop=4 set expandtab set softtabstop=4 set shiftwidth=4 filetype indent on
Multiple files and windows
- :e filename - edit another file
- :ls - show current buffers
- :b 2 - open buffer #2 in this window
- :b filename - open buffer #filename in this window
- :bd - close the current buffer (! to forget changes)
- :bd filename -close a buffer by name
Windows
- :sp[lit] filename - split window and load another file
- :vs[plit] - same but split vertically
- ctrl-w up arrow - move cursor up a window
- ctrl-w ctrl-w - move cursor to another window (cycle)
- ctrl-w_ - maximize current window
- ctrl-w= - make all equal size
- CTRL+z - suspend the process and get back to the shell
- fg - get back to vim
Vimdiff
View differences between file1 and file2 (vim documentation)vimdiff file1 file2
spell check
Set spell check only in the local buffer::setlocal spell spelllang=en_gbTurn spell check off
:set nospell
Mark word as correct, this creates a spell file under /home/user/.vim/spell:
zgMark word as incorrect
zw
Plugins for programming languages
- Vim R
- Vim on Python wiki (set softtabstop=4) or your python development environment (set tabstop=4 and set softtabstop=4)
.vimrc
Text colour.Add syntax highlight to your .vimrc
syntax enableHow to add a file extension to vim syntax highlight
au BufNewFile,BufRead *.dump set filetype=sqlI used it to display markdown files as text files:
au BufNewFile,BufRead *.md set filetype=txt
No comments:
Post a Comment