Problem
I like to make distance actions using ex commands.
It's pretty helpful to remove, copy or move a line or lines to the current position.
However, whenever running, some ex command cursor jumps around, and that is so annoying.
Every time, after running the ex command, I had to navigate back by pressing
Solution
I was looking for a solution on the Internet but didn't find something to solve my problem. So, I came up with the custom function.
function! ExCommandWithoutJump(command)
try
execute ":norm! ml"
execute ":" . a:command
execute ":norm! `l"
execute ":delm l"
catch /.*/
" Suppress the following errors:
" - Line where was mark was removed
" - Wrong range entered - No need to echo the error,
" as there will be no effect
endtry
endfunction
nnoremap <leader>ta :call ExCommandWithoutJump('')<Left><Left>
I mapped it to
Testing
Here is the text we're going to operate on.
PHP
Groovy
TypeScript
Shell
PowerShell
Perl
Haskell
Visual Basic .NET
SQL
Delphi
MATLAB
Groovy
Lua
Rust
Ruby
C
Dart
DM
Bash
C#
JavaScript
Java
So if we go all the way down and press
Now press