diff --git a/home/dot_vimrc b/home/dot_vimrc index 231d1cd2..9e9e3b0c 100644 --- a/home/dot_vimrc +++ b/home/dot_vimrc @@ -67,14 +67,19 @@ map e :Ex " open explorer " marks """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" automatically update marks with helper function +au CursorHold,CursorHoldI,CursorMoved,CursorMovedI,TextChanged,TextChangedP,CmdlineEnter,CmdlineLeave,CmdlineChanged * silent! call UpdateMarkSigns() + " allow only global marks noremap ' "'".toupper(nr2char(getchar())) noremap m "m".toupper(nr2char(getchar())) sunmap ' sunmap m -nnoremap ' :call ListSelect("marks", "'") " list jumps/marks -map md :delmarks A-Z0-9 " clear marks +" list jumps/marks +map mm :call ListSelect("marks", "'") +" clear marks +map md :delmarks A-Z0-9 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " grep @@ -167,3 +172,56 @@ endfunction function! Grep(...) return system(join([&grepprg] + [expandcmd(join(a:000, ' '))], ' ')) endfunction + +" Check if file is valid and exists +" ChatGippity +" +function! IsValidFilename(filename) + let expanded_filename = expand(a:filename) + if !empty(expanded_filename) && filereadable(expanded_filename) + return 1 + else + return 0 + endif +endfunction + +function! PlaceSign(id, symbol, prio, line_number) + call sign_define(a:symbol, {'text': a:symbol}) + call sign_place(a:id, '', a:symbol, bufnr(''), {'lnum': a:line_number, 'priority': a:prio, 'text': a:symbol}) +endfunction + +function! UpdateMarkSigns() + " Reserved unique IDs for marks in case we want to remove in future + " without wiping out all signs + let resvIDs = range(1000, 1027) + + " wipe out all signs (might improve in future) + execute "sign unplace *" + + " get all marks + let lines = [] + redir => lines + silent marks + redir END + + let lines = split(lines, "\n")[1:] + for i in range(len(lines)) + let line = lines[i] + let id = resvIDs[i] + + let splitLine = split(line) + let name = splitLine[0] + let row = splitLine[1] + let col = splitLine[2] + try " empty lines at marks will break things + let file = splitLine[3] + catch + let file = "" + endtry + + " If marks is in another file we don't need to display it + if !IsValidFilename(file) + call PlaceSign(id, name, 99, row) + endif + endfor +endfunction