Browse Source

initial commit

dev
ihsan 9 months ago
commit
7ad9f9ccb8
5 changed files with 199 additions and 0 deletions
  1. +21
    -0
      LICENSE
  2. +34
    -0
      README.md
  3. +36
    -0
      doc/neuron.vim.txt
  4. +5
    -0
      doc/tags
  5. +103
    -0
      plugin/vim-neuron.vim

+ 21
- 0
LICENSE View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 ihsan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

+ 34
- 0
README.md View File

@ -0,0 +1,34 @@
# neuron.vim
Manage your Zettelkasten with the help of
[neuron](https://github.com/srid/neuron) in {n}vim.
## Requirements
- [neuron](https://github.com/srid/neuron)
- [fzf](https://github.com/junegunn/fzf.vim)
- [ripgrep](https://github.com/BurntSushi/ripgrep)
## Installation
### Using [vim-plug](https://github.com/junegunn/vim-plug)
add following to your ~/.vimrc
requirements:
```vim
Plug 'junegunn/fzf.vim'
Plug 'BurntSushi/ripgrep'
```
actual plugin:
```vim
Plug 'ihsanturk/neuron.vim'
```
## Mappings
```vim
nm <m-z> :call ZettelSearch()<cr>
nm <LocalLeader>zn :call ZettelNew()<cr>
nm <LocalLeader>zi :call ZettelSearchInsert()<cr>
nm <LocalLeader>zl :call ZettelLastInsert()<cr>
nm <LocalLeader>zo :call ZettelOpenUnderCursor()<cr>
nm <LocalLeader>zu :call ZettelOpenLast()<cr>
```

+ 36
- 0
doc/neuron.vim.txt View File

@ -0,0 +1,36 @@
*neuron.vim.txt* Manage your Zettelkasten.
Author: ihsan <https://ihsanturk.dev/>
INTRODUCTION *neuron.vim*
neuron.vim manages your zettelkasten. You can search, create and open your
zettels using fzf, ripgrep and neuron under the hood.
CONFIGURATION *neuron.vim-configuration*
g:zkdir Zettelkasten directory.
Default: >
${HOME}/zettelkasten
g:fzf_options All fzf commands are uses these options. For example
you can change the prompt
Default: >
let g:fzf_options = '-d"title: " --with-nth 2 --prompt "Zettelkasten: "'
MAPPINGS *neuron.vim-mappings*
>
nm <m-z> :call ZettelSearch()<cr>
nm <LocalLeader>zn :call ZettelNew()<cr>
nm <LocalLeader>zi :call ZettelSearchInsert()<cr>
nm <LocalLeader>zl :call ZettelLastInsert()<cr>
nm <LocalLeader>zo :call ZettelOpenUnderCursor()<cr>
nm <LocalLeader>zu :call ZettelOpenLast()<cr>
ABOUT *neuron.vim-about*
http://github.com/ihsanturk/neuron.vim
vim:tw=78:et:ft=help:norl:

+ 5
- 0
doc/tags View File

@ -0,0 +1,5 @@
neuron.vim neuron.vim.txt /*neuron.vim*
neuron.vim.txt neuron.vim.txt /*neuron.vim.txt*
neuron.vim-about neuron.vim.txt /*neuron.vim-about*
neuron.vim-mappings neuron.vim.txt /*neuron.vim-mappings*
neuron.vim-configuration neuron.vim.txt /*neuron.vim-configuration*

+ 103
- 0
plugin/vim-neuron.vim View File

@ -0,0 +1,103 @@
" =============================================================================
" File: vim-neuron.vim
" Description: Take zettelkasten notes using neuron in Vim.
" Author: ihsan <ihsanl at pm dot me>
" Created At: 1590326456
" License: MIT License
" =============================================================================
let g:zkdir = '${HOME}/zettelkasten/'
let g:zexte = '.md'
let g:fzf_options = '-d"title: " --with-nth 2 --prompt "Zettelkasten: "'
" Prototypes {{{1
" Functions {{{2
" [ ] ZettelSearch -> Opens selected.
" [X] ZettelLastInsert -> Insert last edited.
" [X] ZettelSearchInsert -> Insert selected.
" [X] ZettelNew -> Open & startinsert title.
" [X] ZettelSearchTitles -> Opens selected.
" [X] ZettelOpen(zettelID)
" [X] ZettelOpenUnderCursor
" }}}
" Commands {{{2
" ZettelOpenUnderCursor
" ZettelOpen
" }}}
" }}}
" Functions {{{1
func ExpandZettelID(ZettelID)
return g:zkdir . a:ZettelID . g:zexte
endf
func ZettelOpen(ZettelID)
exec 'edit '.ExpandZettelID(a:ZettelID)
endf
func ZettelSearch() "opens the zettel after search.
call fzf#vim#grep("rg 'title:' --column", 1,
\ fzf#vim#with_preview({'dir':g:zkdir, 'options': g:fzf_options}))
endf
func ZettelOpenUnderCursor()
call ZettelOpen(expand('<cword>'))
endf
func ZettelNew() " relying on https://github.com/srid/neuron
exec 'e '.system('neuron new "PLACEHOLDER"').' |norm jfP"_D'
endf
func Insert(thing)
put =a:thing
endf
func ShrinkFZF(output)
call Insert(split(a:output, g:zexte)[0])
endf
func ZettelSearchInsert()
call fzf#vim#grep("rg 'title:' --column", 1,
\ fzf#vim#with_preview({
\ 'dir':g:zkdir, 'sink': 'ShrinkFZF ', 'options': g:fzf_options
\ }))
endf
func LastModifiedFile(dir, extension)
return system('ls -t '.a:dir.'*'.a:extension.' | head -1')
endf
func ZettelLast()
return LastModifiedFile(g:zkdir, g:zexte)
endf
func ZettelLastInsert()
call Insert('<'.fnamemodify(ZettelLast(), ':t:r').'>')
endf
func ZettelOpenLast()
exec 'e '.ZettelLast()
endf
" }}}
" Commands {{{1
command! -nargs=* ShrinkFZF call ShrinkFZF(<q-args>)
" }}}
" Mappings {{{1
nm <m-z> :call ZettelSearch()<cr>
nm <LocalLeader>zn :call ZettelNew()<cr>
nm <LocalLeader>zi :call ZettelSearchInsert()<cr>
nm <LocalLeader>zl :call ZettelLastInsert()<cr>
nm <LocalLeader>zo :call ZettelOpenUnderCursor()<cr>
nm <LocalLeader>zu :call ZettelOpenLast()<cr>
" }}}

Loading…
Cancel
Save