├── plugin └── splitline.vim ├── autoload └── splitline.vim ├── LICENSE └── README.md /plugin/splitline.vim: -------------------------------------------------------------------------------- 1 | " vim-split-line 2 | " Author: Sheldon Johnson 3 | " Version: 0.0.1 4 | 5 | if exists('g:loaded_split_line') || &compatible 6 | finish 7 | endif 8 | 9 | let g:loaded_split_line = 1 10 | 11 | command! SplitLine call splitline#SplitLine() 12 | -------------------------------------------------------------------------------- /autoload/splitline.vim: -------------------------------------------------------------------------------- 1 | function! splitline#SplitLine() abort 2 | let l:cnum = col('.') 3 | let l:lnum = line('.') 4 | 5 | if l:cnum == 1 6 | call append(l:lnum - 1, '') 7 | else 8 | let l:line = getline('.') 9 | 10 | let l:first_line = l:line[0:(l:cnum - 2)] 11 | let l:first_line = splitline#RStrip(l:first_line) 12 | let l:second_line = l:line[(l:cnum - 1):-1] 13 | 14 | call setline(l:lnum, l:first_line) 15 | call append(l:lnum, l:second_line) 16 | 17 | call cursor(l:lnum + 1, 1) 18 | normal! == 19 | endif 20 | endfunction 21 | 22 | function! splitline#RStrip(str) abort 23 | return substitute(a:str, '\s\+$', '', '') 24 | endfunction 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Sheldon Johnson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-split-line 2 | 3 | Without exiting normal mode, joining two lines is easy: J 4 | 5 | But splitting and auto-indenting a line is a little awkward: 6 | 7 | | Context | Keyboard | 8 | | --------------------------------------------- | ---------------------------------------------------------------------- | 9 | | Splitting on cursor | i Enter Esc | 10 | | Splitting on one char of whitespace | r Enter | 11 | | Splitting on more than one char of whitespace | c i w Enter Esc | 12 | 13 | vim-split-line gives the `:SplitLine` command. Without leaving normal 14 | mode it: 15 | 16 | - Splits the line under the cursor 17 | - Remove trailing whitespace on first line 18 | - Auto-indents second line 19 | 20 | ## Installation 21 | 22 | Install with a plugin manager. 23 | 24 | ## Configuration 25 | 26 | ```vim 27 | nnoremap S :SplitLine 28 | ``` 29 | 30 | I use S because the default behaviour is almost identical to 31 | c c, and it has a nice symmetry with J. 32 | 33 | 34 | ## Alternatives 35 | 36 | You don't actually need this plugin, the below also works: 37 | 38 | ```vim 39 | nnoremap S :keeppatterns substitute/\s*\%#\s*/\r/e normal! == 40 | ``` 41 | --------------------------------------------------------------------------------