As of May 31, 2023, we have updated our Code of Conduct.
16 votes
Accepted

Is there a command to enter Visual Block mode?

There is no built in command to start visual block mode in vim, but you can define one yourself: command! Vb normal! <C-v> Here is a breakdown of how it works: command! Vb - This creates a ...
EvergreenTree's user avatar
14 votes
Accepted

Passing visual range to a :command as its argument

See this answer on stackoverflow. The example given is: function! PrintGivenRange() range echo "firstline ".a:firstline." lastline ".a:lastline " Do some more things endfunction ...
statox's user avatar
  • 48.5k
10 votes
Accepted

What is the purpose of user `command` in Vi/Vim?

Let's get this confusion out of the way first: Are these ex commands or Vimscript? Vim scripts are made of ex commands. From :help script: Your first experience with Vim scripts is the vimrc file....
8bittree's user avatar
  • 1,457
10 votes

Is there a command to enter Visual Block mode?

As far as I can find, there is no built-in command to start visual mode. However, you can easily add these commands to Vim: :command! Visual normal! v :command! VisualLine normal! V :command! ...
Martin Tournoij's user avatar
7 votes
Accepted

Better "bro ol"

This should work: command! Bro :enew | setl buftype=nofile | 0put =v:oldfiles \| nnoremap <buffer> <CR> gf | 1 :enew doesn't support +cmd, unlike :vnew, so just split the :setl out to ...
muru's user avatar
  • 24.5k
7 votes
Accepted

Filtering text out to new tab with custom command

You can create a new empty buffer in a new tab and then populate it with the result of a grep search on the previous file: :tabnew|0r!grep -n pattern # In a mapping: nnoremap <key> :tabnew\|...
romainl's user avatar
  • 36.9k
5 votes
Accepted

How Can I Rename a Command but Still Use the Original Command

If you want to keep your habit typing tabclose you could use: cnoreabbrev tabclose TabClose Or as mentioned by @Rich to avoid that the abbreviation triggers in search or as part of other commands: ...
Vivian De Smedt's user avatar
5 votes
Accepted

How to write a user-defined command in vim?

It looks like you are trying to use :command like :map to map a series of keys. But they are different. In a user-defined command, you don't need : to enter into command-line mode and you don't need &...
Yegappan Lakshmanan's user avatar
5 votes

Filtering text out to new tab with custom command

First clear an register: qaq second, append all matching lines using the :g command: :g/pattern/y A Third, put all matches on a new page :tabnew +$put\ A If you want to be able to make changes on ...
Christian Brabandt's user avatar
5 votes

How to define a custom user defined command to filter a range?

Ranges are not forwarded automatically, you need to use <line1> and <line2> for that: command! -range Ex <line1>,<line2>!expand -t4 You should read the manuals of :help :...
Ciro Santilli OurBigBook.com's user avatar
5 votes

Using arguments in a .vimrc command

If you are using the :%s command, you are already using some very simple VimScript. So much for not learning it :) If you want to create your custom command, you can use e.g. com! -nargs=1 Replace :%...
Christian Brabandt's user avatar
4 votes
Accepted

How to edit a file in a new tab?

You probably want to read :h user-commands and put the following in your vimrc: command! -nargs=1 -complete=file E tabnew <args> You can't override :e but you can create the command :E which ...
statox's user avatar
  • 48.5k
4 votes

How to create user command without a capital letter as first letter?

Why Commands (custom as well as built-in) are used in mappings, scripts, plugins. If you could override them, it would be very easy to break functionality. There is a mechanism for customization ...
Ingo Karkat's user avatar
  • 17.4k
3 votes

How to create user command to delete current file and saveas to new file?

If plugins are an option, tpope's eunuch plugin offers :Move to anywhere and :Rename within the current directory commands, among many others.
D. Ben Knoble's user avatar
  • 23.9k
3 votes

How to create user command to delete current file and saveas to new file?

Use <args> when referencing command arguments. <args> will expand to the arguments passed to the command. Also, while not strictly required, because you always want to pass one argument to ...
Jake Grossman's user avatar
3 votes
Accepted

Why only part of a command is executed

Your problem is that :command does not (by default) accept the use of bars, as explaind in :h :bar. You may circumvent this by using the -bar option, see :h :command-bar: command! -bar Tags execute '!...
Karl Yngve Lervåg's user avatar
3 votes

Passing visual range to a :command as its argument

you can also adapt this one liner command -range TmuxSession execute "!tmux.session " . @* or if you do need multiline visual selection change @* to substitute(@*,"\n"," ","g") The @* register ...
mrajner's user avatar
  • 213
3 votes
Accepted

Is it possible to non-recursively remap a command?

I don't believe it's possible to redefine :Glog without losing access to the script-local function. However, bearing in mind your muscle memory is for glog, not Glog, I propose another approach: ...
Rich's user avatar
  • 30.4k
3 votes
Accepted

How do I remap the :make command to run a docker container?

Using 'makeprg': set makeprg=docker\ run\ --rm\ -v\ $(pwd):/src\ container\ make Unfortunately, the \ are necessary for set to keep the spaces; single quoting won't work here. Now you can run :make ...
D. Ben Knoble's user avatar
  • 23.9k
2 votes
Accepted

How to use variables in a user defined command?

Can simply use exec and . to build the command: let PathToPluginsFolder = ~/.vim/plugins command! PS silent! exec ':w | PlugSnapshot! ' . PathToPluginsFolder . '/plugins.lock'
ruohola's user avatar
  • 626
2 votes

How to edit a file in a new tab?

Like everyone else, I recommend pretty strongly against doing this, but if you're dead set on the idea (and for future readers who might be doing something slightly different) you could use something ...
Rich's user avatar
  • 30.4k
2 votes
Accepted

Mapping using tpope/vim-surround only works with command

EDIT: Your mapping doesn't work because you are in a rare case where you want to use nmap instead of nnoremap: You want to use in a mapping an already defined mapping. Using nnoremap you said to Vim "...
statox's user avatar
  • 48.5k
2 votes
Accepted

Custom Arguments to User Command

You can use the -complete=... flag while defining a user-command to program how tab completion should work when the command is used. See :help :command-completion for more details about that flag. The ...
filbranden's user avatar
  • 27.5k
2 votes

How to make an user-defined command that works in normal and visual mode?

Alternately, keep your original Fill definition, and always type (or enter from a mapping) :call Fill() When in normal mode, this works fine (as you’ve observed). From visual mode, with a mapping or ...
D. Ben Knoble's user avatar
  • 23.9k
2 votes
Accepted

How to make an user-defined command that works in normal and visual mode?

You are almost there. I would do it the following: Define the command as taking an explicit range: command -range Fill :<line1>,<line2>call Fill() This will call the function with ...
Christian Brabandt's user avatar
2 votes
Accepted

How do I call a function from a user command? (Getting a "trailing character" error, E488)

First thing you need to do is get the syntax of :command right. This is what it's supposed to be... :com[mand][!] [{attr}...] {cmd} {rep} {attr} means attributes. That includes the -nargs value. ...
B Layer's user avatar
  • 19.1k
1 vote
Accepted

Lowercase user-commands?

I suppose I agree with @romainl you need a new keyboard. Here is my proposition: function! CorrectCommand() if getcmdtype() != ':' return "\<CR>" endif if matchstr(...
Vivian De Smedt's user avatar
1 vote

Can I use Telescope to find all commands and functions?

If you are searching for lsp symbols you can do: :Telescope lsp_document_symbols For this to work you need to have Neovim LSP framework to be connected to the corresponding LSP server. In order to do ...
Vivian De Smedt's user avatar
1 vote
Accepted

How do I call a user-defined command from a function, and wait until it finishes?

Here is the solution I came up with after reading the link in @D. Ben Knoble's comment. The only thing I'm not terribly happy with is the expand('<SID>') workaround I used. It just seems like a ...
Phil R's user avatar
  • 411
1 vote
Accepted

How can I execute commands or move to other tabs without first closing the terminal executed by `:term`?

In Neovim there's only one key combination not passed to the underlying terminal process. From :h terminal-input To send input, enter Terminal-mode using any command that would enter "insert mode" ...
Matt's user avatar
  • 19.5k

Only top scored, non community-wiki answers of a minimum length are eligible