#vim
shift V
select line, up or down select linesshift >
shift select block or line outshift <
shift select block or line ind
to delete highlighted text and copy to cliboardD
delete everything after cursor to end of liney
to copy (yank)p
to paste after cursor,P
beforeu
undo last change.
repeat last command$ vim +linenumber file.c
open file and jump to that line numbergg
go to first line,GG
go to lastgt
go to next tab{i}gt
go to tab number{i}
:tabm
move current tab to last tab:tabm {i}
move current tab to position{i}
:tabs
list all tabs including their displayed windows:tabfirst
go to first tab:tablast
go to last tabU
convert SELECTED text to uppercase (alsogU
)u
convert SELECTED text to lowercase (alsogu
)~
toggle SELECTED text to opposiste case (alsog~
)control l
to refresh vim when changes happen (likegit pull
)- Use
*
to go to the definition of the word under the cursor - In NERDTree,
shift T
opens select file in new tab behind current - In NERDTree,
t
opens selected file in new tab :set syntax=php
or:set syntax=yaml
or:set syntax=perl
etc.:set nowrap
turn off word wrap:%s/$/',/
search the entire file%s
, find end of line$
and replace with',
s/' .*/'/
search the selection for'
if found, replace it and the rest of the line with'
%s/ ->\zs .*//
keep the arrow, delete all after arrow%s/ -> .*//
delete the arrow and everything aftervim scp://url/path/remote_file
edit remote file locally, saving to remote- Find this or that or blue
this\|that\|blue
- Sort selection alphabetically:
sort
, reversesort!
- Folding: in
.vimrc
addlet php_folding = 1
- Folding:
za
to toggle foldzA
to toggle all - If
command r
and loose arrow-key, thenctrl z
and typefg
on the command line d0
delete every thing before cursor in visual modectrl u
to delte every thing befor cursor in insert modee
reload current file:retab
set all tabs in current file to current settings. Good for files that used tabs, not spaces.:vertical resize 30
to resize the current window to exactly 30 characters wide.
%
create a new filed
create a new directoryR
rename the file/directory under the cursorD
Delete the file/directory under the cursor
To select a column, or even a block: In normal mode (press ESC
),
control v
- select column
shift I
- enter your comment syntax, like
#
- press
ESC
To delete a column:
control i
- select column
d
will delete (and copy to clipboard,p
to paste)
After copying (yanking) a block of text, can also select another block of text and paste over it. Similar to other editors gui's.
My basic .vimrc
file:
syntax on
set bs=2
set expandtab
set tabstop=2
set shiftwidth=2
set number
" extra
" remove white spaces at end of line
:nnoremap <silent> <F4> :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<CR>
" Format visually selected JSON
:vnoremap <F8> :!python -m json.tool<CR>