Quantcast
Channel: Active questions tagged user-commands - Vi and Vim Stack Exchange
Browsing latest articles
Browse All 61 View Live

How to use variables in a user defined command? [duplicate]

I have this user defined command:command! PS silent! w | PlugSnapshot! ~/.vim/plugins/plugins.lockHow could I change it to take the filepath from a variable, something like this:let PathToPluginsFolder...

View Article


Sort from current column from visual selection

I am trying to write a :sort wrapper that sorts from current column.command! -bang -range=% -nargs=* Sortc exe '<line1>,<line2>sort<bang> <args> /\%' .. virtcol('.') .....

View Article


How to save buffer from command?

I'm trying to get :W to also save like :w (I often mistype). I tried something like this:command! W execute "norm! w", but that doesn't work. How can I do this?

View Article

How can I make a command that checks iteratively through parent directories...

I made a command line tool to generate static websites. I want a way to use this command line tool from the Vim command line, something like the :G command from the Fugitive plugin.The tool can only be...

View Article

How do I do a keybind involving ?

I use a keyboard layout designed for Spanish speakers and I've remapped hjkl to jklñ because those are the main home row keys. With hjkl I have to be constantly moving my hand to the left in order to...

View Article


How to bind function calls in vim

Suppose I have some extension that allows for calling some function foo(). Can I somehow bind the command :call foo() to just :k for example?

View Article

Is there a way to bind `:qw` to `:wq`?

I often mistype :wq as :qw. I can't create a command for qw though since it doesn't start with an uppercase character. Is there a way I can bind qw to wq?

View Article

Apply next non-blankline function as one part of multi-part user-command

Why do I seem to get different results when I apply this function from the Vim command line than when I apply it as part of a user-command?" advance to next non-blank line only if current line is...

View Article


Advance to next non-blank line only if current line is not blank

I want to tell a command or mapping to advance to the next non-blank line before executing - but to do this only if the current line is not blank.Ultimately, I intend to apply this to a command to...

View Article


How to get timezone using strftime command?

I have a custom command for stamping time in my log files. However, I would like that format to match the one of bash command date.For example, I use this command::command InLog pu=strftime(\"\n*****...

View Article

How can I create a command alias for :Ex /path/to/directory

I'm trying to make my life easier by making a shortcut for the following command:Ex /path/to/directoryI need to to be able to press :akeyword and execute the command above.The directory needs to be...

View Article

set a default value to a command that acccepts two arguments?

I often need to delineate "sections" of source code files using a comment character to create horizontal lines. For example if I wanted to draw such a line in a python file I could do:Hline # 79where...

View Article

deleting a plugin (not a user defined) command?

I am using the fzf plugin which has a command called :Windows. Very often I type :W instead of :w when trying to write and it is very annoying. I would like to remove the command, since I do not use it...

View Article


Search for a pattern, copy the line with the matching pattern, copy the next...

I have a file with data that goes like this.Engine1Temp:10Humidity:23 Engine1Temp:13Humidity:21 Engine2Temp:10Humidity:23This pattern repeats throughout the file.I want to do the following in a single...

View Article

Define w< command

I often type :w< instead of :wq, so I wanted to redefine it (in order to avoid the creation of a < file) as following:command! w< wBut it seems to not be allowed:Error detected while...

View Article


Making custom command behave like ":echo" with respect to quotes

This command works without errors::echo v:oldfiles->copy()->filter('v:val =~# "txt$"')(see :h method, :h v:oldfiles, :h v:val and :h =~#)I want to create a custom command / function combination...

View Article

How to identify the script that's calling a user command?

I have a problem: I need to pass « any » caller-session trace into a user command… Was trying with:command WantToKnowWhosCalling call Impl("\<SID>", \ expand("<SID>"),...

View Article


Why does `` behave like `|` in the `:command` command in Vim?

Here is the list of experiments I performed that shows that <Bar> is treated as literal <Bar> in some commands but it is treated as | in the :command command.I am trying to understand why...

View Article

Passing a pattern as argument without extra escaping

so I want to pass a pattern to a command. command! -nargs=1 -buffer Vim silent exec "vim! /" . <args> . "/ ./*" | copen | redraw!But there is a problem. If I want to match /foo i would use the...

View Article

What does the command option '-range=N' do?

I can't understand the vim help for :command-range, it states -range=N A count (default N) which is specified in the line number position (like :split); allows for zero line number.The documentation...

View Article

How to add modifier to user defined command?

I'd like to write commands that work with :tab and :vert. Say I have a command that opens a new split window as shown belowfunction! FooSplit() let l:message="hello world" new put!...

View Article


How to create ctrl map in command directly?

I'm trying to toggle some ctrl maps in command directly, it didn't work as expected:com Test0 nnoremap <c-j> :echo "c-j"<cr>com Test1 nnoremap <c-h> :echo "c-h"<cr>com Test2 exe...

View Article


How to define a command if the function needs to take an argument from the...

Suppose I am defining a few commands that are similar in functionality. In this particular case, I am defining a few commands that each echoes a particular message: function! EchoMessage(text) echom...

View Article

How can I alias a command with arguments?

All I want to do is to change :vertical resize+ arguments into :vr+ arguments.for example change::vertical resize +60 <CR>into::vr +60 <CR>From other answers Aliasing a command in vim, I...

View Article

How to pass everything from a command into a function with escaped characters

These are my scenarios and expected outputfunction! s:Foo(text) echoerr "'" . a:text . "'"endfunctioncommand ... FooCommand ... (not sure what to write here)FooCommand text'text'FooCommand text...

View Article


creating a ":KeepCursor" command

I'd like to make a command that works like this: :KeepCursor {cmd} will the given execute ex command string, then restore the cursor's position. A primary example is::KeepCursor normal! *which would...

View Article

Stop flushing the last command when hitting enter

Suppose I wrote this command:command! -nargs=1 E echo ' -> <args>'and when user feeds an argument,:E abcI intend to see the following effect as they hit Enter::E abc -> abcOf course that's...

View Article

How to find out where a function or command was defined?

I'd like to know if there is an analogue to verbose map <key> (which shows the location where the map was assigned) for functions and commands. For example, I have a few Git plugins and I'd like...

View Article

Run vimscript+python user commands sequentually?

I am running vim 8.2.2121.I am trying to open 3 tabsOne tab has instructions in it and is opened read only.Both tabs 2 and 3 create :new files and read template files into them on separate tabs.There...

View Article



Repeat complete user-defined command

I defined a command that swap case of the first letter of a word.I want to be able to use a "count" to repeat my command in order to swap, for example, the first letter of the next three words. In doc...

View Article
Browsing latest articles
Browse All 61 View Live


Latest Images