Questions tagged [vimscript]

Vim script is the scripting language incorporated into the vim editor. It is based on the ex line editor of vi.

33 questions
10
votes
1 answer

Vim - can I pass multiple args to a custom command without writing a function

I have written following custom command in my .vimrc file: command! -nargs=+ Sub :%s//g It allows me to substitute one word for another and is executed like this: :Sub / I would prefer to write commands with multiple args,…
7
votes
4 answers

Vim Visual mode: Select current block under cursor

Considering we have the current data: ID NAME AGE 1 Joan 29 2 Peterson 16 3 Hunt 47 4 Wenche 12 5 Kennedy 29 6 Lottie 31 And the cursor is the on the N in NAME,…
krystah
  • 1,697
5
votes
2 answers

Vim Script: Is it possible to refer to script-local variables in mappings?

I know that you can refer to script-local functions using but what about script-local variables? I tried the following, and hitting fails: let s:testVar = "foo" function! s:GetTestVar() return s:testVar endfunction nnoremap…
4
votes
1 answer

Check if vim is compiled with +X11 in .vimrc

I have two copies of vim installed. One is installed with macvim and necessarily configured with -X11 (to work with Cocoa), while the other is configured to +X11 (used in terminal, to work with a plugin I use) I would like all yanks to go to the…
Jeff
  • 642
3
votes
1 answer

How can I take control over jumps `Ctrl-O` and `Ctrl-I` in Vimscript?

Is there any way I could use Vimscript to go through the list of jumps Ctrl-O, Ctrl-I and to pick the previous jump buffers/positions? Any suggestion is greatly appreciated.
3
votes
1 answer

Vimscript: how can I call a function but wait for user input before executing it?

In the right-hand-side of a keymapping, you can do something like :call FileTypeToggle("") to start a function call at the command line, move the cursor in between the quotes, and wait for the user to fill in the argument and hit
ivan
  • 1,145
3
votes
1 answer

Vimscript: Error while checking for substring

I am currently trying to tie together a function to do something depending on current file path, triggered whenever I change the current buffer with autocmd BufEnter In my .vimrc autocmd BufEnter * call SayLocation() Further down in my .vimrc fun…
krystah
  • 1,697
3
votes
2 answers

Vim: How do you get the change list in script?

I know that you can print the changelist by running :changes. Is there a way to get this information in vimscript? Even by parsing the print somehow?
2
votes
3 answers

Command to "go to end of last line that has content, in insert mode"

With plaintext files, when I reopen them in Vim to add content, I want to go to the end of the last line of content and get to insert mode. In ideal circumstances, a simple GA after opening the file would take care of this. Unfortunately, I have the…
Sundar R
  • 1,539
2
votes
2 answers

vim find buffer by absolute path

How can I find a buffer in vimscript when I have an absolute path, and as you know vim buffer names can be relative path? Is there a function for that?
user14416
  • 378
2
votes
1 answer

Vim inserting C style comments

:command Linecomment :normal ^i/*$a*/ The above command is one that I came up with in order to comment out an entire line in C, normally for debugging purposes and whatnot. I was wondering what sort of modifications would be needed to…
2
votes
2 answers

Movement command inside vim functions

I want to display the C function to which current line belongs. I don't want to use any plugin because I work on multiple operating systems with different machine capabilities and configurations. I have tried most plugins and it doesn't work out for…
thequark
  • 457
2
votes
1 answer

Vim region with keywords in syntax patterns

I need to create a custom vim region with determines classes and structs. The code, for example, syn region myCxxClass start="\(class\|struct\)\_[ \t]\+" end="}[^;]*;" transparent The patterns for start and end probably will be changed, but the…
user14416
  • 378
2
votes
1 answer

Vim Script: Is it possible to make a custom motion non-repeatable?

I'm trying to write a custom yank function but am unable to figure out how to make it non-repeatable (like the normal yank). I have something similar to the following: function! s:YankMotion(type) if a:type ==# 'line' normal! `[V`]y …
2
votes
3 answers

VIM: Is it possible to add custom behavior when using /c with the substitute command?

There's been a few cases where it would be convenient to hook into the search and replace behavior for certain things. For example, I have the following mapping in my vimrc: nnoremap n nzzzv Which centers the screen every time you advance to the…
1
2 3