Vimscript is the scripting language built into the text editor Vim. It can also be referred to as "Vim Language" or "VimL".
1
vote
1answer
37 views
Is there a way to map Control + 6 or Shift + Control + ^ to a leader key?
Control + 6 or Shift + Control + ^ will switch between the current file and the alternate file in vim. Its useful but I hate using the Control key and try to avoid it if possible. However, despite ...
-1
votes
1answer
38 views
How to check if 1 (or more) variables out of a set of variables is equal to a value?
I can't find out how to check if 1 (or more) variables out of a set of variables is equal to a value:
p.e.
let linecurr = getline(endlijn-line)
let lineabov = getline(endlijn-line-1)
if ...
0
votes
2answers
28 views
Don't wrap certain lines
I'm using conceal in a plugin to hide some data, but when the hidden line gets too long it makes a wrap which is still hidden and just looks weird.
how it looks:
<hidden metadata line that the ...
0
votes
1answer
43 views
Find out vim executable name inside vimrc
I share my ~/.vimrc file between different computers and use it with three different vims (macvim in mac, gvim in my Ubuntu desktop and plain old vim in the servers which I manage)
Most of what I ...
0
votes
3answers
39 views
How to get the value of the current swap directory in vimscript?
You can set a list of directories for vim to use for the swapfile (with it defaulting to the first one it can find) with:
set directory=~/tmp,~/var/tmp,/var/tmp,/tmp
I want to know which directory ...
0
votes
2answers
52 views
How to test if there is only default buffer open?
I'm writing a plugin that loads sessions only if no buffers have been open. So far I'm testing vs argc.
if (argc() != 0)
return
endif
This works fine if I pass in arguments from the command ...
5
votes
1answer
63 views
Why would “\n” become “^@” when writing Python in a .vim file?
For example, here is my function:
function! Test()
python << EOF
import vim
str = "\n\n"
vim.command("let rs = append(line('$'), '%s')"%str)
EOF
endfunction
and when I :call Test() , what I ...
-1
votes
2answers
62 views
how to understand these vim scripts
I have two question about understand those vim script. please give some help,
Question 1:
I download a.vim plugin, and i try to read this plugin, how to understand the below variable definition? the ...
0
votes
1answer
47 views
How do I get the value returned from a function in Python & Vimscript?
I'm using Python to write a vim plugin, but there's something wrong when dealing with Vimscript.
function! Login()
python << EOF
import vim, weibo
appkey = 'xxx'
appsecret = 'xxxxx'
...
0
votes
1answer
34 views
Improve TwiddleCase function to work in visual block mode
The following snippet can be found on the vim wiki:
function! TwiddleCase(str)
if a:str ==# toupper(a:str)
let result = tolower(a:str)
elseif a:str ==# tolower(a:str)
let result = ...
0
votes
0answers
27 views
vim autocomplete: disable the need to accept autocompletion choice
Is there a way to set vim autocompletion (called by using standard ctrl-p hotkey) so that I don't have to press enter to accept the choice? I know that YouCompleteMe plugin does that kind of thing, ...
2
votes
1answer
34 views
When custom mapping is set for :cn, :cp vim doesn't expand the fold that contains an error
I have noticed that when I use :cn :cp directly, vim always expands folds for me. But when I set my custom mapping to call :cn like :map <leader>n :cn<cr>, vim doesn't expand foldings when ...
2
votes
2answers
48 views
How to detect if Vim is running in restricted mode?
... or in any mode for that matter.
I just want to prevent some extensions from loading when that is the case, something like:
if ! currentmode('restricted')
Bundle('some-extension')
endif
0
votes
2answers
45 views
How to replace the contents of the current buffer with the contents of a file?
I have an external script that takes a Javascript file and automatically fixes some style issues, I want to apply it to the current buffer right before writing (BufWritePre,FileWritePre).
So my idea ...
1
vote
2answers
46 views
vim function external call
Currently my vimrc has the following key mappings:
map <leader>m :w\|!clear && rspec --drb %<cr>
map <leader>k :w\|!clear && rspec --drb ...
3
votes
1answer
74 views
How to go to the end of the file in vim while preserving the current column under the cursor?
Often when I use a visual mode, I would like to expand the selection to the whole file. But hitting VG takes me to the first character of the last line. I would like it to take me to the same column ...
0
votes
1answer
29 views
In vim, how do I redirect the output of a vimscript function?
I have this vimscript function
function! Env()
redir => s
sil! exe "norm!:ec$\<c-a>'\<c-b>\<right>\<right>\<del>'\<cr>"
redir END
return ...
0
votes
1answer
48 views
Comment out code using vimscript
Hi Im trying to write my first vim script. I want to write a funtion that will comment out PHP code by the block or curly brackets.
Here is what I've come up with, but I can't get it to work:
...
0
votes
0answers
15 views
Highlighting for viml in latex? [migrated]
I googled around but did not get any good result, as google does not understand what I want. So maybe it is my fault because I don't know how to use google, or it is googles fault because it is not ...
0
votes
1answer
41 views
how to highlight quickfix result keyword?
Normally, when use vim with cscope, it display the search results in quickfix window at the bottom.
when type :cn in the commandline, it will jump to the beginning of line which contains the keyword.
...
1
vote
0answers
52 views
Write a command to increase or decrease the number of vertical splits
I usually have my Vim screen split into two vertical windows, each of which may be further horizontally split. Sometimes, I want to add or delete a vertical window. Is there a way to detect how many ...
2
votes
1answer
91 views
vim how to use rubycomplete with supertab
I installed vim-ruby through pathogen. I think I should be able to use rubycomplete, which is included in the vim-ruby, after installing it, but I am not.
there is not any error, I just can't use ...
0
votes
2answers
41 views
vimscript how to get the parent directory of a path string
I want to do the same thing as the bash dirname command or python os.path.split()[0] in vimscript for any path string (not necessarily the path of the current file).
Sample desired behaviour:
/a/b/ ...
0
votes
1answer
39 views
Is there any way to autoindent a section of text in vimscript?
I'd like to autoindent a range of lines in a Vim plugin I'm writing, but there doesn't seem to be an easy way. Short of an actual vimscript command, I've been looking for ex-mode commands I could use ...
1
vote
1answer
31 views
How to create an alias for ctags in vimscript
I have a function that is invoked based on a simple key mapping
function! JumpToDefinition()
let filetype=&ft
if filetype == 'coffee'
exe '<C-]>'
endif
endfunction
...
1
vote
2answers
85 views
Edit multiple files in 1 vim buffer
I'm making a vim script to take notes, and it should be tag aware.
So when I add a note it should appear under all the correct sections like this:
To avoid making lots of copies of the same text ...
0
votes
2answers
20 views
How to get mapped values in Vim and save them
Let's say I have the next mapping:
imap a AAA
vmap b BBB
I need a way to get value of mappings.
The next is not suitable for me, because I need to operate by returned mapped values:
imap a
vmap b
...
1
vote
1answer
55 views
What is the command in vi editor to covert column of numbers into row?
This is currently what i am dealing with:
$cat k
23
22
35
24
42
:
:
36
I have file like this and I want to use vim convert it like this.
22,23,35,24,42,8,......,36
Please Help
1
vote
0answers
67 views
How to emulate :autocmd VisualLeave * or :autocmd VisualEnter * in vim?
As you know, there are (sadly) no VisualLeave or VisualEnter autocmds in vim. Is there a way to emulate it?
(Sidenote: Having such events would add even more power to vim)
2
votes
3answers
43 views
VIM: Optional line range for command / function
I have this in my .vimrc to remove trailing whitespace:
function! RemoveTrailingWhitespace()
for lineno in range(a:firstline, a:lastline)
let line = getline(lineno)
let cleanLine = ...
2
votes
2answers
78 views
VIM: Change cursor to underscore in normal mode
One nice feature of Sublime Text's Vintage Mode is that entering normal mode makes an underscore under the character you are one, rather than the standard cursor that highlights the current character ...
2
votes
1answer
46 views
setting the cursor to a vertical thin line in vim not working
I am trying to set the cursor in insert mode to be a thin vertical line and I am unable to. I have tried this:
set guicursor+=i:ver100-iCursor
to no avail.
What am I missing?
0
votes
3answers
62 views
How does .vimrc set its own filetype?
In response to this question on SuperUser, I wrote a small vimscript that will detect the filetype of a symbolic link and change the syntax highlighting:
au BufNewFile,BufRead * if &syntax == ...
1
vote
2answers
64 views
How to enable map command in vim?
How to enable map command only when filetype is 'perl'?
something like:
if(&ft=='perl')
map ,pt <ESC>:%! perltidy<CR>
endif
but it doesn't work.
3
votes
1answer
53 views
Superpose two vim syntax matches on the same character
I'm defining the following syntax rules in a vimscript:
hi MyBold term=bold gui=bold
hi MyRed ctermfg=red guifg=#ff0000
And later on, I want to apply both highlights to the same character. So ...
0
votes
1answer
54 views
How to check existence of swap file in .vimrc?
I have in my home directory on Windows a task.otl, which is a kind of Todo list, using the vim-outliner format.
When launching gvim without argument, I automatically load it. However, I would like to ...
0
votes
3answers
71 views
GVim/Vim. How to delete all white space up to a certain word
I'm a .Net dev but recently started dabbling with Vim (or in my instance GVim) for when I need to do repetitive text editor type tasks.
My experience is basically non-existent. So please bear with ...
4
votes
2answers
45 views
Can I create unlimited marks with vim?
I'd like to be able to set additional marks to the already existing single lettered marks. Thus, I could solve two problemes I am currently facing:
the marks are set in a script and I don't want to ...
1
vote
2answers
45 views
Vim - get output of EX mode into a variable
I'm writing a vim script where I need to get the first line of the current buffer. In Ex mode I can simply type 1 and it shows me the content I want.
How can I put the output of the ex command into a ...
1
vote
3answers
64 views
.vimrc script for opening a web link from VIM
I would like to setup .vimrc, such that I can open a weblink from inside the vim editor. Any good examples?
1
vote
3answers
39 views
How do I get Vim to test if user input is an integer?
I'm sure this is probably a simple problem, but I'm stuck. I need to write a small Vim scripting program that asks for input from the user. If the user enters an integer then the program continues. If ...
3
votes
2answers
73 views
How to pass arguments from :command to function?
I want to write a command, this command would have this format:
[range]MyCMD[!] [count] [oneArg] [flags]
or
[range]MyCMD[!] [oneArg] [count] [flags]
similiar to
:[range]P[rint] [count] [flags]
...
1
vote
1answer
28 views
Calling autoloaded dictionary functions from other autoloaded dictionary functions in VimL (vimscript)
Is it possible to invoke an autoloaded dictionary function from within another autoloaded dictionary function in Vim script?
I want to have something like this in autoload/foo.vim:
function! ...
1
vote
2answers
43 views
How to map a sequence in vim conditionally to run external programs without printing the else clause
How can I map a sequence in vim conditionally to run any of two external programs in such way that the screen is not cleared to show the else clause?
For example:
:nmap <c-l> :if ...
2
votes
1answer
49 views
Automatic unfold small folds
Is there a way to automatic unfold small folds (<10 lines) when using foldmethod=syntax?
I understand that there would be the option to use
set foldminlines=10
But if I use this setting, I ...
1
vote
1answer
48 views
How to automatically insert braces after starting a code block in vim?
It's really easy to insert a closing brace after typing the opening one:
inoremap { {<CR>}<Esc>ko
This way
if (true) {
converts to
if (true) {
|
}
But I'd like to save time and ...
1
vote
2answers
28 views
Is it possible for a “range” function to return a value
The following simple function is supposed to count and return the number of lines that are visually selected:
fu! TQ84_fu_test() range
return line("'> ") - line("'<") + 1
endfu
If I ...
3
votes
2answers
97 views
Automate running several vim commands and keystrokes
I want to automate running several commands in vim, i.e. by typing :repl. The commands are:
:ConqueTerm lein repl
<Esc>
:set syntax=clojure
<i>
How do I define a custom vim function ...
0
votes
2answers
51 views
Vim highlighting nested regions
I'm working with vim for several months now, and I still try to improve my experience with this great editor.
What I try to do is to create a syntax highlighting file for spice netlists (electronic ...
7
votes
2answers
105 views
VIM : What is the difference between let g: , let b: , etc
I often see in vim plugin something like these :
let g:variable
let b:variable
let l:variable
I made a long research on the vim documentation and on the Internet about these letters 'g', 'b', 'l', ...