Questions tagged [user-commands]
Questions about :command and how the user can define custom commands.
20
questions
0
votes
1answer
55 views
Intercepting & modifying commands
Is it possible to intercept incoming user commands? For example, if the user executes :echo 'hello', then I would like to compare the string and the command, and change it to execute :echoerr 'hello' ...
0
votes
2answers
28 views
How to create user command to delete current file and saveas to new file?
I use :saveas to move a file while maintaining its undo history. Most of the time I immediately delete the old file. So if I'm editing foo.txt I'll issue
:saveas bar.txt
:!rm foo.txt
I wanted to ...
0
votes
1answer
26 views
How can I execute commands or move to other tabs without first closing the terminal executed by `:term`?
I've created a new terminal by executing :tabnew +term.
How can I execute other Vim commands or move to another tab without first closing the terminal (:term)?
Currently, all input is directed to ...
2
votes
0answers
28 views
Chaining user-defined commands [duplicate]
Assuming I have defined 2 commands in .vimrc
MultipleEmptyLinesToOne
RemoveExcessiveSpaces
I can run them in command-line mode:
:exec "'<,'>MultipleEmptyLinesToOne" | exec "'<,'>...
4
votes
3answers
4k views
Passing visual range to a :command as its argument
I have a command:
command! -nargs=1 TmuxSession !tmux.session "<args>"
and I want to run it in visual mode so that selected text will be passed as argument.
By selected text I mean selected in ...
1
vote
1answer
84 views
How do I remap the :make command to run a docker container?
I use a custom docker container to build my project so my "make" command is actually docker run --rm -v $(pwd):/src container make $arg.
I'd like to be able to type :make $arg in command mode and ...
0
votes
1answer
101 views
How to use variables in a user defined command? [duplicate]
I have this user defined command:
command! PS silent! w | PlugSnapshot! ~/.vim/plugins/plugins.lock
How could I change it to take the filepath from a variable, something like this:
let ...
3
votes
1answer
176 views
What is the purpose of user `command` in Vi/Vim?
What is the purpose of user command in Vi/Vim? I noticed that a lot of commands are usually used to call functions like this:
command! TrimWhitespace call TrimWhitespace()
From my observation, ...
0
votes
1answer
40 views
Is it possible to non-recursively remap a command?
So Fugitive defines :Glog. This is, apparently, aliased to a call to the script-local s:Log() function (according to :command Glog.)
My muscle-memory has been using glog at the command-line, for ...
4
votes
2answers
215 views
How to edit a file in a new tab?
I want to map :e file.txt to :tabnew file.txt, or the equivalent setting for editing file in a new tab. What do I need to put into my vimrc?
1
vote
1answer
773 views
Using arguments in a .vimrc command
I've discovered that I can edit the .vimrc file to create custom commands and would like to create simpler search and replace alternative commands, but have no idea how to edit %s/foo/bar/gc so that ...
0
votes
2answers
271 views
Mapping using tpope/vim-surround only works with command
I have this mapping to surround a Word with jQuery id selector $("#...") and it works fine using a command:
command! JqId normal viwo^[i#^[ysiW"ysiW)i$^[E
nnoremap <Leader>jqid :JqId<CR>
...
0
votes
2answers
52 views
Extract JavaScript variable (feature example): how to improve it?
I am a Vim newbie with one week experience and I'm already enjoying it.
I've successfully written an (ugly) command+function+mapping with which I can extract some code to a new variable in JavaScript....
0
votes
1answer
52 views
Why does the <count> escape sequence insert the current line number in my user command?
I've added the following to my .vimrc in order to test how <count> works in a user defined command because I was noticing odd behaviour:
:command! -count=1 CountTest :exe "echo " . <count>...
1
vote
1answer
298 views
How to create user command without a capital letter as first letter?
I know I can set user-defined commands using the :command Foo bar syntax, but I want a way to set a command without using capitals.
For example, to save all open buffers, the command is :wa, but that'...
2
votes
1answer
466 views
Better “bro ol”
Inspired by a nice solution on a Stack Overflow, the following was put in my vimrc:
command! Bro :vnew +setl\ buftype=nofile | 0put =v:oldfiles
\| nnoremap <buffer> <CR> :e <C-r>=...
8
votes
2answers
5k views
Is there a command to enter Visual Block mode?
I've set up a bunch of key mappings that would cause many Vim users to cringe. Now I am unable to get into Visual Block mode using Ctrl-V (Ctrl-Q isn't mapped, but it doesn't work).
Is there any ...
1
vote
1answer
56 views
Why only part of a command is executed
I have created a new command
command! Tags execute '!GTAGSFORCECPP=1 gtags' | cscope kill -1 | cscope add GTAGS
However, for some reason cscope add GTAGS doesn't execute when I execute :Tags.
Can ...
2
votes
2answers
910 views
Filtering text out to new tab with custom command
I would like to add to my vimrc a custom command (:customFilter {pattern}) for filtering text and placing result in a new tab.
I tried using :global or :vimgrep /{pattern}/ % but the problem is that ...
3
votes
1answer
1k views
How to define a custom user defined command to filter a range?
I want to select some lines in visual mode, and enter a custom command :Ex<CR> so that:
'<,'>!expand -t4
is run to expand all tabs in selected range. How to define the Ex command?
I ...