https://github.com/tyru/empty-prompt.vim
Vim plugin to add mappings only when shell prompt is empty
https://github.com/tyru/empty-prompt.vim
Last synced: 8 months ago
JSON representation
Vim plugin to add mappings only when shell prompt is empty
- Host: GitHub
- URL: https://github.com/tyru/empty-prompt.vim
- Owner: tyru
- Created: 2020-01-06T05:51:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-10T04:36:07.000Z (over 6 years ago)
- Last Synced: 2025-01-14T07:30:17.927Z (over 1 year ago)
- Language: Vim script
- Homepage:
- Size: 9.77 KB
- Stars: 14
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# empty-prompt.vim
Vim plugin to add mappings only when shell prompt is empty
## Requirements
* Vim 8.2 or higher
## Usage
After installing this plugin, write this to your vimrc.
```vim
function! s:empty_prompt_mappings() abort
" If current line is empty prompt ...
" : works as :
call empty_prompt#map(#{lhs: ':', rhs: ':'})
" works as N
call empty_prompt#map(#{lhs: '', rhs: 'N'})
" ... Add more mappings you like
endfunction
autocmd VimEnter * ++once call s:empty_prompt_mappings()
```
## Customize
`g:empty_prompt#pattern` (default: `&shell =~# 'sh$' ? '\$ $' : '>\s*$'`)
If current line on terminal window matches this pattern, fire given mapping.
Default is:
* current line ends with `$ ` (`&shell` ends with `sh` (bash/zsh/...) like Unix environment)
* current line ends with `>` (otherwise, cmd.exe/powershell like Windows)
If the default value does not fit your environment, please consider customize the value.
## API
### `empty_prompt#map({'lhs': , 'rhs': [, 'fallback': ]})`
```vim
call empty_prompt#map(#{lhs: '', rhs: "N"})
```
This will be expanded to:
```
tnoremap {lhs} empty_prompt#is_empty() ? {rhs} : {fallback}
```
`{fallback}` is optional.
Default `{fallback}` is same as `{lhs}`