Questions tagged [functions]

Question about the use of functions in Vimscript defined in the `.vimrc` or a script file.

Filter by
Sorted by
Tagged with
0
votes
1answer
18 views

How do I move to the beginning of a visual block from a vimscript function?

Suppose i have several lines of text: line1 line1 line2 line2 line3 line3 I want to create a vimscript function that has the following result: <itemizedlist> <listitem><para>line1 ...
0
votes
2answers
59 views

Vim: Foldtext contain all content, instead of only the first line

Would like to have all content of the folded block, instead of only the first line. My current foldsettings are: set foldmethod=marker set foldmarker={,} Example how my data is structured: { ...
0
votes
1answer
45 views

Capture the next keypress under 200ms

1) I need to capture the next key press from the keyboard, if there are any in 200 millisecond. Which function should I use to achieve this? 2) Basically I need to re-send the captured key, with some ...
0
votes
1answer
38 views

Why does `:call f(…)` do nothing while mapping it to a binding works?

I'm not really sure how to describe this behavior better than with the example I'm dealing with. I'm trying to write a custom completion using fzf-vim ... and as I'm looking through the documentation,...
0
votes
1answer
69 views

Function Unable to Fail: Breaks Macros

Vim functions do not seem to be able to fail without spitting out 3 unnecessary lines. For example, take this set of functions and maps: " NEXT / PREVIOUS " ~~~~~~~~~~~~~~~ " n and N always search ...
0
votes
1answer
224 views

How to use a value stored in a variable in the command mode?

Consider the following function function! AbbreviationsOpen() "go to the first word of the last line normal G "store the word in the register named a let @a = expand('<cword>') ...
0
votes
1answer
38 views

How to invoke mapped `i_CTRL-W` in function

First I will describe what I am trying to achieve: In general I use set iskeyword+=- as I see this more usable (one should always put spaces around operators when needed). This is quite helpful, but ...
0
votes
1answer
133 views

Convert newline to something else in variable using substitute

Inside of a variable, a newline is encoded as ^@ which represents a null byte. In the vim Ex command line it is possible to issue something like substitute(var, '^@', '\\n', 'g'), this produces \n ...
0
votes
1answer
76 views

Replicate normal mode function in visual mode

I had the following mapping to go to the 1st non blank character of a line nnoremap M ^ I then decided that if I was already at the 1st non blank character I wanted M to take me to the absolute 1st ...
0
votes
1answer
38 views

How may I create an excmd that has a signature like g, s, v commands? (`:cmd/str1/str2/options`)

A g command can find the lines globally and then apply actions, like the following would find lines that contain foo and delete those lines: :g/foo/d An s command is more well-known for its ...
0
votes
1answer
128 views

Get list of javascript functions in file

The functionality that I am after, is to get a list of the javascript functions present in the file that I am in. Clicking a function in the list will then take me to that function. How do I go about ...
0
votes
2answers
124 views

How to make vim functions local to script but callable by mapping?

To make functions local, you prefix it with 's:'. But then it can't be called with mappings. Given this function: function! ScriptFunction() ... endfunction What convention or keywords do I add to ...
0
votes
1answer
527 views

Alternative to shellescape that doesn't add quotes in Linux?

According to the documentation for shellescape in vim: shellescape({string}, [, {special}]) shell escape() Escape {string} for use as a shell command argument. ... For other systems, it will ...
0
votes
1answer
27 views

How to keep vim running after kick off an application?

I have below function to compare perforce versions. The function runs fine, only I must quit the version compare software to keep typing words or switch to anther window. Basically gvim stops ...
0
votes
1answer
20 views

Check nerd tree is open function

I'm trying to create a simple function in vim which lets me map <leader>b, <leader>n, and <leader>0 to execute a function that checks if a nerd tree is open then cycle tabs and do :...
0
votes
0answers
35 views

How to stop a function when <esc> is pressed? OR how to catch a <esc> signal in vimscript?

I have a function which calls another function that reads user input from input(). function! fun1() call fun2() endfunction function! fun2() let temp = input("Please input:") endfunction What I ...
0
votes
0answers
174 views

Exclamation mark after autocommands

I'm trying to understand what does exclamation mark after autocommands mean. Sometimes it is possible to see something like this: function! LangSpecificOptions() if (&filetype == 'markdown' || ...
0
votes
1answer
115 views

Sharing vim commands history across different users and computers

I have configured .dotfiles. Eg. see here https://wiki.archlinux.org/index.php/Dotfiles So now I can do dgit push or dgit pull on whichever computer I want, and I have all my config files (including ....
0
votes
2answers
44 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
0answers
35 views

Why is this function clearing screen output?

This is an example script which is meant to print the keyboard shortcut for a command. Applying it clears the screen output. The result of commands like intro or version get cleared off the screen ...
-1
votes
2answers
35 views

Increase numbers by one in a visual block

I edit DocBook XML files. In my plugin, i want to implement a function that would increase or decrease the section numbers recursively, assuming that cursor is at the toplevel section. For example, ...
-2
votes
1answer
669 views

How to redraw vim after a function call to the commandline

While doing a fun vim exercise I ran into an odd redraw problem. nmap goo :execute ':call GoogleIt("' . input("What would you like to google?: ") . '")'<cr> function GoogleIt(content) ...