├── LICENSE.md ├── README.md ├── autoload └── husk.vim ├── doc └── husk.txt └── plugin └── husk.vim /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (C) 2014 Bruno Sutic 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the "Software"), 5 | to deal in the Software without restriction, including without limitation 6 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | and/or sell copies of the Software, and to permit persons to whom the 8 | Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included 11 | in all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 14 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 15 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 17 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 18 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 19 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # husk.vim 2 | 3 | Mappings that boost vim command line mode. 4 | 5 | The goal is to have mappings similar to `bash` emacs mode. 6 | You can read more about this idea in vim's docs 7 | [:h tcsh-style](http://vimdoc.sourceforge.net/htmldoc/cmdline.html#tcsh-style). 8 | 9 | Plugin killer feature are convenient `M-f` and `M-b` CLI mappings that move one 10 | "word" right or left (notice the lowercase "word"). 11 | 12 | This is an enhancement from vanilla vim that enables only "WORD" (uppercase) 13 | left or right with
14 | `` and ``. 15 | 16 | Works in NeoVim too. 17 | 18 | ### Mappings 19 | 20 | All mappings work **only** in vim command line mode. 21 | 22 | - `C-a` go to the beginning of the line 23 | - `C-f` go one character right or fall back to 24 | [c_CTRL-F](http://vimdoc.sourceforge.net/htmldoc/cmdline.html#c_CTRL-F) 25 | at the end of the line 26 | - `C-b` go one character left 27 | - `C-d` delete character or fall back to 28 | [c_CTRL-D](http://vimdoc.sourceforge.net/htmldoc/cmdline.html#c_CTRL-D) 29 | at the end of the line 30 | - `C-k` clear line after the cursor, overrides 31 | [c_CTRL-K](http://vimdoc.sourceforge.net/htmldoc/cmdline.html#c_CTRL-K) 32 | (if you're using `C-k` for digraphs check the docs how to disable) 33 | - `C-x C-e` open the command-line window, same as 34 | [c_CTRL-f](http://vimdoc.sourceforge.net/htmldoc/cmdline.html#c_CTRL-F) 35 | - `M-f` (Alt-f) go one "word" right 36 | - `M-b` (Alt-b) go one "word" left 37 | - `M-d` (Alt-d) delete "word" after the cursor 38 | - `M-BS` (Alt-Backspace) delete "word" before the cursor, same as 39 | [c_CTRL-W](http://vimdoc.sourceforge.net/htmldoc/cmdline.html#c_CTRL-W) 40 | - `M-#` (Alt-shift-3) insert comment at the beginning of the line and execute 41 | it. Useful for discarding the line, but still keeping it in the command-line 42 | history for later retrieval. 43 | 44 | ### Installation 45 | 46 | * Vundle
47 | `Plugin 'vim-utils/vim-husk'` 48 | 49 | * vim-plug
50 | `Plug 'vim-utils/vim-husk'` 51 | 52 | * Pathogen
53 | `git clone git://github.com/vim-utils/vim-husk.git ~/.vim/bundle/vim-husk` 54 | 55 | *Note*: In order to enable alt mappings (`M-f`, `M-b` etc) Mac OS users using 56 | Terminal.app may need to go to Preferences > Profiles > Keyboard and tick 57 | "Use Option as Meta key". 58 | 59 | ### About 60 | 61 | `vim-husk` grew out from Tim Pope's [vim-rsi](https://github.com/tpope/vim-rsi) 62 | plugin. `C-f`, `C-d` and `M-BS` mappings are directly copied. 63 | 64 | Differences: 65 | 66 | - `vim-husk` has proper `M-f`, `M-b` and `M-d` mapping implementation 67 | - with `vim-husk` there's no risk of breaking vim's macros. Link to related 68 | [vim-rsi issue](https://github.com/tpope/vim-rsi/issues/13). 69 | - `vim-rsi` has a broader scope and provides `insert` and `normal` mode 70 | mappings while `vim-husk` focuses only on vim's CLI. 71 | 72 | ### Licence 73 | 74 | [MIT](LICENSE.md) 75 | -------------------------------------------------------------------------------- /autoload/husk.vim: -------------------------------------------------------------------------------- 1 | function! husk#left() 2 | let line = getcmdline() 3 | let pos = getcmdpos() 4 | let next = 1 5 | let nextnext = 1 6 | let i = 2 7 | while nextnext < pos 8 | let next = nextnext 9 | let nextnext = match(line, '\<\S\|\>\S\|\s\zs\S\|^\|$', 0, i) + 1 10 | let i += 1 11 | endwhile 12 | return repeat("\", pos - next) 13 | endfunction 14 | 15 | function! husk#abstract_right(command) 16 | let line = getcmdline() 17 | let pos = getcmdpos() 18 | let next = 1 19 | let i = 2 20 | while next <= pos && next > 0 21 | let next = match(line, '\<\S\|\>\S\|\s\zs\S\|^\|$', 0, i) + 1 22 | let i += 1 23 | endwhile 24 | return repeat(a:command, next - pos) 25 | endfunction 26 | 27 | function! husk#right() 28 | return husk#abstract_right("\") 29 | endfunction 30 | 31 | function! husk#del_word() 32 | return husk#abstract_right("\\") 33 | endfunction 34 | 35 | function! husk#clear_line_after_cursor() 36 | let pos = getcmdpos() 37 | let line_len = strlen(getcmdline()) 38 | return repeat("\", line_len - pos + 1) 39 | endfunction 40 | -------------------------------------------------------------------------------- /doc/husk.txt: -------------------------------------------------------------------------------- 1 | *husk.txt* Mappings that boost vim command line mode. 2 | 3 | Author: Bruno Sutic 4 | 5 | INTRODUCTION *husk* 6 | 7 | Mappings that boost vim command line mode. The goal is to have mappings 8 | similar to bash emacs mode. You can read more about this idea in |tcsh-style|. 9 | 10 | Plugin killer feature are and CLI mappings that move one "word" 11 | right or left (notice the lowercase "word"). This is an enhancement from 12 | vanilla vim that enables only "WORD" (uppercase) left or right with 13 | |c_| and ||. 14 | 15 | MAPS *husk-maps* 16 | 17 | All mappings are defined only in vim's command line mode. 18 | 19 | *husk-CTRL-A* 20 | Cursor to beginning of command line, same as |c_CTRL-B|. 21 | 22 | *husk-CTRL-F* 23 | Cursor right, same as |c_|. Falls back to 24 | |c_CTRL-F| at the end of the line. 25 | 26 | *husk-CTRL-B* 27 | Cursor left, same as |c_|. 28 | 29 | *husk-CTRL-D* 30 | Delete character after the cursor. Falls back to 31 | |c_CTRL-D| at the end of the line. 32 | 33 | *husk-CTRL-K* 34 | Clear line after the cursor. 35 | If you're using |c_CTRL-K| you can disable this mapping 36 | with 'let g:husk_ctrl_k = 0'. 37 | 38 | *husk-CTRL-X_CTRL-E* 39 | Open the command-line window, same as |c_CTRL-f|. 40 | 41 | *husk-META-F* 42 | Cursor one "word" right. Command line equivalent of |w| for 43 | normal mode. 44 | 45 | *husk-META-B* 46 | Cursor one "word" left. Command line equivalent of |b| for 47 | normal mode. 48 | 49 | *husk-META-D* 50 | Delete "word" after the cursor. Command line equivalent of 51 | 'dw' for normal mode. 52 | 53 | *husk-META-BS* 54 | Delete "word" before the cursor. Same as |c_CTRL-W|. 55 | 56 | *husk-META-#* 57 | Insert comment at the beginning and execute the line. 58 | This is different than just discarding the line, because 59 | commented line stays in the command-line history and can 60 | later be retrieved. 61 | 62 | CONTRIBUTING *husk-contributing* 63 | 64 | Contributing is welcome. Github repo: 65 | 66 | https://github.com/vim-utils/vim-husk 67 | 68 | CHANGELOG *husk-changelog* 69 | 70 | v0.6.1: Sep 30, 2015 * bugfix: when '&term' changes plugin stops 71 | working 72 | v0.6.0: Nov 26, 2014 * Add 'C-k' mapping 73 | v0.5.0: Nov 26, 2014 * Add 'M-#' and 'C-x C-e' mappings 74 | v0.4.0: Nov 24, 2014 * Autoload functions 75 | v0.3.0: Oct 08, 2014 * Add 'C-f` mapping 76 | v0.2.0: Oct 01, 2014 * Add 'M-BS' mapping 77 | v0.1.0: Sep 29, 2014 * Add 'M-d' mapping 78 | v0.0.2: Sep 29, 2014 * Add 'C-d' mapping 79 | v0.0.1: Aug 22, 2014 * Initial working version 80 | 81 | LICENSE *husk-license* 82 | 83 | Copyright (c) Bruno Sutic. Distributed under the MIT license. 84 | 85 | vim:tw=78:ts=8:ft=help:norl: 86 | -------------------------------------------------------------------------------- /plugin/husk.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================ 2 | " File: husk.vim 3 | " Author: Bruno Sutic 4 | " WebPage: https://github.com/vim-utils/vim-husk 5 | " ============================================================================ 6 | 7 | if exists('g:loaded_husk') && g:loaded_husk 8 | finish 9 | endif 10 | let g:loaded_husk = 1 11 | 12 | let s:save_cpo = &cpo 13 | set cpo&vim 14 | 15 | set ttimeout 16 | if &ttimeoutlen == -1 17 | set ttimeoutlen=50 18 | endif 19 | 20 | function! s:enable_husk() 21 | cnoremap 22 | cnoremap 23 | cnoremap getcmdpos()>strlen(getcmdline())?&cedit:"\Right>" 24 | cnoremap getcmdpos()>strlen(getcmdline())?"\C-d>":"\Del>" 25 | cnoremap 26 | 27 | if get(g:, 'husk_ctrl_k', 1) 28 | cnoremap husk#clear_line_after_cursor() 29 | endif 30 | 31 | if !has('gui_running') && !has('nvim') 32 | cmap d 33 | cmap b 34 | cmap f 35 | cmap # 36 | cmap 37 | cmap 38 | cmap 39 | 40 | cnoremap stridx(&cpo, 'x') < 0 ? "\" : "\" 41 | endif 42 | 43 | cnoremap husk#del_word() 44 | cnoremap husk#left() 45 | cnoremap husk#right() 46 | cnoremap "\\"\" 47 | cnoremap 48 | endfunction 49 | 50 | call enable_husk() 51 | 52 | let &cpo = s:save_cpo 53 | unlet s:save_cpo 54 | --------------------------------------------------------------------------------