An open API service indexing awesome lists of open source software.

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

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}`