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 [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.

0
votes
1answer
22 views

How can I make Vimscript check if the current line has a comment?

I want to make a Python ftplugin (but other filetypes will also have this option) where, if the previous line has a comment that starts with #, the next line can be commented via <Shift><CR&...
1
vote
1answer
24 views

Load current buffer in another pane

I'm writing a plugin where I have several buffers open in split panes ( let's call them small panes ). The user can navigate between the small pane using the usual ctrl+w , wincmd etc ways. While I ...
2
votes
1answer
29 views

How to set group of tabs and 1 single terminal in Vim 8?

I am a Vim beginner. I know you can do :tabnew file1 file2 to have Vim open up a bunch of files name file1, file2 spread across as tabs. I know you can move forward and backward between tabs. My ...
0
votes
1answer
27 views

How use a custom time value in `strftime()`

I am able to use strftime() to convert the current time to a string, but now I need to work the other way around: Convert a string to {time} Modify the time value Convert back to string Is there a ...
0
votes
0answers
32 views

An operator pending mapping [on hold]

I have added the following operator pending mappings to my vimrc. onoremap K H onoremap H ^ onoremap J L onoremap L g_ This does not do what I want it to. I tried other suggestions in :h omap-info ...
1
vote
1answer
16 views

How to do a conditional key mapping dynamically?

I know that I can do a conditional key mapping by map-expression: map [key] [condition] ? [foo] : [bar] But now my situation is somehow awkward. I want to map <C-h> to <C-w>h if I have ...
1
vote
1answer
19 views

How to have vnoremap call function once?

I'm trying to write a function + map that works on a visual selection. My function just prints out the marks right now: let g:count = 0 function! s:plink(...) abort let g:count = g:count + 1 ...
0
votes
0answers
27 views

How to get the current word starting from the cursor?

In vimscript expand('<cword>') gives me the word under the cursor. How can I get the word under the cursor starting at he current cursor location (skipping the word start).
0
votes
1answer
33 views

Call function with count after performing some normal! level tasks

I have this following function " copy yanked text to tmux pane function! Send_to_tmux(count) range if (a:firstline == a:lastline) execute "normal! \"zyip" else execute "normal!...
3
votes
1answer
40 views

jobstart callback wont assign variable outside of function

I have a job I want to run in the background of vim, and update my status line with the periodic results of that job. I'm able to setup the timer, call the external job and get my response back. I'm ...
0
votes
1answer
40 views

Vim disables syntax highlighting after execution `autocmd BufAdd * exe 'buffer ' . expand('<abuf>')`

Following code switches off Vim syntax highlighting for buffers opened after its execution. autocmd BufAdd * exe 'buffer ' . expand('<abuf>') Why? Is it bug?
1
vote
0answers
22 views

May I let `titlestring` tell whether I am in command-line mode?

Following from this post, I can happily "project" character n to the titlestring when Vim is in Normal-mode, and "project" character i to the titlestring when Vim is in Insert-mode. This almost ...
0
votes
0answers
39 views

Why does this autocommand works on neovim but not on vim?

I have this little augroup that contains a simple autocommand that hides the /home/devs/ text on top of nerdtree: augroup HideHOME autocmd! FileType nerdtree autocmd FileType nerdtree syntax ...
0
votes
0answers
15 views

Fuzzy / smart / intellisense completion in input mode

Standard Vim completion supposes that you type in the beginning of the word, then press CTRL-N, and get all the words that begin with the prefix you typed in. In my situation, prefixes are mostly the ...
0
votes
1answer
45 views

Display the first line of some file instead of an identifier

Is there some way to display an identifier as something else? Imagine the following setup: You have a readme file: * <<123456>> * <<789078>> This readme file is inside of a ...
1
vote
1answer
34 views

function: sort output alphabetically

This function outputs data between braces as joined lines in a quickfix window. The output is sorted based on line numbers. I'm searching for a method to sort the data alphabetically. I tried to ...
1
vote
2answers
38 views

How to detect running in intellij in vimrc?

I have some plugins I would prefer load by default in the terminal, and cause performance issues or ux glitches in jetbrains ides running ideavim. Neovim needs to start getting adopted, but that's an ...
0
votes
0answers
20 views

How to get the same message and error behavior as normal `n` when calling `normal n` in function

I wrote a vimscript function that prevents the cursor from changing its location on the screen when I press n: function! my_n() let l:start=line("w0") let end = line("w$") let cursor = ...
-1
votes
1answer
18 views

How to edit multiple files with same scriptin/scriptout using vim

When I use a command like vim -s script *.cfg it stops at the end of first file stating that there are x files left to edit and not executing the script in the remaining matching files. script ...
1
vote
0answers
20 views

How to write to a temproary buffer in a plugin

I've started to write my first vim plugin, a simple timer. I want to be able to set a timer for an arbitrary amount of time, and have it notify me once that time has passed. I've got it all working, ...
2
votes
2answers
66 views

How to make vim open two windows when opening a directory or file with netrw?

I want to achieve two effects about using the netrw plugin for vim. EFFECT ONE: I have a test directory.Here is its directory structure: MINGW64 ~/test $ ll total 1 drwxr-xr-x 1 uooki2 197121 0 一月 ...
0
votes
1answer
22 views

Using %:p when path has space in it

I have this bit of vim script: nmap <F9> :w<cr> \:execute 'silent !tmux new -ds blah'<cr> \:execute "silent !tmux send-keys -t blah '%:p' Enter"<cr> \:execute 'silent !...
0
votes
0answers
21 views

How to show “/foobar match 1 of ” or “E486: Pattern not found: foobar” in commandline when calling `normal! n` in function [duplicate]

I'm calling normal! n in a vimscript function. If there is a match, I don't get the message /foobar match 1 of 3 in the commandline. If there is no match, my commandline shortly flickers up and down ...
0
votes
0answers
28 views

Is there a C++ format plugin just like Visual Studio

Coding C++ in Visual Studio, if you type ;, this line will be formatted. For example, typing a ; after int i= 1+ 2 will make this line as int i = 1 + 2;, which means that each operator is surrounded ...
0
votes
0answers
38 views

command: how to avoid “Press ENTER or type command to continue”

In my .vimrc, I set a shortcut: command Q call delete('.ycm_extra_conf.py')|call delete('.tags')|qa Now I can type :Q + [enter] to delete the two files and quit all plugins and vim. However, if I ...
2
votes
1answer
225 views

How to get rid of “Press ENTER or type command to continue”

I'm using ctags to code C++ with vim. I set two shortcuts of ctags as below: autocmd VimEnter * silent! !eval 'ctags -R --c++-kinds=+p --fields=+iaS --extras=+q --language-force=C++ -o newtags; mv ...
2
votes
1answer
35 views

Not displaying ErrorMsg for long lines only with tex, md and calendar buffers

I use and love the plugin calendar.vim. Those days, I decided to add the following to my vimrc: autocmd BufEnter *.tex,*.md call matchdelete(4) autocmd BufLeave *.tex,*.md call matchadd("ErrorMsg", "\...
0
votes
1answer
28 views

How to print a message after `autocmd` is done

I'm using ctags to generate tag file so that I can jump to declaration or to definition while working with C/C++ project. To make ctags work automatically while entering vim, I add such a line in my ...
1
vote
1answer
30 views

How to create or modify vim commands?

In Vim wrapping lines at 80 characters without breaking words can be done with the following commands according to this article: :set formatoptions+=w :set tw=80 gggqG Setting 80 char wrap is ...
0
votes
1answer
59 views

Vim can't search for dot

I'm trying to write a Vim script function to toggle between -> and . but searching for . is seemingly impossible. I've tried to search using ASCII (decimal and hex) and it doesn't work. It all ...
2
votes
1answer
101 views

UltiSnips, Context and Tex

For best experience, I want to enable some snippets to be expanded only in Tex Math environments. A wonderful person, lacygoill helped me on GitHub to achieve just this with the following setup: Let ...
1
vote
0answers
31 views

display list of buffers `ls` without scrolling down

Is there a way to display output at the bottom of the screen like ls does, but without scrolling down to accomodate the output? The Vim Wiki (no https) has the following snippet :nnoremap <A-n>...
2
votes
2answers
54 views

A vim plugin like FLOWSTATE

Is there a way to make vim behave like the app flowstate? What this app does is forces the user to type continuously without pause for a certain period of time (which is very useful for brainstorming)...
0
votes
1answer
15 views

Function arguments + shell

I'm trying to write a command for adding a Python import line. The problem is that what's added it import a:name and not the module name. Here's the code func! PyImport(name) w silent !isort ...
0
votes
1answer
22 views

vimL, how to get alternate window's current buffer number

Say, with 2 windows open in vim, cursor is window 2, how can I get the current buffer of the alternate window (window 1 in this case)?
0
votes
1answer
28 views

Capture the next keypress under 200ms

1) I need to capture the next key press from the keyboard, if there are any in 200 millisecond. Which function should I use to achieve this? 2) Basically I need to re-send the captured key, with some ...
1
vote
1answer
45 views

Vim: Replace visual selection without overwriting the unnamed register

How do I replace a visual selection with some register content without overwriting the unnamed ("") register by the visual selection? The question https://stackoverflow.com/questions/3837772/vim-...
1
vote
0answers
30 views

Integrating ranger into neovim

I am trying to get ranger working inside neovim in a sensible way. The official vim plugin provided by ranger works perfectly in ordinary vim: <Leader>r launches ranger in full screen, q exits ...
1
vote
1answer
44 views

How do I make this vimscript function (taken from another question here) 'forget' about a previous search term?

Based on the accepted answer to this previous question, I put the code below in my .vimrc, which changes the color of my statusline depending on whether my search (started with / or ?) yields results ...
0
votes
1answer
63 views

matchstr() acts differently when used in script?

I have these lines in a script: " go to start of file and search until the end call cursor([1,1]) let moreLinesToGo = v:true let b:qtags = [] while (moreLinesToGo) " search for lines like ":344f:",...
0
votes
1answer
36 views

How to get writefile() to pay attention to &nofixeol?

I want to write the contents of a buffer with writefile(). However I do not want to use binary mode because I suspect it has (undocumented) side effects. My question concerns noeol files, i.e. files ...
0
votes
1answer
32 views

How to parse a string to a list?

Is there a way in Vim to do the following: let S = '[''123'', ''456'', ''789'']' let L = parseStringToList(S) " L is a list containing the string '123', '456', and '789'
2
votes
1answer
27 views

Swapping two vim mappings

I have added the following the mappings to my vimrc. I want K to take me to the top line of the window and H to take me to the first non-empty character of the line. nmap K H nmap H ^ nmap J L nmap L ...
0
votes
1answer
35 views

Why does `:call f(…)` do nothing while mapping it to a binding works?

I'm not really sure how to describe this behavior better than with the example I'm dealing with. I'm trying to write a custom completion using fzf-vim ... and as I'm looking through the documentation,...
1
vote
1answer
131 views

What is the difference of using `au BufNewFile,BufRead *.py` and `au Filetype python` in .vimrc?

As I am setting .vimrc, I found these two code blocks have the same functionality. au Filetype python set \ tabstop=4 \ softtabstop=4 \ shiftwidth=4 \ textwidth=79 and au ...
1
vote
1answer
70 views

Unmapping filetype mappings

I'm trying to unmap some key sequences mapped by python filetype plugin. While I know a better way, I'm still curious if it can be done with autocommands. Here's what I've got so far: augroup ...
0
votes
1answer
60 views

Get the column that the cursor is on in vimscript

In vimscript, how can I get the column that the cursor is currently on? I would like to save this value in a variable.
2
votes
1answer
61 views

How to yank count of matches of a pattern to a register?

%s///n show number of matching pattern like 102 matches on 102 lines. How to copy this output to a register?
0
votes
1answer
42 views

How to use fnamemodify to return dirname/filename?

I am using vim-airline and buffer tabline. I want to make the tab name become dirname/filename. How to achieve it? For example :ec fnamemodify('/usr/lib/abc/file.sh', '<something>') should ...
2
votes
6answers
80 views

Indent on New Line between HTML/XML Tags

I'm currently using imap <silent> <C-c> </<C-X><C-O><C-X><Esc>F<i as per this post and this page to close <></> tags of any kind with <C-c&...