From 467ba11bc9e33dfe6463d11fc40fbb296cec3dfc Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 17 Sep 2020 15:22:40 +0900 Subject: Update .vimrc: add :Reverse command --- .vimrc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.vimrc b/.vimrc index 1df1a4e..0934775 100644 --- a/.vimrc +++ b/.vimrc @@ -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 +" 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 reverse_lines(, ) + -- cgit v1.2.3-70-g09d2