junegunn / junegunn/vim-easy-align
[sharing]: auto align in insert mode.
- Dominant language
- Vim Script
- Stars
- 4.2k
- Forks
- 122
- PR merge metrics
- No merged PRs in 30d
Description
This is not really an issue, but rather a function that I wrote to mimic [this](https://gist.github.com/tpope/287147) but by using this plugin.
```vim
vim9script
export def Align()
const p = '^\s*|\s*.*\s*|\s*$'
if exists(':EasyAlign') != 0 && getline('.') =~# '^\s*|'
# Save column and position
const curpos = getcursorcharpos()
# Search for first line
var startline = line('.')
if startline != 1
while getline(startline - 1) =~ p
startline = search(p, 'bW')
endwhile
endif
setcursorcharpos(curpos[1], curpos[2])
# Search for last line
var endline = line('.')
if endline != line('$')
while getline(endline + 1) =~ p
endline = search(p, 'W')
endwhile
endif
setcursorcharpos(curpos[1], curpos[2])
# Easy align
execute $":{startline},{endline}EasyAlign *|"
setcursorcharpos(curpos[1], strchars(getline(curpos[1])))
endif
enddef
inoremap Align()a
```
Hope you find it useful!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.