DEV Community

Discussion on: Use external programs like git in Neovim commands

Collapse
 
pbnj profile image
Peter Benjamin (they/them)

Running external programs to modify the current buffer is one of the main features I use vim for.

You can also take :! to the next step by wrapping it in a Vim command.

For example, instead of typing :! echo % | pbcopy every time, you can wrap it in a command like:

command! CopyFilename :! echo % | pbcopy
Enter fullscreen mode Exit fullscreen mode

Now, you can just run :CopyFilename.

You can also take it another step by binding it to a key map, like:

nnoremap <leader>cf <cmd>CopyFilename<cr>
" or
nnoremap <leader>cf :CopyFilename<cr>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
danrot90 profile image
Daniel Rotter

Yeah, creating your own Vim commands is also something really nice :-) Whether or not I do that depends a bit on my personal intuition. E.g. for the git command I would not like to do that, because I prefer to use them in the exact same way as on the command line, this way I don't have to remember two different ways of doing the same thing 🙂