/r/vim

Photograph via snooOG

The place for questions and conversation on the Vim editor


Please read the rules before posting


Help:

Community:

Resources:

Tutorials and Guides:


Don't be afraid to ask questions, this sub is here for the vim community. And please those of you who deign to grace us with your vim wisdom - be kind. We are all human and vim is that cool.

/r/vim

181,703 Subscribers

7

Has anyone done anything interesting with findfunc?

:h findfunc has been out for a few months now. Has anyone found an interesting or beneficial use for it?

5 Comments
2025/02/03
17:21 UTC

1

Install CoC extensions as part of a script without getting stuck

I have a dotfiles repo where I have added a line to install all CoC extensions like this:

vim +"CocInstall coc-html coc-css coc-tsserver coc-json coc-pyright coc-sh coc-als coc-clangd"

The problem is that the command does not exit. ChatGPT tells me that since the CocInstall command is async, it cannot simply wait for it to exit, nor is there any CocInstallCompleted event it could wait for.

How can I install these extensions automatically without requiring user intervention (where I have to type :qa)?

I have seen that it is possible to outsource the installation of the extensions to vim-plug, but that seems to require a more complex installation process overall, so all in all it does not seem that attractive ...

4 Comments
2025/02/03
11:41 UTC

1

Has anyone done something interesting or useful with findfunc?

:h findfunc has been out for a few months. The examples in the docx include using glob (haven't tried) or git ls-files (have tried, but found sluggish). I`m curios if anyone has done something interesting or useful with this setting.

0 Comments
2025/02/02
18:15 UTC

5

Newbie, confused about shift + 4 and shift + 6

So, shift + 4 moves the cursor to the end, while shift + 6 sends it to the beginning.

Therefore, the smaller number (or $) which is at the same time more left positioned is used to reach the rightmost position of the line? While the higher number (or ^) is vice-verse used to reach the leftmost position of the line.

EDIT: Meanwhile: "H" and "L" do in fact respect left-right rule

What was the logic here, sounds counterproductive, what am I missing?

My keyboard reference: US ANSI 75%

25 Comments
2025/02/02
18:29 UTC

1

netrw not working with vim9script vimrc?

Hi,

Having converted my vimrc in vim9script, I found that netrw no longer opens or enter directories. Hitting Enter just moves the cursor to the line below without opening anything.

I tried using this minimal vimrc:

vim9script

set nocompatible

With no luck. Removing the vim9script line fixes the issue, so my guess is that netrw doesn't like vim9script?

I know it's not the most recommended file explorer, but to this day it was enough for my needs.

3 Comments
2025/02/02
18:00 UTC

6

vimrc using vim9script: Unknown function

Hi,

I'm trying to rewrite my vimrc using vim9script as a way to learn vim9script a little bit, and I'm already stuck while trying to define my status line function. When I try this:

def GetStatusLine(): string

return "Status line"

enddef

set statusline=%!GetStatusLine()

I get the E117 error: Unknown function: GetStatusLine. Not sure what I'm doing wrong here?

7 Comments
2025/02/02
14:09 UTC

1

Foot Trackpoint

3 Comments
2025/02/01
23:09 UTC

1

Using VimSpeak With GVim (Windows 10)

I'm trying to set up VimSpeak so I can speak editor commands to GVim in Windows 10. I cloned the repo and compiled the VimSpeak solution, and it works: I can run it and it will respond to my voice commands. However, the commands aren't sent to GVim. The video that describes how to set it up doesn't use GVim. Any help is appreciated.

0 Comments
2025/01/31
18:59 UTC

5

Ctrl mappings not working in Vim :term subinstance

Hi, is there a workaround for the fact that Ctrl mappings (eg. noremap <C-h> :bp<CR>) don't work in a Vim subinstance opened in a :term buffer of a main Vim instance?

Other mappings are working fine (<Space> etc), it's just the Ctrl ones. In this case Ctrl-h it's not executing :bp but if i enter :map <C-h> i can see it's mapped to :bp but it behaves as Ctrl-h native, sending Backspace.

Is this a known issue?

EDIT: Bingo, I found that $TERM=xterm-256color whas causing the issue, so setting it to screen-256color resolves problem. Now I need to figure the smartest way to set it on the subinstance, but that's it.

11 Comments
2025/01/31
20:39 UTC

1

local file caching for editing on unstable connections

my #1 reason for sticking with vscode over my neovim config is that for my last 2 jobs, I have had to ssh into a remote machine to develop. Editing files over that connection meant vim commands often buffering and being a generally bad editor experience

I think that something like this should exist for vim/neovim/variant. is there a solution?

4 Comments
2025/01/31
13:47 UTC

4

Wildmenu auto-open

I've migrated from nvim to vim recently and the last thing I want to configure is the wildmenu.
I've read the docs and I know there is no 'native' way to make it auto-open in each keypress.
Is there any way to script it? Did anyone accomplished it?
I've tried wilder.nvim which supports vim, but I get buggy visual artifacts at the screen that makes it unusable (when in xterm-256color and foot/kitty terms. In alacritty and/or tmux-256color it works fine, but it is unmaintaned).
Thanks

5 Comments
2025/01/31
11:13 UTC

13

I don't understand folding

I've been trying for hours to get function folding in neovim. I don't get what I'm doing wrong.

all I want is a way to toggle between having all functions folded and not.
and I want them to be automatically folded whenever I have the toggle on.
I also don't want anything inside the functions to be folded

I just cannot get this to work.

I followed the instructions on this post, but I still see folds inside the function. I don't know why, I'm losing my mind https://stackoverflow.com/questions/5074191/vim-fold-top-level-folds-only

for reference here's my config https://github.com/officiallyaninja/neovim

7 Comments
2025/01/30
19:48 UTC

12

How to teach people vim motions?

Im part of a programming club in my Uni and I'm going to be taking a class on vim motions for people interested. AFAIK I'm the only person in my uni that uses vim motions and I wanna know what the best way to teach them is.

I expect to also see a few people that don't even know what vim motions are so i'd also like some ideas on things I could show them to get them hooked (like some common text editing operations you do while programming like copying and modifying a function and showing them how much nicer it is do it using vim motions)

29 Comments
2025/01/30
16:26 UTC

12

ctrl to exit 'i'

are there any keybinds you guys find to be very good i would lose if i bind ctrl to exit insert mode? im playing around with my keyboard layout and currently i have caps set to esc but wanted to map it to control , i like exiting insert mode so close to my fingers. i know how to map it but frankly i dont know if i will miss out on some fire shortcuts.
edit: i didnt know about ctrl c and binding ctrl alone is too much of a hassle anyway, thanks

49 Comments
2025/01/29
06:59 UTC

0

Why is there no information about + and - keys anywhere other than :help?

I'm new to vim. I found out about this key when I made a typo and pressed the plus key by mistake. When I searched sites like Vim CheatSheet to find out about this key, there was no information about this key. When I looked at :help, it said "[count] lines upward/downward, on the first non-blank". I think this key is very useful, but why is it not well known?

2 Comments
2025/01/28
17:28 UTC

1

Vim takes a long time to get back after closing an application

I'm making a synthesizer on C which is something that requires a lot of memory management, which could be why it's doing that. But every time I run my program from vim and close it, it takes like a minute to get back to vim, and my computer fans speed up a lot, is it a fault of my own or is it a vim thing?

28 Comments
2025/01/28
18:44 UTC

5

Finding the right moment to load a local.vim once!

I have a setup where I load cscope with several databases, and I set the tags variables to reflect the libraries my c-code use.

Due to plugins I can't just source local.vim if it exists in the project directory from .vimrc, because then the contents is overwritten by plugins. And due to the fact that the ~/.vim/after/fplugin/c.vim is executed by some autocmd several times, if I specifiy several files on the commandline like so: vim -O file1.c file2.c there is a race condition so that any guard variables won't work and the contents of the local.vim is executed twice.

As I write this, I think I might go look after an event that happens after plugins are loaded.

Any suggestions for events to use for an autocmd that I can use to source local.vim that works after any plugins or files specified on the commandline is loaded/read are most welcome!

The idea is that local.vim should be sourced once.

Thanks!

4 Comments
2025/01/28
13:22 UTC

1

What is the best practice to debug a buggy program using pure Vim?

Pure Vim refers to Vim without any plugins, such as a setup consisting only of a .vimrc file.

The expected answer should describe the most efficient approach to perform debugging tasks under these conditions.

However, using a terminal multiplexer is allowed.

20 Comments
2025/01/28
08:13 UTC

1

Recommendations to go beyond VIM + screen.

I flip between Vim + Screen and "real" IDEs (like Intellij + the vim plugin) depending on the language.

For most languages, VIM + Gnu Screen works pretty well but it is pretty cumbersome with high numbers of files. Small things like opening a new "window", navigating and opening the file (and later going in to quit cleanly, or reload after a git pull) just get more and more tedious.

I find myself searching for language-specific IDEs for no other reason than I just want to see a file tree, double click on a file, and open that in vim.

Does anyone else feel this way? Is there a good generic text editor out there with a "project explorer" file tree view, and some vim bindings?

3 Comments
2025/01/27
21:26 UTC

1

Vim Mapping Help

I want to create a mapping which creates a mapping to edit the current file from anywhere.

nnoremap m1 :execute "nnoremap <Leader>1 :e %<cr>"

This is close but the current filename does not get expanded at the time of executing m1. Escaping the % character does not work.

Any ideas?

4 Comments
2025/01/27
18:48 UTC

3

Help with an automated action with a pattern

Hi there guys,

Hi there gys , I've got quite a little bit of a question , so basically I have a document full of ocurrences . ^js$ , that means that start javascript code . So I wanted to insert a line such as ```javascript after that ocurrence . Then keep vim checking upon the next ocurrence of a Nonwhite character been foud on the first position (^\S) On there prepend a ```

js

    // myModule.js
    export let x = 1;
    export const setX = (val) => {
      x = val;
    };

js

    // closureCreator.js
    import { x } from "./myModule.js";

    export const getX = () => x; // Close over an imported live binding

js

    import { getX } from "./closureCreator.js";
    import { setX } from "./myModule.js";

    console.log(getX()); // 1
    setX(2);
    console.log(getX()); // 2

Creating closures in loops: A common mistake



SHOULD BE

js
\`\`\`javascript

    // myModule.js
    export let x = 1;
    export const setX = (val) => {
      x = val;
    };

\`\`\`
js
\`\`\`javascript

    // closureCreator.js
    import { x } from "./myModule.js";

    export const getX = () => x; // Close over an imported live binding

\`\`\`
js
\`\`\`javascript

    import { getX } from "./closureCreator.js";
    import { setX } from "./myModule.js";

    console.log(getX()); // 1
    setX(2);
    console.log(getX()); // 2

\`\`\`
Creating closures in loops: A common mistake

How would you do that in a one-liner in vim?

Note that I didnt know how to escape backticks within the code-block , they should appear tripple backticks instead of escaped with backward slash triple backticks

7 Comments
2025/01/27
21:28 UTC

1

copying text without numbers

Hallo Team,

i did searched and did not found what I"m looking for. Sorry.

i have enabled :set nu and now i wish copy text between vim windows.

is there a way copy text without disabling :set nonu?

I"m using gnome terminal

5 Comments
2025/01/25
18:12 UTC

13

Motions for the end of sentences and paragraphs?

I looked this up and didn't find any solutions. I would like to press a key a few times to go to the end of the current sentence (right before the .) and then the end of the next sentences, until I am on the one I want. Same thing with paragraphs, either the last character or right before the ..

) goes to the first character in the next sentence and } goes to the space below the paragraph.

12 Comments
2025/01/25
17:08 UTC

11

When in the `BufReadPost` event, how can I tell that the file has been read with a jump?

BufReadPost is triggered whenever a file is read into a buffer. This can happen with a jump (like specifying a line number on the command line, jumping to a tag or using LSP go-to-definition).

Is there a way to detect this case, as opposed to just :e filename?

I know I can handle the command line thing as a special case by using argv, but it'd be great to have a solution that covers all cases.

I waned to use getjumplist for this, but it doesn't get populated with the current jump until you jump back.

Any ideas welcome!

2 Comments
2025/01/25
01:51 UTC

1

Colored undercurl in tmux

Hello guys, I need help showing colored undercurl in vim using tmux.
I am using foot terminal, by also tried with alacritty and kitty.
I use coc.nvim for diagnostics, and only want the undercurl to be colored.

I have read the :help hightlight, and also tmux FAQ and tmux terminal features.
I got it working without tmux.
Also when I was using nvim and native diagnostics, it worked.
Also if I launch vim as TERM=xterm-256color vim it works, but when I write in the command line (I use gelguy/wilder.nvim the rendering gets buggy and flickering)
Has anyone got it working?
Bellow is the relevant config.
You may checkout my dotfiles also if needed.
Thanks in advance!

EDIT: printf '\e[4:3m\e[58:2:206:134:51mUndercurled\n\e[0m' renders as it should inside tmux.

.vimrc:

" Undercurl support
let &t_Cs = "\e[4:3m"
let &t_Ce = "\e[4:0m"
hi CocUnderline gui=undercurl term=undercurl cterm=undercurl
hi CocWarningHighlight gui=undercurl term=undercurl cterm=undercurl guisp=#e5c07b
hi CocErrorHighlight gui=undercurl term=undercurl cterm=undercurl guisp=#e06c75

.tmux.conf

set -g default-terminal "tmux-256color"
set -ga terminal-overrides ',*:Tc'
set -as terminal-features ",gnome*:RGB:usstyle:cstyle:ccolor:sync"
set -as terminal-overrides ',*:Smulx=\E[4::%p1%dm'  # undercurl support
set -as terminal-overrides ',*:Setulc=\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m'  # underscore colors - needs tmux-3.0
0 Comments
2025/01/24
16:41 UTC

10

On-screen keyboard mapping help?

Any way to get Vim to display keyboard mapping help on-screen, for those moments where muscle memory fails you?

Like this:

https://preview.redd.it/vx6rouvsxzee1.png?width=2394&format=png&auto=webp&s=00b8542321918532f88f21c2ae67d19ca90212db

4 Comments
2025/01/24
19:51 UTC

23

Roast my weird habit and suggest how to improve

I often have a situation where I'm programming and notice I've used one variable in a few places where I should have used another. I can't find and replace as there are multiple legitimate uses of both. I noticed that I don't have a nice way to swap out a handful of instances that aren't gathered together in a block. Keen for your expertise.

I generally yiw to grab it, then navigate to one of the places I want to replace. Then maybe *N so I can jump around the potential locations I might want to swap with n and N. Then the first one I'll use viwp, then after navigating to the next one I use viw"0p which feels so awkward.

Also interested if anyone has moved the 0 register to a key that isn't so far away. For me 0 is one of the only keys I need to reach for.

EDIT: Thanks to everyone!

I'll personally be using this

*
:%s//replacement/gc

but read the comments for other ideas - especially regarding ways to stop the register from being overwritten by p in visual mode.

32 Comments
2025/01/24
02:22 UTC

1

How to select multiple lines in Visual mode and extend the selection on each line until a specific string or regex is found?

consider this text:

<a href="http://en.wikipedia.org/wiki/Theology"></a>
<a href="http://en.wikipedia.org/wiki/Philosophy"></a>
<a href="http://en.wikipedia.org/wiki/Physics"></a>
<a href="http://en.wikipedia.org/wiki/Engineering"></a>

I wanna select this block of text and each line should be selected until reaching the first >< pattern. so the selected text will be:

<a href="http://en.wikipedia.org/wiki/Theology"
<a href="http://en.wikipedia.org/wiki/Philosophy"
<a href="http://en.wikipedia.org/wiki/Physics"
<a href="http://en.wikipedia.org/wiki/Engineering"
8 Comments
2025/01/23
23:34 UTC

2

How to include plugin code directly into the Vim settings file?

I have wanted to use both the fzf and goyo plugins by junegunn for a while, but there are features and settings in them both that I do not want in my Vim setup.

Can anyone tell me how I would go about finding a way to simply port what I need from fzf and goyo into my vimrc file?

I like having everything I need in one vimrc file, and having to load in plugins every time I have to code on a new workstation is annoying. Especially when most of my programming happens within terminals like ConEmu.

I know how to read VimScript - but not Vim9Script. I am using Vim 8.2 I believe.

Thanks.

9 Comments
2025/01/23
21:07 UTC

4

How do I change the cursor behavior such that a char the cursor is hovering over gets deleted instead of the char behind it?

I just downloaded vim yesterday, and honestly I'm not sure what this feature is called, but I'm somewhat positive that it's configurable through one's .vimrc. Else, lmk how to :P

9 Comments
2025/01/23
19:18 UTC

Back To Top