aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2020-09-17 15:22:40 +0900
committernsfisis <nsfisis@gmail.com>2020-09-17 15:22:40 +0900
commit467ba11bc9e33dfe6463d11fc40fbb296cec3dfc (patch)
tree6dfc63cd8228e8f8965e424d1753ce9b4aaf9b91
parent055fabe9bacce8f47a30ecc67c271e8e07747faa (diff)
downloaddotfiles-467ba11bc9e33dfe6463d11fc40fbb296cec3dfc.tar.gz
dotfiles-467ba11bc9e33dfe6463d11fc40fbb296cec3dfc.tar.zst
dotfiles-467ba11bc9e33dfe6463d11fc40fbb296cec3dfc.zip
Update .vimrc: add :Reverse command
-rw-r--r--.vimrc17
1 files changed, 17 insertions, 0 deletions
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<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>)
+