Vim script is the scripting language incorporated into the `vim` editor. It is based on the `ex` line editor of `vi`.
Questions tagged [vimscript]
33 questions
8
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,…
Alex Mckay
- 183
- 1
- 4
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,637
- 3
- 22
- 28
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…
Steve Vermeulen
- 567
- 4
- 14
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
- 2
- 7
- 20
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.
Annis Monadjem
- 41
- 4
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,637
- 3
- 22
- 28
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?
Steve Vermeulen
- 567
- 4
- 14
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,409
- 10
- 25
- 36
2
votes
1 answer
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
- 368
- 3
- 14
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
- 447
- 1
- 5
- 8
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
- 368
- 3
- 14
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
…
Steve Vermeulen
- 567
- 4
- 14
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…
Steve Vermeulen
- 567
- 4
- 14
2
votes
1 answer
Vim: print lines from hidden buffers
I'd like echo line from a hidden buffer without moving my cursor. Something like this:
:redir! > /tmp/myfile
:1,$print 3
:redir end
(I want to inspect hidden buffers without changing the window layout or the cursor position.)
The above works great…
So8res
- 1,521
- 1
- 18
- 30
2
votes
1 answer
Testing vimscript
I'm hacking on a test framework for vimscript (an exercise in futility, I know; humor me). Some vim plugins make calls out to the shell (with the system() function or the ! command). I want the test driver to be able to grab those calls and return…
So8res
- 1,521
- 1
- 18
- 30