diff --git a/vimrc b/vimrc index 25ec1e5..c59ae8b 100644 --- a/vimrc +++ b/vimrc @@ -87,8 +87,12 @@ noremap d "_d noremap x "_x noremap x x +" === GENERAL COMMANDS === +command! L lopen | set number | set norelativenumber + " === GENERAL KEY MAPPINGS === let mapleader = "\\" +nnoremap :L noremap : noremap @: noremap Q @q @@ -159,7 +163,7 @@ digraph OE 214 digraph ss 223 " === GENERAL UTILITIES === -function! Matchinglines(pattern) +function! MatchingLines(pattern) let list = [] let pattern = a:pattern exec "g/".pattern."/ call add(list, expand('%').'('.line('.').') : '.matchstr(getline('.'), '".pattern."'))" @@ -284,9 +288,16 @@ endif " === FILETYPE SPECIFIC STUFF === " Vimscript Stuff -au BufNewFile,BufRead *.vim,*vimrc :nnoremap :so % -au BufNewFile,BufRead *.vim,*vimrc :nnoremap c A" -au BufNewFile,BufRead *.vim,*vimrc :nnoremap if ofunction! m'()endfunction`'l +au BufNewFile,BufRead *.vim,*vimrc :call init_vim_file() + +function! s:init_vim_file() + nnoremap :so % + nnoremap c A" + nnoremap if ofunction! m'()endfunction`'l + + command! -buffer Functions lex MatchingLines("^\\s*fun\\(ction\\)\\?\\>!.*$") + command! -buffer Commands lex MatchingLines("^\\s*com\\(mand\\)\\?\\>!.*$") +endfunction " --- C / C++ Stuff --- @@ -298,21 +309,27 @@ au BufNewFile,BufRead *.c,*.cpp,*.h,*.hpp :nnoremap im oint mai au BufNewFile,BufRead *.c,*.cpp,*.h,*.hpp :nnoremap ; m'$a;`' " --- Ruby Stuff --- -" Insert Stuff -au BufNewFile,BufRead *.rb :command! -buffer Defines lex Matchinglines("^\\s\\+def\\>") -au BufNewFile,BufRead *.rb :command! -buffer Classes lex Matchinglines("^\\s\\+class\\>") -au BufNewFile,BufRead *.rb :command! -buffer Modules lex Matchinglines("^\\s\\+module\\>") -au BufNewFile,BufRead *.rb :nnoremap ic oclass m'end`'a -au BufNewFile,BufRead *.rb :nnoremap id odef m'()end`'a -" Other Stuff -au BufNewFile,BufRead *.rb setl expandtab -au BufNewFile,BufRead *.rb nnoremap :w:!ruby % -au BufNewFile,BufRead *.rb nnoremap :w:!ruby -wc % +au BufNewFile,BufRead *.rb :call init_ruby_file() + +function! s:init_ruby_file() + command! -buffer Defines lex MatchingLines("^\\s*def\\>.*$") + command! -buffer Functions Defines " Alias + command! -buffer Methods Defines " Alias + command! -buffer Classes lex MatchingLines("^\\s*class\\>.*$") + command! -buffer Modules lex MatchingLines("^\\s*module\\>.*$") + + nnoremap ic oclass m'end`'a + nnoremap id odef m'()end`'a + + setl expandtab + nnoremap :w:!ruby % + nnoremap :w:!ruby -wc % + nnoremap ~ :call RubyComment(0) + nnoremap # :call RubyComment(1) + vnoremap ~ :call RubyComment(0) + vnoremap # :call RubyComment(1) +endfunction -au BufNewFile,BufRead *.rb :nnoremap C :call RubyComment(0) -au BufNewFile,BufRead *.rb :nnoremap c :call RubyComment(1) -au BufNewFile,BufRead *.rb :vnoremap C :call RubyComment(0) -au BufNewFile,BufRead *.rb :vnoremap c :call RubyComment(1) function! s:RubyComment(a) if a:a==0 silent! exec '.s/\m^\s*\zs#*//'