vim tuning

Some improvements to vim for usability.

if has("autocmd")
  au BufReadPost * if line("'"") > 1 && line("'"") <= line("$") | exe "normal! g`"" | endif
endif
set ts=4
set showcmd         " Show (partial) command in status line.
set showmatch       " Show matching brackets.
set ignorecase      " Do case insensitive matching
set incsearch       " Incremental search
set background=dark
syntax on
filetype plugin off   " Do not insert " and # marks after <CR> if it has before
" format .xml files by pressing F2
:map <F2> <Esc>:1,$!xmllint --format -<CR>
    cheat codes

           k
        h  +  l
           j

b – back one word
$ – to the end of line
0 – to the beginning of the line
: – jump to #line line
} – right one paragraph
{ – left one paragraph
Ctrl-F – forward one page
Ctrl-B – back one page
G – end of file

:18,24 del – delete from line 18 to line 24
:23,48 copy 17 – block from line 23 to 48 copy to line 17
:2,17 move 92 – block from line 2 to 17 move to line 92

Perform an external UNIX command on the range of lines superseded by “!”:
:11,16! sed -e “s/^/\/\*/” -e “s/$/\*\//”
(wraps a block of text with comments: /* text */.

:set list – show tabs, row ends

:ci”replace text between double quotes (:di” for delete, :ci( for brackets, etc.)
:ca” – same as above, but the quotes are included
:cit – the same as above but for text between html/xml tags (:cat – also can be used)

:s/foo/bar/g -> change each ‘foo’ to ‘bar’ in the current line
:%s/foo/bar/g -> change each ‘foo’ to ‘bar’ in all lines
:5,12s/foo/bar/g -> change each ‘foo’ to ‘bar’ for all lines from line 5 to line 12 inclusive
:.,$s/foo/bar/g -> change each ‘foo’ to ‘bar’ for all lines from the current line (.) to the last line ($) inclusive
:.,+2s/foo/bar/g -> change each ‘foo’ to ‘bar’ for the current line (.) and the two next lines (+2)
:g/^baz/s/foo/bar/g -> change each ‘foo’ to ‘bar’ in each line starting with ‘baz’

On replace:
g -> replace all
c -> ask for confirmation
I -> case sensitive

avatar

About tompos

Hungary, Budapest
This entry was posted in BSD, IT, Linux. Bookmark the permalink.

Leave a Reply