├── README.markdown ├── doc ├── tags └── textobj-quoted.txt └── plugin └── textobj └── hydrogen.vim /README.markdown: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | 4 | The textobj-hydrogen plugin provides two new text-objects, `ah` and `ih`, 5 | and backwards and forwards motion for them, `[h` and `]h` respectively. You 6 | can use them when you have to deal with hydrogen style python notebook cells. 7 | These are usually encountered when transforming jupyter notebooks to plain text 8 | files with tools such as jupytext and notedown. 9 | 10 | All code cells start with `# %%` . The end of the cell is implicitly defined 11 | by either a new cell marker or the end of the file. The `ah` object includes 12 | the marker line while the `ih` does not. Both commands treat the end of the 13 | cell in the same way. 14 | 15 | The new objects and motions combined with a plugin that will allow the user to 16 | send input to a REPL running along the editor allows for an enhanced Jupyter 17 | notebook like experience. 18 | 19 | 20 | Installation 21 | ------------ 22 | 23 | My prefered method of installation is using the Plug plugin manager. For it to 24 | work you will need to have `kana/vim-textobj-user` and this repo installed. 25 | 26 | ``` 27 | Plug 'kana/vim-textobj-user' 28 | Plug 'GCBallesteros/vim-textobj-hydrogen' 29 | ``` 30 | 31 | Copyright 32 | --------- 33 | 34 | Copyright (c) Guillem Ballesteros. Distributed under the same terms as Vim itself. 35 | 36 | Acknowledgements 37 | ---------------- 38 | 39 | I used [vim-textobj-underscore](https://github.com/lucapette/vim-textobj-underscore) 40 | as a template for this plugin. 41 | -------------------------------------------------------------------------------- /doc/tags: -------------------------------------------------------------------------------- 1 | textobj-hydrogen textobj-quoted.txt /*textobj-hydrogen* 2 | textobj-hydrogen-contents textobj-quoted.txt /*textobj-hydrogen-contents* 3 | textobj-hydrogen-copyright textobj-quoted.txt /*textobj-hydrogen-copyright* 4 | textobj-hydrogen-introduction textobj-quoted.txt /*textobj-hydrogen-introduction* 5 | textobj-hydrogen.txt textobj-quoted.txt /*textobj-hydrogen.txt* 6 | -------------------------------------------------------------------------------- /doc/textobj-quoted.txt: -------------------------------------------------------------------------------- 1 | *textobj-hydrogen.txt* Text objects for hydrogen stlye python notebook cells 2 | 3 | Version 0.0.1 4 | 5 | CONTENTS *textobj-hydrogen-contents* 6 | 7 | Introduction |textobj-hydrogen-introduction| 8 | Copyright |textobj-hydrogen-copyright| 9 | 10 | 11 | ============================================================================== 12 | INTRODUCTION *textobj-hydrogen-introduction* 13 | 14 | The *textobj-hydrogen* plugin provides two new |text-objects|, `ah` and `ih`, 15 | and backwards and forwards motion for them, `[h` and `]h` respectively. You 16 | can use them when you have to deal with hydrogen style python notebook cells. 17 | This are usually encountered when transforming jupyter notebooks to plain text 18 | files with tools such as jupytext and notedown. 19 | 20 | All code cells start with `# %%` . The end of the cell is implicitly defined 21 | by either a new cell marker or the end of the file. The `ah` object includes 22 | the marker line while the `ih` does not. Both commands treat the end of the 23 | cell in the same way. 24 | 25 | The new objects and motions combined with a plugin that will allow the user to 26 | send input to a REPL running along the editor allows for an enhanced Jupyter 27 | notebook like experience. 28 | 29 | Latest version: 30 | http://github.com/GCBallesters/vim-textobj-hydrogen 31 | 32 | ============================================================================== 33 | COPYRIGHT *textobj-hydrogen-copyright* 34 | 35 | Copyright (c) Guillem Ballesteros. Distributed under the same terms as Vim itself. 36 | See |license|. 37 | 38 | vim:tw=78:ts=8:ft=help:norl: 39 | -------------------------------------------------------------------------------- /plugin/textobj/hydrogen.vim: -------------------------------------------------------------------------------- 1 | if exists('g:loaded_textobj_hydrogen') 2 | finish 3 | endif 4 | 5 | call textobj#user#plugin('hydrogen', { 6 | \ '-': { 7 | \ '*sfile*': expand(':p'), 8 | \ 'select-a': 'ah', '*select-a-function*': 's:select_a', 9 | \ 'select-i': 'ih', '*select-i-function*': 's:select_i', 10 | \ 'move-n': ']h', '*move-n-function*': 's:move_n', 11 | \ 'move-p': '[h', '*move-p-function*': 's:move_p' 12 | \ } 13 | \ }) 14 | 15 | function! s:move_p() 16 | let next_line = search("^# %%", "cbnW") 17 | 18 | " Just in case the notebook has no starting cell. 19 | if next_line == 0 20 | let next_line = 2 21 | endif 22 | 23 | let curr_pos = getpos('.') 24 | let pos = [curr_pos[0], next_line - 1, 1, curr_pos[3]] 25 | 26 | return ['V', pos, 0] 27 | endfunction 28 | 29 | function! s:move_n() 30 | let next_line = search("^# %%", "cnW") 31 | 32 | if next_line == 0 " We are the last cell 33 | let next_line = line('$') 34 | else 35 | let next_line = next_line - 1 36 | endif 37 | 38 | let curr_pos = getpos('.') 39 | let next_pos = [curr_pos[0], next_line + 2, 0, curr_pos[3]] 40 | 41 | return ['V', next_pos, 0] 42 | endfunction 43 | 44 | function! s:select_a() 45 | let start_line = search("^# %%", "cbnW") 46 | let end_line = search("^# %%", "nW") 47 | 48 | " Just in case the notebook is malformed and doesnt 49 | " have a cell marker at the start. 50 | if start_line == 0 51 | let start_line = 1 52 | endif 53 | 54 | if end_line == 0 " We are the last cell 55 | let end_line = line('$') 56 | else 57 | let end_line = end_line - 1 58 | endif 59 | 60 | let curr_pos = getpos('.') 61 | let start_pos = [curr_pos[0], start_line , 1, curr_pos[3]] 62 | let end_pos = [curr_pos[0], end_line, 0, curr_pos[3]] 63 | 64 | return ['V', start_pos, end_pos] 65 | endfunction 66 | 67 | function! s:select_i() 68 | let start_line = search("^# %%", "cbnW") 69 | let end_line = search("^# %%", "nW") 70 | 71 | " Just in case the notebook is malformed and doesnt 72 | " have a cell marker at the start. 73 | if start_line == 0 74 | let start_line = 1 75 | endif 76 | 77 | if end_line == 0 " We are the last cell 78 | let end_line = line('$') 79 | else 80 | let end_line = end_line - 1 81 | endif 82 | 83 | let curr_pos = getpos('.') 84 | let start_pos = [curr_pos[0], start_line + 1 , 1, curr_pos[3]] 85 | let end_pos = [curr_pos[0], end_line, 0, curr_pos[3]] 86 | 87 | return ['V', start_pos, end_pos] 88 | endfunction 89 | 90 | let g:loaded_textobj_hydrogen = 1 91 | --------------------------------------------------------------------------------