From 5ada6ec04205ff6acb18106eb3df870a2a167695 Mon Sep 17 00:00:00 2001 From: plrectco Date: Mon, 9 Dec 2019 16:46:33 -0800 Subject: [PATCH] auto build command copy to clipboard --- vimrcs/google.vim | 49 ++++++++++++++++++++++++++++++++------- vimrcs/plugins_config.vim | 26 --------------------- 2 files changed, 41 insertions(+), 34 deletions(-) diff --git a/vimrcs/google.vim b/vimrcs/google.vim index 7f30804f..3a086505 100644 --- a/vimrcs/google.vim +++ b/vimrcs/google.vim @@ -89,10 +89,6 @@ function GetGoogle3Path(filepath, clientpath) endif endfunction -function PathNameFilterHelper(key, val) - let l:idx = strridx() -endfunction - function GoogleECompletion(ArgLead, CmdLine, CursorPos) let l:citc = GetCitCPath() let l:filepath = GetGoogle3Path(a:ArgLead, l:citc) @@ -138,9 +134,46 @@ execute 'CommandCabbr e GoogleE' " Play the macro in register q. nnoremap . @q -" FromProto -let @f = "ywidata.\wwi = proto.\pa()\jb" -" ToProto -let @t = "ywiif (proto->\wwi() != data.\pa) {\\}\kAproto->\pbdwaset_\pa(data.\pa);\jxj" + +" Class Access Operator toggle +" Only work if current char under the cursor is either . or -> +function ClassAccessOperatorToggle() + " Col number starts at 1 while string index starts at 0. + let cur_char = matchstr(getline('.'), '\%' . col('.') . 'c.') + " == does not match case, but it is sufficient here. ==# match cases. For more :help expr-< + " To do replace . with -> or replace -> with . + let line = line(".") + if cur_char == '.' + execute line . "," . line . "s/\\./->/" + endif + if cur_char == '-' || cur_char == '>' + execute line . "," . line . "s/->/./" + endif +endfunction + +command ClassAccessOperatorToggle call ClassAccessOperatorToggle() +nnoremap ,p :ClassAccessOperatorToggle + +" Copy the buildable command of the current file to clipboard. +" If the current file is a/b/c/d/k.h +" Copy 'blaze build a/b/c/d:k' to clipboard. +function! GetCurrentFileBuildCmd() + " citc:filepath + let path = GetSmartFilePath() + let subs = split(path, ':') + + let file = expand('%:p:t') + " Need to escapte the dot. + let file_subs = split(file, '\.') + if len(subs) > 1 && len(file_subs) > 0 + let output = 'blaze build ' . subs[1] . ':' . file_subs[0] + " Copy to secondary clipboard, ctrl+c/v + echom l:output + let @+ = l:output + endif +endfunction + + + diff --git a/vimrcs/plugins_config.vim b/vimrcs/plugins_config.vim index 14b688b8..5f90cef7 100644 --- a/vimrcs/plugins_config.vim +++ b/vimrcs/plugins_config.vim @@ -141,32 +141,6 @@ let g:lightline = { \ 'subseparator': { 'left': ' ', 'right': ' ' } \ } -function! GetSmartFilePath() - let path = expand('%:p:h') - " If in google3 path, display the client name and the absolute path - if matchstr(path, 'google3') == 'google3' - let output = '' - let subs = split(path, '/') - let add_to_output = 0 - let prev_s = '' - for s in subs - if add_to_output == 1 - let output .= '/' - let output .= s - endif - if s == 'google3' - let output .= prev_s - let output .= ':' - let add_to_output = 1 - endif - let prev_s = s - endfor - return output - else - return path - endif -endfunction - """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Vimroom """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""