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 ...
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
...
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....
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! ...
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 ...
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\|...
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:
...
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 &...
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 ...
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 :...
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 :%...
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 ...
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 ...
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.
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 ...
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 '!...
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 ...
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:
...
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 ...
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'
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 ...
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 "...
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 ...
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 ...
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 ...
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. ...
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(...
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 ...
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 ...
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" ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
user-commands × 31functions × 6
command-line × 5
neovim × 4
visual-mode × 4
key-bindings × 3
command × 3
vimscript × 2
range × 2
vimrc × 1
buffers × 1
terminal × 1
autocompletion × 1
normal-mode × 1
external-command × 1
linux × 1
visual-block × 1
variables × 1
makeprg × 1
path × 1
plugin-fugitive × 1
count × 1
quit × 1
sort × 1
object-motions × 1