Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [functions]

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

5
votes
1answer
389 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
252 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 ...
4
votes
1answer
68 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 ...
2
votes
1answer
49 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 ...
5
votes
2answers
2k views

How to wait for user input in the middle of a mapping?

I want to make a mapping that does the following: nnoremap <F1> oHello, (user inputs their name. Ex. Jason). You have a very nice name.<ESC> This mapping should make a non-recursive map ...
4
votes
1answer
100 views

Can my mapping/function detect when count/range 1 is given instead of none?

I have a key mapped to a command which runs a function, and I would like to detect whether it has been passed a range (prefixed with a count) or not. The difficultly is that I need to be able to ...
4
votes
1answer
492 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;...
4
votes
4answers
1k views

How to pass control characters, e.g. <c-e> to a function in a mapping?

I often find myself accidentally pressing <c-e>/^E while in normal mode inside a terminal buffer. This causes the terminal buffer to scroll down and a line with a ~ is displayed, like when your ...
7
votes
2answers
664 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 ...
5
votes
3answers
404 views

Making a custom function to comment out a range of lines

I want to make block commenting easy. To comment out a range of lines, what I can do is something like: :17,21s/^/# This will comment lines 17 to 21 in Python. But I don't want to write the whole ...
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
3answers
90 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? ...
4
votes
1answer
577 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 ...
1
vote
1answer
452 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 ...
16
votes
1answer
13k 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 ...