From f90c93a19b96584d2eccfff0e053019893e8c132 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Mon, 30 Oct 2017 13:01:10 +0100 Subject: [PATCH 1/2] Several quickfix and location list related things * Moved general utilities block * Added MatchingLinesDict function Works like MatchingLines, but returns a dictionary compatible with setqflist() and setloclist() * Added [Q|L]add[line|cursor] commands * Added LFind and QFind commands --- vimrc | 56 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/vimrc b/vimrc index 35fc4db..759c3fd 100644 --- a/vimrc +++ b/vimrc @@ -87,11 +87,52 @@ noremap d "_d noremap x "_x noremap x x +" === GENERAL UTILITIES === +function! MatchingLines(pattern) + let list = [] + let pattern = a:pattern + exec "g/".pattern."/ call add(list, expand('%').'('.line('.').') : '.matchstr(getline('.'), '".pattern."'))" + return list +endfunc + +function! s:mld_helper(list, pattern) + " Helper function for MatchingLinesDict + call add(a:list, {'filename': expand("%"), 'lnum': line("."), 'col': match(getline("."), a:pattern)+1, 'text': matchstr(getline("."), a:pattern)}) +endfunc +function! MatchingLinesDict(pattern) + let list = [] + silent! exec "g/".a:pattern."/ call s:mld_helper(list, a:pattern)" + return list +endfunc + +function! LocationAddLineCol(filename, lnum, text, col) + call setloclist(0, [{'filename': a:filename, 'lnum': a:lnum, 'desc': a:text, 'col': a:col}], 'a') +endfunction + +function! QuickfixAddLineCol(filename, lnum, text, col) + call setqflist([{'filename': a:filename, 'lnum': a:lnum, 'desc': a:text, 'col': a:col}], 'a') +endfunction + +function! LocationAddLine(filename, lnum, text) + call setloclist(0, [{'filename': a:filename, 'lnum': a:lnum, 'desc': a:text}], 'a') +endfunction + +function! QuickfixAddLine(filename, lnum, text) + call setqflist([{'filename': a:filename, 'lnum': a:lnum, 'desc': a:text}], 'a') +endfunction + " === GENERAL COMMANDS === command! L lopen | set number | set norelativenumber +command! LAddLine call LocationAddLine(expand("%"), line("."), getline(".")) +command! QAddLine call QuickfixAddLine(expand("%"), line("."), getline(".")) +command! LAddCursor call LocationAddLineCol(expand("%"), line("."), getline("."), col(".")) +command! QAddCursor call QuickfixAddLineCol(expand("%"), line("."), getline("."), col(".")) -command! Fixme cex MatchingLines("\\cfixme.*") -command! Todo cex MatchingLines("\\ctodo.*") +command! Fixme lex MatchingLines("\\c\\)) +command! -nargs=1 QFind call setqflist(MatchingLinesDict()) " === GENERAL KEY MAPPINGS === let mapleader = "\\" @@ -165,14 +206,6 @@ digraph oe 246 digraph OE 214 digraph ss 223 -" === GENERAL UTILITIES === -function! MatchingLines(pattern) - let list = [] - let pattern = a:pattern - exec "g/".pattern."/ call add(list, expand('%').'('.line('.').') : '.matchstr(getline('.'), '".pattern."'))" - return list -endfunc - " === GENERAL AUTOCOMMANDS === nnoremap h :call toggleWUC() @@ -323,6 +356,7 @@ function! s:init_vim_file() command! -buffer Functions lex MatchingLines("^\\s*fun\\(ction\\)\\?\\>!.*$") command! -buffer Commands lex MatchingLines("^\\s*com\\(mand\\)\\?\\>!.*$") + command! -buffer Autocommands lex MatchingLines("^\\s*au\\(tocmd\\)\\?\\>!\\@!.*$") endfunction " --- C / C++ Stuff --- @@ -374,5 +408,5 @@ autocmd! au BufWritePre *.rb :retab au BufWritepost *.rb :set noexpandtab - au BufWritepost *.rb :retab! + au BufWritepost *.rb :silent! :undo augroup END From 30a6db56ee90e88485940fe789d8159289f092c9 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Mon, 30 Oct 2017 15:50:14 +0100 Subject: [PATCH 2/2] Added HTML stuff * Improved ruby find commands to not include keywords like "def" and "class" * Saving now jumps back to last position after undoing retab in ruby files * Added HTML block * Added HTML mappings to expand word under cursor to opening and closing tag --- vimrc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/vimrc b/vimrc index 759c3fd..112dc4e 100644 --- a/vimrc +++ b/vimrc @@ -372,11 +372,11 @@ au BufNewFile,BufRead *.c,*.cpp,*.h,*.hpp :nnoremap ; m'$a;`' au BufNewFile,BufRead *.rb :call init_ruby_file() function! s:init_ruby_file() - command! -buffer Defines lex MatchingLines("^\\s*def\\>.*$") + command! -buffer Defines lex MatchingLines("^\\s*def\\>\\s\\+\\zs.*$") command! -buffer Functions Defines " Alias command! -buffer Methods Defines " Alias - command! -buffer Classes lex MatchingLines("^\\s*class\\>.*$") - command! -buffer Modules lex MatchingLines("^\\s*module\\>.*$") + command! -buffer Classes lex MatchingLines("^\\s*class\\>\\s\\+\\zs.*$") + command! -buffer Modules lex MatchingLines("^\\s*module\\>\\s\\+\\zs.*$") nnoremap ic oclass m'end`'a nnoremap id odef m'()end`'a @@ -399,7 +399,7 @@ function! s:RubyComment(a) endfunction augroup rbindent -autocmd! + autocmd! au BufNewFile,BufRead *.rb :set noexpandtab au BufNewFile,BufRead *.rb :retab! @@ -408,5 +408,18 @@ autocmd! au BufWritePre *.rb :retab au BufWritepost *.rb :set noexpandtab - au BufWritepost *.rb :silent! :undo + au BufWritepost *.rb :silent! :undo :normal augroup END + +" --- HTML Stuff --- +au BufNewFile,BufRead *.html,*.htm :call init_html_file() + +function! s:init_html_file() + command! -buffer -nargs=1 Tag normal + \ i<><m'/>`' + nnoremap t ""ciw<""p>m'""p>`'l + nnoremap T ""diw"_cc<""p>o""p>O + + inoremap ""ciw<""p>m'""p>`'l + inoremap ""diw"_cc<""p>o""p>O +endfunction