diff options
| author | nsfisis <nsfisis@gmail.com> | 2020-09-17 15:22:40 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2020-09-17 15:22:40 +0900 |
| commit | 467ba11bc9e33dfe6463d11fc40fbb296cec3dfc (patch) | |
| tree | 6dfc63cd8228e8f8965e424d1753ce9b4aaf9b91 | |
| parent | 055fabe9bacce8f47a30ecc67c271e8e07747faa (diff) | |
| download | dotfiles-467ba11bc9e33dfe6463d11fc40fbb296cec3dfc.tar.gz dotfiles-467ba11bc9e33dfe6463d11fc40fbb296cec3dfc.tar.zst dotfiles-467ba11bc9e33dfe6463d11fc40fbb296cec3dfc.zip | |
Update .vimrc: add :Reverse command
| -rw-r--r-- | .vimrc | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -1074,6 +1074,8 @@ inoreabbrev tihs this " Commands {{{1 +" Set 'makeprg' to `ninja` if `build.ninja` exists in the current working +" directory. Then, execute :make command. command! -bang -bar -nargs=* \ Make \ if filereadable('build.ninja') | @@ -1082,6 +1084,21 @@ command! -bang -bar -nargs=* \ make<bang> <args> +" The current search pattern will not changed by :global in a user function. +" See :Reverse's comment below. +function! s:reverse_lines(from, to) abort + execute printf("%d,%dg/^/m%d", a:from, a:to, a:from - 1) +endfunction + +" Reverse a selected range in line-wise. +" Note: directly calling `g/^/m` will overwrite the current search pattern with +" '^' and highlight it, which is not expected. +" :h autocmd-searchpat +" :h :nohlsearch +command! -bar -range=% + \ Reverse + \ call <SID>reverse_lines(<line1>, <line2>) + |
