dotfiles

personal configuration files and scripts
git clone https://tongong.net/git/dotfiles.git
Log | Files | Refs | README

commit e7ed98db0e5f5b44fdeccaf1a7e55d6a5cbda098
parent ab1bc480e791dac336963030829f24fdee70d3ad
Author: tongong <tongong@gmx.net>
Date:   Sat, 26 Jun 2021 22:40:39 +0200

markdown, notes, autocmds, folding [nvim]

Diffstat:
Mconfig/dmenu/terminal | 2++
Aconfig/nvim/after/ftplugin/markdown.vim | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aconfig/nvim/after/syntax/markdown.vim | 5+++++
Mconfig/nvim/init.vim | 33++++++++++++++++++---------------
Aconfig/nvim/notes.vim | 31+++++++++++++++++++++++++++++++
Mconfig/nvim/restore-view.vim | 9++++++---
Mprofile | 5++++-
Ascripts/dnote | 9+++++++++
Ascripts/note | 2++
Ascripts/notes | 2++
Dscripts/wiki | 3---
Msuckless/dwm/config.h | 4++++
12 files changed, 139 insertions(+), 22 deletions(-)

diff --git a/config/dmenu/terminal b/config/dmenu/terminal @@ -11,3 +11,5 @@ pulsemixer wiki aerc fman +note +notes diff --git a/config/nvim/after/ftplugin/markdown.vim b/config/nvim/after/ftplugin/markdown.vim @@ -0,0 +1,56 @@ +" https://habamax.github.io/2019/03/07/vim-markdown-frontmatter.html +function! MarkdownFold() + let line = getline(v:lnum) + + " Regular headers + let depth = match(line, '\(^#\+\)\@<=\( .*$\)\@=') + if depth > 0 + return ">" . depth + endif + + " Setext style headings + " let prevline = getline(v:lnum - 1) + " let nextline = getline(v:lnum + 1) + " if (line =~ '^.\+$') && (nextline =~ '^=\+$') && (prevline =~ '^\s*$') + " return ">1" + " endif + + " if (line =~ '^.\+$') && (nextline =~ '^-\+$') && (prevline =~ '^\s*$') + " return ">2" + " endif + + " frontmatter + if (v:lnum == 1) && (line =~ '^----*$') + return ">1" + endif + + return "=" +endfunction + +setlocal foldmethod=expr +setlocal foldexpr=MarkdownFold() + +" fancy foldtext +function! MyFoldText() + let line = getline(v:foldstart) + + " markdown frontmatter -- just take the next line hoping it would be + " title: Your title + if line =~ '^----*$' + let line = getline(v:foldstart+1) + endif + + let indent = max([indent(v:foldstart)-v:foldlevel, 1]) + let lines = (v:foldend - v:foldstart + 1) + let strip_line = substitute(line, '^//\|=\+\|["#]\|/\*\|\*/\|{{{\d\=\|title:\s*', '', 'g') + let strip_line = substitute(strip_line, '^[[:space:]]*\|[[:space:]]*$', '', 'g') + let text = strpart(strip_line, 0, winwidth(0) - v:foldlevel - indent - 6 - strlen(lines)) + if strlen(strip_line) > strlen(text) + let text = text.'…' + endif + return repeat('#', v:foldlevel) . repeat(' ', indent) . text .' ('. lines .')' +endfunction +set foldtext=MyFoldText() + +" for markdown I prefer 2-wide tabs +setlocal tabstop=2 softtabstop=2 shiftwidth=2 diff --git a/config/nvim/after/syntax/markdown.vim b/config/nvim/after/syntax/markdown.vim @@ -0,0 +1,5 @@ +" https://habamax.github.io/2019/03/07/vim-markdown-frontmatter.html +" for pandoc YAML headers +unlet b:current_syntax +syntax include @Yaml syntax/yaml.vim +syntax region yamlFrontmatter start=/\%^---$/ end=/^---$/ keepend contains=@Yaml diff --git a/config/nvim/init.vim b/config/nvim/init.vim @@ -19,6 +19,7 @@ set colorcolumn=80 set signcolumn=yes set noshowmode " not needed because of lightline statusline set fillchars=eob:\ , +set conceallevel=2 " use persistent history. " -> these are reset for /dev/shm to keep pass secure (see #autocommands) @@ -56,7 +57,6 @@ Plug 'junegunn/goyo.vim' Plug 'mbbill/undotree' Plug 'tpope/vim-commentary' Plug 'tpope/vim-fugitive' -Plug 'vimwiki/vimwiki' call plug#end() @@ -69,10 +69,6 @@ colorscheme dim " statusbar let g:lightline = { 'colorscheme': 'dim', } -" vimwiki -let g:vimwiki_list = [{'path': $VIMWIKI_DIR, - \ 'syntax': 'markdown', 'ext': '.md'}] - " spell check toggle let g:myLangList = ["nospell", "de_de", "en_us"] function! ToggleSpell() @@ -107,6 +103,9 @@ let g:repl_config = { \ } \ } +let g:notes_dir = $NOTES_DIR +source $HOME/.config/nvim/notes.vim + "### REMAPS ################################################################ let mapleader = " " @@ -152,6 +151,9 @@ nmap <Leader>io <Plug>(GitGutterNextHunk) " exit terminal mode tnoremap <Esc> <Esc><C-\><C-n> +" why would you use gf instead of gF? +nmap gf gF + " I always get these wrong command! W w command! Wq wq @@ -188,20 +190,21 @@ endfun set viewoptions=cursor,folds,slash,unix source $HOME/.config/nvim/restore-view.vim -augroup SOME_NAME +augroup main autocmd! - autocmd BufWritePre * call TrimWhitespace() + autocmd BufWritePre * call TrimWhitespace() + autocmd BufEnter * call InitToggleSpell() " clear colon commands - autocmd CmdlineLeave : echo '' - " fix weird markdown bug - autocmd BufEnter *.md setl syntax=markdown - autocmd BufEnter *.remark setl syntax=markdown - autocmd BufEnter * call InitToggleSpell() + autocmd CmdlineLeave : echo '' + + " filetypes + autocmd BufRead,BufNewFile *.md setlocal filetype=markdown + autocmd BufEnter *.remark setlocal syntax=markdown " do not keep history for pass - autocmd BufEnter /dev/shm/* setl undofile& + autocmd BufEnter /dev/shm/* setlocal undofile& " Don't screw up folds when inserting text that might affect them, until " leaving insert mode. Foldmethod is local to the window. - autocmd InsertEnter * let w:last_fdm=&foldmethod | setlocal foldmethod=manual - autocmd InsertLeave * let &l:foldmethod=w:last_fdm + autocmd InsertEnter * let w:last_fdm=&foldmethod | setlocal foldmethod=manual + autocmd InsertLeave * let &l:foldmethod=w:last_fdm augroup END diff --git a/config/nvim/notes.vim b/config/nvim/notes.vim @@ -0,0 +1,31 @@ +function OpenNotesDir() + exe "e " . g:notes_dir . "/refile.md" +endfunction + +function NewNote() + call OpenNotesDir() + call feedkeys("Go- ") +endfunction + +function NewAnnotation() + let location = expand("%:p") . ":" . line(".") + call OpenNotesDir() + call feedkeys("Go- [" . location . "]\<esc>0la") +endfunction + +nmap gN :call OpenNotesDir()<CR> +nmap gM :call NewNote()<CR> +nmap gA :call NewAnnotation()<CR> + + +function InitNotesFile() + " echomsg "loaded notes buffer" + " it is super annoying that you cant set the cwd per buffer + " and this is a really bad fix + exe "nnoremap <buffer> <leader>f :Files " . g:notes_dir . "<CR>" +endfunction + +augroup notes + autocmd! + exe "au BufEnter " . g:notes_dir . "/* call InitNotesFile()" +augroup END diff --git a/config/nvim/restore-view.vim b/config/nvim/restore-view.vim @@ -2,7 +2,7 @@ " Language: vim script " Maintainer: Yichao Zhou (broken.zhou AT gmail dot com) " Version: 1.3 -" Description: +" Description: " This is a simple script to autosave cursor position and fold " information using vim's mkview. Although you can easily do this job by " just add serveral line to {.,_}vimrc, write a script plugin can make it @@ -14,7 +14,7 @@ " Suggested Setting: " Please put them in you vimrc file. " set viewoptions=cursor,folds,slash,unix -" +" " Set it in a plugin file looks dirty to me. So you'd better do it your " self. This only keywords not in viewoptions is "options". I believe it " does not belong to a view. If you think you need it, feel free to @@ -58,5 +58,8 @@ augroup AutoView autocmd! " Autosave & Load Views. autocmd BufWritePre,BufWinLeave ?* if MakeViewCheck() | silent! mkview | endif - autocmd BufWinEnter ?* if MakeViewCheck() | silent! loadview | endif + " the loadview could change foldmethod. in this case foldmethod is + " correctly reset using filetype rules + " for the lightline part see https://github.com/itchyny/lightline.vim/issues/484 + autocmd BufWinEnter ?* if MakeViewCheck() | silent! loadview | let &l:filetype = &l:filetype | call lightline#update() | endif augroup END diff --git a/profile b/profile @@ -27,13 +27,16 @@ export MANWIDTH=80 # load private environment variables (not tracked in git) . "$HOME/.profile-private" +# notes +# export NOTES_DIR=[private] + # set pass directory # export PASSWORD_STORE_DIR=[private] # diary settings # export DIARY_KEYID=[private] -export DIARY_EDITOR=nvim # export DIARY_DIRECTORY=[private] +export DIARY_EDITOR=nvim export DIARY_READER=less # autostart X at login diff --git a/scripts/dnote b/scripts/dnote @@ -0,0 +1,9 @@ +#!/usr/bin/env sh +while : +do + note="$(echo -n "" | dmenu -p "new note:")" + + [[ -z $note ]] && exit + + echo "- $note" >> $NOTES_DIR/refile.md +done diff --git a/scripts/note b/scripts/note @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +nvim -c ":call NewNote()" diff --git a/scripts/notes b/scripts/notes @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +nvim -c ":call OpenNotesDir()" diff --git a/scripts/wiki b/scripts/wiki @@ -1,3 +0,0 @@ -#!/usr/bin/env sh -# vimwiki alias -nvim -c :VimwikiIndex diff --git a/suckless/dwm/config.h b/suckless/dwm/config.h @@ -99,6 +99,8 @@ static const char *passmenucmd[] = { "passmenu-plus", "--type", "-l", "10", NUL static const char *settingscmd[] = { "dmenu-settings", NULL }; static const char *notificationcmd[] = { "st", "-e", "less", "/tmp/notification-list", NULL }; static const char *pausemusiccmd[] = { "playerctl", "play-pause", NULL }; +static const char *notescmd[] = { "st", "-e", "notes", NULL }; +static const char *newnotecmd[] = { "dnote", NULL }; static Key keys[] = { /* modifier key function argument */ @@ -121,6 +123,8 @@ static Key keys[] = { { MODKEY|ShiftMask, XK_d, spawn, {.v = passmenucmd } }, { MODKEY, XK_s, spawn, {.v = settingscmd } }, { MODKEY, XK_m, spawn, {.v = pausemusiccmd } }, + { MODKEY, XK_g, spawn, {.v = notescmd } }, + { MODKEY|ShiftMask, XK_g, spawn, {.v = newnotecmd } }, // run keepass global auto type (configured through keepass) //MODKEY|ShiftMask, XK_t // Rotate focus through windows