Questions tagged [vimscript]

A scripting language embedded into Vim. It can be used to customize Vim to suit your needs and to create plugins. Also called VimL.

5
votes
1answer
66 views

Can I block vim from saving a file that isn't validated using an outside tool?

I'm trying to find out if it's possible to make the write ":w" command perform a forced validation for certain file types. My use case is that I want to prevent small typos and idention errors in ...
2
votes
1answer
208 views

VimScript “unknown function” on a lot of functions

So I have been writing a vim extension but it simply does not make sense to me. I am using nvim and clearly see the function chansend in the documentation yet I get "Unknown function: chansend" when ...
2
votes
1answer
86 views

Convert a search and replace to a function

Given this search and replace expression, which works fine on one or multiple visually selected lines: :'<,'>s/\v.{-}(`.{-}`).{-}(\\'.{-}\\').*/$this->execSQL('DELETE FROM \1 WHERE id = \2;')...
1
vote
1answer
81 views

BufNewFile doesn't work from ftplugin

I have below autocmd in my cobol.vim ftplugin file in ~/.vim/ftplugin/ augroup cobmods autocmd! autocmd BufNewFile * call s:CleanStart() augroup END This doesn't work when I open a file ...
3
votes
1answer
70 views

Is loadview conflicted with readonly mode?

When i used following code to keep my folder view, it seemed that vim -R and view don't work at all (Only [readonly] was shown but it didn't work at all). Is there any misunderstanding about it? " ...
2
votes
0answers
27 views

How to make YouCompleteMe work with cgo

In C, YouCompleteMe could autocomplte the function if I include the header file in code: I want it work like C, when I write Go code and include the C header file in cgo: So, how should I config ...
0
votes
1answer
124 views

Call vimscript function on first keypress

Is there a way to call arbitrary vimscript functions when the first keypress is made by the user? I am looking to lazily start-up plug-in when the user starts using vim. This is to save resources ...
1
vote
1answer
52 views

How can I determine if *any* window in the current tabpage is in diff-mode?

So, I found this useful answer about iterating buffers; but due to the tabpage-specific duality of windows in Vim, I failed at adapting it to my needs. Thus: how can I construct a boolean expression, ...
0
votes
1answer
42 views

Command Ordering

I made a user command called Type and would like it to appear first in the list of available commands when I type :t and then hit tab. Currently, the first command is TOhtml, which I've never used. ...
3
votes
0answers
125 views

How do I call functions and commands from .vim files in Vader tests?

I am trying to write tests using Vader plugin but unfortunately, every time I try to invoke a command/function in Execute/Do block it doesn't see seems to work on the text provided in Given block! # ...
3
votes
2answers
116 views

Use current filename register in bash command ran from VIM

I'm making a command that runs tests and opens coverage report for the currently opened file. nnoremap cov :!vendor/phpunit/phpunit/phpunit --coverage-html \ /tmp/coverage/ test/ && google-...
2
votes
1answer
66 views

Execution of nnoremap takes significant time

I am developing a vim plugin and I have set a default mapping this way. if !hasmapto('<Plug>DumpDebugString') nmap <unique> <Leader>ds <Plug>DumpDebugString nmap <...
0
votes
1answer
478 views

How do I insert value of a 'vim global variable' or 'vim internal commands' in text?

I have multiple vim global variables declared in .vimrc file like let g:wiki_list = {some dictionary ...} I am able to echo its output in vim exec window using :echo wiki_list BUT How do I read/...
4
votes
1answer
216 views

Switch to viewport by name?

Typing :buffers gives a list of loaded buffers. Can I switch to a viewport that views one of those buffers by name? I know that :buffer NAME will load the named buffer in the current viewport. But I ...
1
vote
1answer
114 views

Visual mode toggle block commenting with vimrc command

I am trying to get vim to do block commenting and uncommenting of highlighted lines while keeping the correct indentation level. I am so frustratingly close. let b:commentChar='//' autocmd ...
2
votes
1answer
316 views

Trouble using <cword> in mapping

I'm trying to pass the word under the cursor to gtags and chain the definition search and the reference search together using a single function key. My understanding is that this should work: ...
2
votes
1answer
725 views

How can I use a string variables for filepath in vimscript map command?

I have multiple lines like the once below in .vimrc file. nnoremap \html :-1read $HOME/.vim/snippets/html_basic.snippet<CR> nnoremap \bs :-1read $HOME/.vim/snippets/bootstrap.snippet<CR>...
3
votes
1answer
226 views

What are/could be the potential advantages of learning VimL or vim scripting language? [closed]

I have been using VIM for quite some time now and I wish to level up my VIM skills. I have started going through some VimL or vim script as it's called. To motivate me further, I am just curious to ...
1
vote
1answer
75 views

remove automatic '<,'> when hitting colon in visual mode

This problem started because I want to run a command in visual mode with :silent! '<,'> command here however if I do a mapping vnoremap ,a :silent! '<,'> command here then in vim runs ...
0
votes
1answer
130 views

Convert newline to something else in variable using substitute

Inside of a variable, a newline is encoded as ^@ which represents a null byte. In the vim Ex command line it is possible to issue something like substitute(var, '^@', '\\n', 'g'), this produces \n ...
2
votes
0answers
53 views

Is it possible to develop decent plugins using Ruby?

I've been playing around trying to learn VimL and to do so, I'm toying with the Evernote Ruby SDK to do basic stuff. Is there a reference manual where to find a full Ruby bindings guide or something ...
0
votes
2answers
409 views

How to write the output of scriptnames into a file? [duplicate]

:scriptnames can list all plugins installed in my vim. How to write the output of scriptnames into a file? :scriptnames > names.txt It can't do the trick.
4
votes
1answer
122 views

Why vim plugins have a check on &cp

I'm trying to wrap my head around vim plugin development and I see a constant check on a variable to see if the plugin has already been loaded like: if exists('g:loaded_plugin') || &cp finish ...
2
votes
0answers
60 views

Implement “Press any key to close” in neovim terminal buffer

When running shell commands in a terminal buffer I often just want to examine the output, and then close the buffer. Let's say I call :term ls. How would I implement a simple "Press any key to close" ...
2
votes
1answer
119 views

How to use “FocusGained” to stop my cursor from moving

I tend to use GVim a lot. Very frequently, I'll click on some other window and then when I click on vim to regain focus, my cursor will end up in some random location depending on where I clicked. I ...
1
vote
1answer
50 views

How to transform this mapping into a function?

So I made this mapping "%p$?/<CR>d$V"uy:cd <C-r>u<CR> That is the crux of the mapping but it leaves artifacts in the current file, that is part of what I want to avoid. My attempt ...
3
votes
1answer
134 views

How to test if certain event is supported?

I want to test in a script if this version of vim supports the "CmdlineEnter" event. This is a relatively new addition in vim and neovim doesn't support it in it's current 0.2.2 version (although ...
0
votes
1answer
287 views

Why does vim not highlighting leading and trailing spaces? [duplicate]

I want trailing and leading whitespaces to be highlighted by vim. I created a ~/.vimrc file and appended this: " highlight trailing and leading whitespaces highlight TrailingWhitespaces ctermbg=red ...
0
votes
1answer
169 views

Learning vimscripting and functions

Can you help me how this function does what it does, like step by step? function! GitBranch() return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'") endfunction I ...
0
votes
1answer
147 views

Persistent conceal settings through Vim / Neovim restarts

I can successfully toggle between different conceal levels in Neovim, which is rather handy when working with markdown documents. Also, when working with with multiple documents in a Neovim session, ...
1
vote
2answers
58 views

How can I toggle between three predefined positions?

I am trying to create an Emacs like Ctrl-l feature, similar to Vim's H, M and L. For those who don't now, these keys jump to top, middle, and bottom of the window. I already have something but I am ...
0
votes
1answer
51 views

How to NOT create a view and session file when viewing man pages

I recently discovered the world of vim session files, and they are awesome for working with multi-file code projects. However, when opening a man page I don't need a session file created for viewing ...
0
votes
1answer
38 views

Vim not using variable value when changing a setting

I have the following vimscript: let g:base_path="~/.config/nvim/" let g:plugins_path=base_path."plugins/" let g:repos_path=plugins_path."repos/github.com/" set runtimepath+=g:repos_path."Shougo/dein....
0
votes
1answer
81 views

Automatically inserted timestamp no longer working

I use the following code function! LastModified() if &modified let save_cursor = getpos(".") let n = min([6, line("$")]) keepjumps execute '"1," . n . "s#^% Modified:\zs.*# " . ...
0
votes
3answers
65 views

mystery cursor motion

I hope someone can riddle me this one: I have set up the function below to have a slightly more fancy behavior of the End key, moving first to the end of the line, but if the cursor is already at the ...
2
votes
1answer
40 views

What are suggested ways to modify a plugin that was installed by vim-plug?

Suppose there is a particular plugin that I wanna tweak part of its functionality (and it is not under active development anymore), I'd like to test the modified version without pushing to my forked ...
1
vote
0answers
424 views

Calling vimscript functions from inside functions?

Could somebody explain me what happens here? I want to get my plugin update the airline at the MpcAdd function call. Yet, no calls seem to work from inside the function. The MpcAdd function call is ...
0
votes
2answers
91 views

Simple modification of behavior of Home, End keys

I'm completely new to Vim scripting, so forgive me if this may seem trivial, but I would like to modify the Behavior of the Home and End keys such that, if the cursor is somewhere between the first ...
1
vote
1answer
689 views

Syntax of :endif in if-statements

I have the following code in my vimrc to compile my latex documents with <F5>: map <F5> :write <Bar> :if expand("%") == "body.tex" <bar> :exe ':!arara -v "main.tex"' <cr>...
1
vote
0answers
134 views

What encoding does :! use?

I'd like low-level control over exactly what bytes I send and receive from a process spawned from some vimscript. What encoding is used for communications with commands started with :!foo? Can I ...
1
vote
0answers
69 views

Trim/clear new line character from batch script at Windows7 with gvim

I want to put timestamp using Leaderts (\ts) I am using the following script timestamp.bat(Windows 7): @echo off cls echo|set /p=%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2% and the ...
1
vote
0answers
145 views

Issues with autocomplete in vim8

I have installed two vim plugins javacomplete2 and vim-emoji successfully but I'm not able to use their auto-prompting feature which enables the user to select an autocomplete suggestion without ...
2
votes
1answer
137 views

Vimscript, how to shorten a filename?

Given these file names, I want to get the corresponding value: Chart.js => C.j chart.js => c.j chart-type.js => ct.j ChartType.js => CT.j _chart-type.scss =>...
1
vote
1answer
86 views

How to add specific string if it is not exists in current file?

I want to add this string "declare(strict_types=1);" after <?php when I save or open a file. <?php declare(strict_types=1); If the file already contains declare(strict_types=1); don't do ...
1
vote
1answer
132 views

How to know the shell started with :terminal?

After :terminal runs, is there a way within Vim script to determine the type of shell that started with creation of the terminal ? within Vimscript, NOT via OS commands such as ps.
2
votes
1answer
128 views

Using colon-commands inside ternary expression

I have the following lines in my .vimrc let g = 0 inoremap <silent> <C-g> <C-o>:let g = !g<CR> inoremap <expr> <C-_> <C-o>(g == 0 ? :undo : :redo)<CR> ...
2
votes
6answers
3k views

How to refer to “~/vimfiles” on Windows and “~/.vim” on Linux?

Consider an answer to How do I install a plugin in Vim/vi?: call plug#begin('~/.vim/plugged') " For MS Windows, this is probably better: "call plug#begin('~/vimfiles/plugged') And more generally, ...
3
votes
1answer
2k views

What is the correct way to escape UNC paths?

Let's say there is a file \\server-42\tmp\dir\test.txt. When my plugin tries to execute this command via system() it triggers an error: cd "\\server-42\tmp\dir" && git ls-files --error-...
2
votes
2answers
92 views

How to remove lines which have lower numbers than before, and keep only the sequential?

In order to parse certain log file and make a plot of sequential numbers, I need to filter out the lines with numbers which appearing lower than in the previous lines. For example, given the list of ...
0
votes
2answers
146 views

Competitive coding template in vim macro

I want to have a vim register that pastes : #include <iostream> #include <string> #define 1e9 + 7 typedef long long ll; using namespace std; int main(int argc, char ** argv){ return 0;} ...