VIM: Handle Urls

Making a shortcut to open urls under cursor Note: There is also available gx shortcut that uses netrw plugin. But I’ve decided to use own little solution instead of big plugin for one function. """ open urls using \u shortcut function HandleURL() let l:uri = matchstr(getline("."), '[a-z]*:\/\/[^ >,;)]*') if l:uri != "" silent call system("xdg-open " . shellescape(l:uri, 1)) else echo "No URI found in line." endif endfunction nnoremap <leader>u :call HandleURL()<cr> """ Now if we hit \u shortcut while our cursor is on the url line, this url will be opened in default browser....

October 15, 2020

VIM: Making Markdown Checklist Shortcut

Interesting exercise to implement shortcut in vim. Often while writing markdown files in vim I’m writing a lot of checkboxes. It’s a bit annoying to do by hand so let’s make a script and bind it to shortcut. """ markdown shortcuts function MarkdownCheckboxInsert() let l:line = line('.') let l:str = getline(l:line) let l:match = matchlist(l:str, '^\([ ]*\)\?\([-+*]\)\? \?\(.*\)$') if empty(l:match[2]) let l:list_syn = '-' else let l:list_syn = l:match[2] endif let l:buf = l:match[1] ....

October 14, 2020

VIM: YCM and Pipenv

While writing another python script under pipenv I have met a problem that YCM autocomplete worked only for built in functions. That was annoying because without autocomplete YCM looses it’s sense. Solution Let’s create module for filetype plugin. cat ~/.vim/after/ftplugin/python.vim if !empty($VIRTUAL_ENV) let g:ycm_server_python_interpreter = $VIRTUAL_ENV . '/bin/python' let $PYTHONPATH = finddir('site-packages', $VIRTUAL_ENV . '/lib/*') endif Then you can simply run command pipenv run vim some/script.py And now YCM works correctly :3

October 14, 2020

VIM: Append Filetype

If you open a file with a non-standard extension, syntax highlighting will not work. This is easily solved by installing filetype manually. :set filetype=markdown You can add a hint for VIM about the file type to the file so that you don’t have to set the type manually the next time. ~ cat Readme # vi:syntax=markdown I wanted to make a hotkey to add information about its type to the end of the file....

June 6, 2020

VIM: File Autosave

I was wondering how to save file in VIM automatically. Found some solutions in internet but decided to do it my way. So I wrote this small solution: """ Save file on each edit exit function FileAutoSave() if exists('g:file_autosave_async') return endif if @% == "" return elseif !filewritable(@%) return endif let g:file_autosave_async = 1 call timer_start(500, 'FileAutoSaveAsync', {'repeat': 1}) endfunction function FileAutoSaveAsync(timer) update unlet g:file_autosave_async endfunction :autocmd InsertLeave,TextChanged * call FileAutoSave() """ It updates file in two cases:...

June 2, 2020