Vimnotes
From KallestadWiki
[edit]
Notes on VIM
Trying to get better with using VIM - to see if it might actually replace my preferred editor of choice UltraEdit32. Not that I see anything wrong with ultraedit - it's something I recommend and would still recommend to everyone. VIM/vi is a pain to work with sometimes, but as you learn the keymappings and create your own it can be an invaluable timesaver for those of us doing development work.
- commands I did not know about
e end of the current word w start of next word de delete until the end of the current word dw delete until the start of the next word dj delete the current line and the line below * find the next instance of the word under the cursor # same for previous 0 or ^ start of the line (knew these, never remember to use them) u undo - yep I've been living without undo for years. It's surprising how little this comes up when you get used to not having it. U undo changes to the whole line. ctrl+r redo p put the deleted text below the cursor. ce correct the word - deletes to the end of the word and puts you in insert mode (really c works like delete where you can use numbers and motion. G move to the end of a file. Oh how long I needed this command! gg to go to the start. or :0 % moves you back and forth within a matching ),],} :s/old/new/g - replace all instances in a line. I always have to look this one up :%s/old/new/g - replace all instances of old with new in an entire file. :%s/old/new/gc - replace, but prompt ! execute a command (like ls -lh) v visual selection. (select and :w file to write selection to file) r !command - take the output of a command and insert it in the current file o,O insert line below or abOve the cursor, move there, and insert
- folding perl routines
set perl_fold=1 doesn't seem as friendly as this function for ~/.vimrc:
function GetPerlFold()
if getline(v:lnum) =~ '^\s*sub\s'
return ">1"
elseif getline(v:lnum) =~ '\}\s*$'
let my_perlnum = v:lnum
let my_perlmax = line("$")
while (1)
let my_perlnum = my_perlnum + 1
if my_perlnum > my_perlmax
return "<1"
endif
let my_perldata = getline(my_perlnum)
if my_perldata =~ '^\s*\(\#.*\)\?$'
" do nothing
elseif my_perldata =~ '^\s*sub\s'
return "<1"
else
return "="
endif
endwhile
else
return "="
endif
endfunction
setlocal foldexpr=GetPerlFold()
setlocal foldmethod=expr
- perl block commenting (download. goes in ~/.vim/plugins/ maps .c to comment block, .C to uncomment)
- color schems - here's the global sample pack - read the page.
:colorscheme schemename to change schemes
add something like this to ~/.vimrc to permanently choose one
colorscheme fred
- numbering - add the following to .vimrc or run it in command mode to see numbers
set number
to turn it off
set nonumber
- text completion ctrl+n / ctrl+p
You can use ctags files (man ctags)
- Perl compiler
in .vimrc:
autocmd BufNewFile,BufRead *.p? compiler perl
now just run
:make
to test for errors in your perl code
- search highlighting
put this in ~/.vimrc to map F4 to toggle search highlighting
map <F4> :set hls!<CR>:set hls?<CR>
