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
2answers
152 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 ...
7
votes
0answers
241 views

vim ZZ lost output with autocommand

I want to check file before quitinq vim with custom functions, everything seems fine with QuitPre autocommand except using ZZ to exit. In this case the output is missing. Consider following function ...
2
votes
2answers
94 views

Running python code in a function

I'm having problems with latex-suite (some research indicates that many people are). The issue at hand is that they have a nifty python script that gives you a nice outline of your document and ...
2
votes
1answer
358 views

How to organize autoload functions?

I'd like to put all my custom functions into autoload folder, but I have functions with the same name. How should I organize them?
4
votes
1answer
179 views

Strange behavior with “map(range …)”

I'm trying to get into more advanced features of vimscript, so I'm trying to figure out how to use the map function, so I thought I'd write a function that returns every character with ASCII values ...
5
votes
1answer
600 views

Print an error message without “Error detected while processing function”

If I type: :echoerr "test error" I simply get the message printed (with red background): test error However, inside a function: function! Printerror() echoerr "test error" endfunction I get ...
2
votes
1answer
376 views

Get column of last character in visual line - Vimscript

In one of my vim scripts I require the column of the last non-whitespace character of the current line and the column of the last character of the current line (when the current line is wrapped into ...
1
vote
2answers
411 views

Call function on several lines

I have a function that changes the 6th caracter of a line to a dollar symbol ($). I want it to be performed on several lines, so I naively did a "while" loop using a counter (as shown under). But ...
2
votes
1answer
399 views

Carriage return as argument breaks the function

I have a remap that calls a function with a key combination as an argument. In this function I want to execute another remap to yet another function. But whatever I do, it complains about a missing ...
12
votes
4answers
786 views

Command to loop through spelling suggestions

I mapped zz to 1z=, which is great most of the time, but every now and then the first suggestion isn't the right one. So I'd like to keep repeating zz (or .) to cycle through the other suggestions. ...
-2
votes
1answer
730 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) ...
4
votes
2answers
167 views

How to debug an external function

I am trying to debug the vim-fugitive plugin, to dig into how it works. When I develop a piece of vim script, I am used to testing a function with the debug command. Here it does not work because the ...
1
vote
0answers
212 views

Vimrun.exe keeps opening and closing when statusline is updated

I am working on a plugin and as part of that plugin I am trying to update the statusline with setlocal statusline=%!GetMPCStatusline(). But this causes vimrun.exe to open and close very fast. This ...
3
votes
0answers
188 views

system function output with Chinese chars

I want to run shell command with system function and the command output has some Chinese chars. echo system('svn status') But I got incorrect encoding output like this: svn: ?\232?\173?\166?\229?\...
2
votes
1answer
516 views

Function does not work when called as from a mapping

I have a function that depends on the character under the cursor : if it's a ), then the function does nothing ; if it's not, the function adds a ). function! Ket() let char = getline(".")[col('.')...
5
votes
3answers
257 views

Way to get content of Visual Selection?

Now if I select something in visual mode, is there some way to get the selected area without having to yank it to some register? I looked through :h functions but didn't find anything.
2
votes
1answer
62 views

Use motion in normal mapping calling a function

I have this function which displays line numbers. I want it to be called in different ways: from a command, specifying the lines as arguments with a visual selection, printing the first and last line ...
3
votes
1answer
785 views

Function that opens file for editing

Is there a function that can be called to open a file for editing? I know how to open and edit files in Vim, and I know I can use :e filename, but is there a built in function I can call that does ...
2
votes
1answer
380 views

Function to refactor indents and tabs

I'm writing a vim function to set hard tabs and refactor indents in a whole file. This is the function: function RefInd() :set tabstop=4 softtabstop=0 noexpandtab shiftwidth=4 gg=G ...
3
votes
1answer
82 views

Defining a command on more than one line

It seems like the command command expects a one line set of arguments. What is a good way to define a command from something longer? I suppose defining a function with no argument and then calling ...
4
votes
1answer
75 views

Get visual column number with conceal feature

One can use col('$') to get the length of the current cursor line. Further, one can use virtcol('$') to get the same length, but this returns the actual screen column. However, it ignores the conceal ...
8
votes
3answers
2k views

Tutorial for vim programming? [duplicate]

I am a veteran user of vi. When I started using it, there was basically nothing... Now, we have vim. But, how do I program it? Where does one start? With help? Not sure this is a good start.
2
votes
0answers
44 views

Why does append(…, readfile()) add a zero when run using Ctrl-R?

While looking for ways to solve How can I create a /* comments section with /// like in XCode?, I cam across this puzzling behaviour. Say I have foo.txt containing: /*! * @author Robbie Yi JIANG, 29-...
5
votes
1answer
425 views

Vim Function to Send Highlighted Text to a Git Commit

Problem: Suppose I have the following text in my vim buffer: This is a commit msg. Suppose further I have a git repo located at ~/my_repo. Goal: Make a vim script so that I can highlight the text ...
4
votes
1answer
271 views

Does Vim compile user-defined functions?

If I define a function in my vimrc (or in a plugin), Vim will load it and I can use it. But what's happening under the hood after my vimscript is parsed? Is it transcoded down to C and compiled? Is ...
2
votes
1answer
52 views

Can't seem to get syntax information when in insert mode

This is for an indent function that should maintain the indentation should the cursor happen to be in a string region. It maintains the indentation when I hit == in normal mode but changes when I open ...
3
votes
3answers
1k views

How to put custom functions at bottom?

I want to organize my vimrc better, so I want to put all the custom functions at bottom: "different setting between different os if MyDetectOS() ==? "windows" set rtp+=~/vimfiles/bundle/Vundle....
4
votes
1answer
513 views

if/else condition for matching a regex in a file [duplicate]

I want to run a function with a condition that checks for ANSI color escape codes when I open files but I don't know how to write the condition. I expect it to look something like this: if ? '^[[0;...
7
votes
2answers
689 views

Go to the next word starting with specific letter on current line

I want to have the command which is stated in the title. I looked for it in intrinsic Vim command but did not find it. I ran some tutorial online about functions in vim, The idea would be to have ...
4
votes
3answers
96 views

Save functions in a session

I have a function I wrote specifically for a certain session in vim. Manually redefining it every time I load the session is tedious. Is there any way custom functions can be saved with the session? ...
1
vote
1answer
497 views

How do I use input() to get the name of a new composer project from the user?

I often start new projects in the same way. I guess it exists a way to be fast a starting a project. For example: I am trying to start new composer project with the following function. I perfectly ...
4
votes
1answer
695 views

Call function from string name

I am trying to achieve the following : Having a set of predefined functions in my script Having a map of relation between the functions and their argument Calling the functions with their argument ...
16
votes
1answer
15k views

Why am I getting a “E488: Trailing characters” error on this custom command?

I have a ~/.vimrc that contains just this: function! NewFile() let filename = input("Filename:") endfunction command NewFile :call NewFile()<cr> (of course my real .vimrc is more ...