/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

177,758 Subscribers

10

Terminal fonts

Which is you favorite terminal fonts that you like to have for VIM?

15 Comments
2024/11/03
05:46 UTC

1

How to practice Vim WITHOUT coding?

I find learning through code projects pretty frustrating cause my mind is already trying to solve the problem at hand + I don't code much outside of work, and I dont want to slow myself down at work just to practice vim.
Vim adventures seems like the perfect solution but the $25 license is limited to 6 months which I find to be pretty greedy, so I'm looking for stuff like this that are pretty practical in how vim is used in the real world, without coding

3 Comments
2024/11/02
23:03 UTC

316

Vim turned 33 today! 🥳

Happy birthday vim!

19 Comments
2024/11/02
09:52 UTC

4

GVIM , zoom in and out

how do i zoom in and out in gvim(the gui vim)

i noticed that ctrl + and ctrl - doesnt work there like it works in terminal vim.

am i doing someting wrong or this feature is not avaliable in vim

and also is it possible for vim to have feature like ctrl and scroll up down to change font size like in vscode or emacs

4 Comments
2024/11/02
09:45 UTC

3

Alternative to Jonathon F's PPA for vim?

Jonathon F has passed away and the last update to his vim ppa was in 2021/22

Is there an alternative PPA for Vim? Or are you compiling the latest build from source?

8 Comments
2024/11/02
09:48 UTC

1

Update to yegappan-lsp-settings plugin

Hi, now my plugin will automatically pull configurations from nvim-lspconfig. This will ensure an up to date lsp configuration with a best practicies etc.

Most people now they can simply install the plugin, select some servers from :h lsp-settings-server-list and go about their day without much configuration.

Here's mine:

let s:lsp_options = {
  \ 'autoComplete': v:false,
  \ 'showSignature': v:false,
  \ 'omniComplete': v:true,
  \}

function! s:on_lsp_buffer() abort
  setlocal signcolumn=yes
  setlocal completeopt-=preview
  nnoremap <buffer> gr :LspReferences<CR>
  nnoremap <buffer> <leader>a :LspCodeAction<CR>
  nnoremap <buffer> <leader>r :LspRename<CR>
endfunction

function! s:lsp_init() abort
  call LspOptionsSet(s:lsp_options)
  call lsp_settings#Clangd()
  call lsp_settings#RustAnalyzer()
  call lsp_settings#Pyright()
endfunction

augroup lsp
  au!
  au User LspSetup call s:lsp_init()
  au User LspAttached call s:on_lsp_buffer()
augroup end
3 Comments
2024/11/01
14:57 UTC

16

How do I get completion in vim?

How to make auto completion in vim? Is it possible without plugins? And some recommendations...

46 Comments
2024/11/01
10:45 UTC

10

Quick Vim + LLM tip: I made a keystroke helper that doesn't break my flow

Just set up a quick way to get instant vim command help without leaving vim. Here's how:

  1. Install the llm CLI tool: brew install llm (or pipx install llm)
  2. Create this script (I named it vh):bashCopy#!/bin/sh llm -s "Output the keystrokes required to achieve the following task in vim. Answer in as few words as possible. Print the keystrokes, then on a newline print a succinct explanation." -m claude-3.5-sonnet "$*"
  3. Make it executable: chmod +x vh
  4. Add to vimrc: :map <leader>v :!vh (be sure to add a space after vh)

Now I just hit \v, type my question, and get instant vim commands. No need for quote marks in the question.

Example: \v delete until end of line → get d$ with brief explanation.

Uses LLM - a command-line tool for interacting with large language models. Works great with Claude, GPT-4, or any model llm supports.

2 Comments
2024/11/01
07:32 UTC

16

:Open path / :Launch app

Latest Vim (netrw runtime files) brought commands

  • :Open to open a file / URL
  • :Launch to launch a (GUI) app

For example,

  • let &keywordprg = ':Open https://devdocs.io/\#q='..&filetype to look up documentation for the keyword under the cursor on Devdocs hitting K, or
  • alternatively nnoremap <expr> <F1> '<cmd>Launch zeal "'..&filetype..':'..expand('<cword>')..'"<CR>' hitting <F1> in Zeal,
  • :Launch okular %:S to (live) preview the currently edited markdown file in Okular, and
  • :compile pandoc | make pdf and :Open %:r.pdf to compile it with pandoc and view it as PDF file.
5 Comments
2024/10/31
09:32 UTC

3

Edit multiple files without the use of :bn/:bp

I swear there's some default bind/key combo to switch which buffer you're in/what file you're editing that isn't :bn or :bp, but I cannot remember what it is. I remember when trying to move past the last file in the line of files, Vim would print near the bottom bar "no more files left to edit". Using :bn, it will switch between buffers/files infinitely. It won't stop me, or print a message of "no more files left to edit".

This isn't a big annoyance, but I'm going slightly crazy as I can't find anything online about this other than references to :bn/:bp. Also, I'm definitely sure that I was not using a plugin. My Vim has no plugins other than Goya.

If anybody has an idea, please let me know.

5 Comments
2024/10/30
18:16 UTC

3

Issues with numpad on vim

I have a problem that’s driving me crazy. Yesterday I unknowing mistyped something somehow and now my numpad doesn’t work correctly in vim. It works on the command line, it works on slack so numlock is on. But when I’m in vim on ‘server A’ all num pad keys work except 9 does a page up and numpad 3 does a page down. I’ve tried a different user on the same server and same behavior. I’ve tried checking all key maps and I don’t see it mapped. I’ve tried :unmap k9, :unmap <k9> and it says it’s not mapped. Nothing to note in my .vimrc.

I tried another sever and on ‘server B’ my numpad doesn’t work at all so that’s another issue in itself but I guess I can tackle that later.

If I open a file on my local laptop and not a server I ssh to then numpad works fine also. So my guess it’s some global setting specifically on the server but I’ve wasted a day trying to figure this out.

2 Comments
2024/10/30
17:44 UTC

30

[Workflow] Have you tried using LLMs without copilot in Vim? I tried a more in-control approach

disclaimer: I built a tool, but it's not the only one and I am actually here to talk workflow and use the feedback!

I love LLMs but I have never been a fan of copilot. I like to have more control over LLMs, what goes in them so I can manage my expectations and steer them to produce more relevant answers.

So I got to work and built a tool which you can pipe text into interfaces with LLMs with a default prompt (which you can configure) that make them play nice as CLI tools (no explanations, no markdown marking etc).

Here's the result https://github.com/efugier/smartcat

You can acheive a roughly the same thing through a pletora of tools, aichat for instance, or code it yourself / make a plugin whatever.

But once you have such a tool available, here's what the workflow looks like:

Select some text, then press :. It will pipe the selection content to you tool of choice and overwrite the selection with the output.

Here's a few practical example of how it can be use:

:'<,'>!sc "replace the versions with wildcards"
:'<,'>!sc "fix this function"
:'<,'>!sc "write test for that function"
:'<,'>!sc "write a function to solve that test"
:'<,'>!sc "translate that script into python"
:'<,'>!sc "format that stack trace and explain the issue"

with a remap, interfacing with lllms becomes very easy and quick

nnoremap <leader>sc :'<,'>!sc

You can also ask questions from the confort of your editor by selecting nothing, it also works from the terminal.

I found it's actually the cheapest and most brand-agnostic way to leverage the latest llms into you coding workflow.
For me a month of heavy use with the best models is about 2$.

In the end I really don't feel like I need copilot, I'd much rather have a LLM write a great and tailored v0 and iterate on it (which is what our editor is the best at) than auto-completing into an appoximative one.

I considered making a plugin for that but I felt more in line with the unix philosophy to leverage vim playin nice with standards I/O and make a separate tool that could be used on its own and in other situation.

Have any of you stumbled upon a similar workflow? What are you doing differently?

26 Comments
2024/10/30
13:12 UTC

10

I've created two plugins, let me know what you think

During my jobs, I've found these functions useful, and rather than keep copying them from one job computer to the next, I decided to make plugins for them.

This one allows you to use one button to copy/paste URLs to the current line you're on, as well as open the file in your browser https://github.com/cd-4/vim-extrovert

This one adds 4 movement functions so that if you're within some level of a huge yaml file, you can just call the function (or remap it to C-j/k/h/l) and jump to the next level of the same indentation, or go up or down an indent. It also stops you from escaping a sublevel of indentation. Initially created for huge yaml config files, I've found it's pretty useful in a lot of places. It also creates some smart folding methods to hide lower levels of yaml files, and automatically expands when moving into them using the movement functions https://github.com/cd-4/vim-yamove

2 Comments
2024/10/30
12:05 UTC

1

how can i write to the command line buffer.

So i have some commands there that dont want to see. I dont want to delete the whole history just couple of them. Deleting is fine it allows me to, but when i try to save over it it doesnt let me :

https://preview.redd.it/wx20nkx9gsxd1.png?width=865&format=png&auto=webp&s=5d72c1b4a690c23cd8288b13117a44b5933aacab

https://preview.redd.it/3nec9pcfgsxd1.png?width=971&format=png&auto=webp&s=a9b5be2203f2601bdea87fba1261ba3166632c74

in additon how can i disable the popup message ive tried with several shortmess options but it doesnt work.

4 Comments
2024/10/30
00:31 UTC

40

Open two files side by side with one command

[SOLVED] `vim -O a.txt b.txt` Many thanks!

I'd like to make a bash alias `openab` which opens "a.txt" and "b.txt" in a vertical split beside it.

What would the command be?

13 Comments
2024/10/29
10:31 UTC

0

Chat-gpt integration plugins.

I am wondering if there is any plugin with chat-gpt integration and what is your experience with that. My brain is getting damaged due to context switch with the browser: for example, when I add something in the google search box I instinctively hit ctrl-p for scrolling through the suggestions but that opens the printer dialog box. Given that the most web service while working I use is chat-gtp I was wondering if I can use it in Vim directly. Note: I have preferences for Vim9. :)

5 Comments
2024/10/29
09:28 UTC

8

I need some help with my new plugin that configures yegappan/lsp

Hi,

I need some help making my plugin come to life https://github.com/saccarosium/yegappan-lsp-settings.

I would love having contribution with your specific lsp

1 Comment
2024/10/28
23:26 UTC

6

Custom binding for adding lines

I come with this, let's see if you like it.

Add lines keeping cursor location, only when used with line numbering (ex. 3o, 99O etc), otherwise it behaves as standard o/O. You can also return to last line with gi or ``.

nnoremap <expr> o v:count>0 ? 'm`:<C-u>exe "norm! '.v:count.'o"<CR>``' : 'o'
nnoremap <expr> O v:count>0 ? 'm`:<C-u>exe "norm! '.v:count.'O"<CR>``' : 'O'
4 Comments
2024/10/28
23:50 UTC

3

Indexing plugin documentation to access in :help

I have a couple of plugins manually installed under $HOME/.vim without the aid of a plugin manager. Currently, I have NERDTree and table-mode installed. Both plugins show up when I do :help local-additions but typing :help NERDTree or :help table-mode gives an error. What do I need to do so vim indexes those help files?

4 Comments
2024/10/28
17:51 UTC

1

Vimspector issue while debuggingnode express app

I have been trying to setup vscode like setup for debugging nodejs app in vim but even after installing the gadget, when trying to launch vimspector it shows

The specified adapter 'vscode-js-debug' is not available. Did you forget to run 'VimspectorInstall'?

0 Comments
2024/10/28
12:46 UTC

1

Telescope for vim & lib source folder

hi all, is telescope only available for nvim? tried to install with vim-plug for my vim but i wont work..

is there an alternative for vim maybe?

btw i came from vscode, in vs i could ctrl+click on a certain #include<lib> and it will take me to where this lib is install on my machine, is there a plug maybe for that action?

thanks!

9 Comments
2024/10/28
12:09 UTC

17

Workflow for code reading on vim

I would like to know what are your workflows for code reading and understanding of large code bases on vim?

Also specifically I would like to know what is your specific setup to taking notes of code? Is there a way to map to a source file to your notes?

15 Comments
2024/10/28
06:44 UTC

6

Is there an alternative to gilles castels inkscape vim shortcut plugin that works on wayland

It only works on x11 because it uses xlib. Is there an alternative that would work on wayland.

1 Comment
2024/10/27
23:33 UTC

0

Remap <tab> as <esc> key (100% legit 2024 no virus)

Creator of vi keymap used keyboard which had escape in place where tab nowadays is:

https://i.sstatic.net/g1Hzo.png

Problem if you remap Tab to escape normally is that you lose ability to do ctrl+i ctrl+o

I'm here to share solution/hack with yall to restore this confortable <esc> key layout without losing ctrl+i ctrl+o.

.vimrc:

nnoremap <Tab> <Esc>
vnoremap <Tab> <Esc>gV
onoremap <Tab> <Esc>
"cnoremap <Tab> <C-C><Esc>
inoremap <Tab> <Esc>`^
inoremap <Leader><Tab> <Tab>
noremap <F12> <C-i>

install xremap works on x11 and wayland

https://github.com/xremap/xremap

(for arch users, there is an aur as usual)

.remap:

keymap:
  - name: joe
    application:
      only: [org.kde.konsole]
    remap:
      C-i: f12

replace org.kde.konsole with terminal you use.

note: <F12> is an arbitrary unused key, replace it with any unused key

for auto-starting do:

/usr/lib/systemd/system/xremap.service:

[Unit]
Description=Change keycodes at boot

[Service]
Restart=always
ExecStart=/usr/bin/xremap /home/<User Name>/.remap.yml

[Install]
WantedBy=multi-user.target
7 Comments
2024/10/27
12:17 UTC

9

:set filetype=i3config for files only in the ~/.config/i3 folder

[SOLVED]
I realized the problem was only happening when I ran vim with sudo. Vim was probably searching for a .vimrc in a root folder rather than my user home directory.
To fix this, create a symlink to your .vimrc:

sudo ln -s ~/.vimrc /root/.vimrc

####################
I want to have all the current files and the files that would be created in the ~/.config/i3 folder to be set to filetype i3config. I am compartmentalizing my i3 config file and while the config file works fine by itself, "appearance", "workspacess" and other files in the folder default to the sh filetype.

Currently I am manually executing :set filetype=i3config very time I open one of those files but I would like to automate that. I tried adding this command to my .vimrc but it did not help

autocmd BufRead,BufNewFile /home/martin/.config/i3/* setlocal filetype=i3config
8 Comments
2024/10/27
07:08 UTC

19

Is there some tutorials to make vim/neovim plugins?

Like the title

32 Comments
2024/10/26
03:26 UTC

8

A gist of the builtin libcall() function

I'm writing a couple of vim9script plugins that use large dictionaries. That poses performance challenges because loading large dictionaries initially is a bottleneck. And, although vim9script functions are compiled (and, like loaded dictionaries, are extraordinarily fast once they have been), there is no pre-compiled vim9script option (and it is not on the roadmap), which could have been a solution.

So, I looked at a few ways to tackle the issue, including libcall(), which enables using a .so or .dll. I've not progressed using it**, though could have, and it was interesting checking it out. I found virtually no examples of it being used, so, if anyone's interested, there's a gist. Although I don't use Neovim (other than occasionally for compatibility testing), I used it for the .dll test just to see whether it worked with it too, and it did. Vim is used for the .so demo. (** Incidentally, I went with JSON / json_decode(), which, from some testing, seems to be the the fastest means of filling a large dictionary when it's first required.)

10 Comments
2024/10/25
18:19 UTC

Back To Top