/r/vim

Photograph via snooOG

The place for questions and conversation on the Vim editor

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

168,861 Subscribers

2

How to setup formatprg to get start/end line from selection?

Hi, I was wondering if there some convenient way to setup formatprg such that the visual selection range gets picked up by the external cmd?

Let's say I have a formatter tool that can be launched with command banana-formatter --range A:B sourcefile where A is first line and B is last line to be formatted.

Can I set something like set formatprg=banana-formatter --range \start:\end?

6 Comments
2024/04/10
18:29 UTC

2

Is there a way to print date-1 and day-2 from today?

Hi, Is there a way to print in Vim (=show, output) date-1 and day-2 from today?

sometime I need to fill a log. 1 or 2 days after. So I'd like to have a command in .vimrc that print -1 or -2 days after today in the doc. I have these 2 commands in .vimrc for print date: Long version and short version of today, but maybe you can post the same commands for print date -1 (rare -2) from today, print passed date:

iab _d <C-R>=strftime("%A, %d de %B de %Y.")<CR>

iab _f <C-R>=strftime("%d/%m/%Y.")<CR>

Thank you and Regards!

7 Comments
2024/04/10
12:13 UTC

11

vim-manim: render scenes without leaving Vim.

This is for rendering manim scenes (for those who use it) without leaving Vim. The plugin is extremely small: there are more line of comments than lines of code ahahahah.

https://github.com/ubaldot/vim-manim

Any feedback is appreciated!

0 Comments
2024/04/10
10:17 UTC

2

Vifm command to display selected directory as :tree view in second pane

Hi, I guessed this was the best place to ask about Vifm on the internet as I didn't find anything better.
My goal is to separate Vifm in two panes, the second one showing the file information of the selected object of the first pane. If it is a directory, the second pane shows the inside of the directory in :tree mode, and if it is a file, it simply previews the file.
I was able to do it, but I do not like at all the way it was done, and I need help making a better version.

" repeated code for hjkl
nnoremap h :view!<CR>:view<CR>h:if filetype('.') != 'dir' | view! | else | :sync %c<CR>:winrun , tree | endif<CR>

Explanation:

:view!<CR>:view<CR> forces into view mode and then back out of it, as to reset my view each time.
h:if filetype('.') != 'dir' | view! presses 'h' and checks if the selected object is a directory, if not, it forces into view in order to preview the file.
else | :sync %c<CR>:winrun , tree if it's a directory, it will sync the second pane with the first one, as to have the selected directory become the one shown in the second pane (thanks to %c). winrun will then run ":tree" on the second pane as to show a tree view of the selected directory in the second pane.

Even though this works, it constantly displays the error message ":endif without :if" and also takes allot of time to load big directories, during which I cannot act.
My goal is to create a command that works constantly instead of when I press "hjkl", to remove the error message, and also to disable this whole command on a button press, or when I selected a folder that is too big. I have tried functions but was not able to create one, as Vifm is not very documented.

0 Comments
2024/04/10
09:49 UTC

1

Need advice on how to do this seamless

so lets say i need to type this below efficiently
list = ('book','pencil','toothbrush','pole')
usually i use vim with a combination of smart completion like if i type ' itll type the other ' or if i type ( itll type the end ) . what i do i i either have to esc then press L key to go the right or use arrow key which is really far.

8 Comments
2024/04/10
07:20 UTC

2

What does lint mean?

I read this in my Muon repo of Lubuntu:

ALE (Asynchronous Lint Engine) is a plugin providing linting (syntax checking and semantic errors) in NeoVim 0.2.0+ and Vim 8 while you edit your text files, and acts as a Vim Language Server Protocol client.

ALE makes use of NeoVim and Vim 8 job control functions and timers to run linters on the contents of text buffers and return errors as text is changed in Vim. This allows for displaying warnings and errors in files being edited in Vim before files have been saved back to a filesystem. In other words, this plugin allows you to lint while you type.

but what is this? it correct my bad spell? is it for write better text? I am not programmer!

6 Comments
2024/04/10
02:07 UTC

5

Short and stout

🫖 I'm a teapot!

I found another easter egg to add to my vimpromptu collection.

:call err_teapot()

1 Comment
2024/04/10
00:28 UTC

0

Why do vim people hate debuggers so much?

Is a serious question. Why do vim people are so hostile towards having a integrated debugger?

52 Comments
2024/04/09
21:52 UTC

4

How to trigger a function call from QuickFix list movement

So each time I move through the QuickFix list (for example, using commands like :cnext, :cfirst, :.cc, etc), I'd like to perform some tasks (which in my case is highlighting the current error in the file's window). How do I do this? I didn't find any auto command for this purpose. Or is there any other way?

5 Comments
2024/04/08
13:17 UTC

15

Just installed vim-ai and love it

being able to vip a whole function and say "make this more idiomatic" all from within vim.

Nothing else, just an appreciation post. I've been copying/pasting from the web browser and this is so, so much better.

14 Comments
2024/04/08
12:41 UTC

0

How to get back from address bar of Firefox to main browsing field? (Not a lost Redditor)

Hello my fellow connoisseurs of HJKL.

I used the browser addon VimiumC for a long time now in Edge and can't live without it. Recently I decided not only to switch my operating system, but also to Firefox as my main browser. In Edge while focused on the address bar pressing ESC key brings the focus back on the main tile of the browser and hence granting me the pleasure of navigating with HJKL. However, in Firefox this does not work. Pressing ESC keeps me in the address bar and I have to hit TAB a couple of times before coming back to the actual main tile of the window.

Did anyone encounter this problem? Has anyone an idea how to solve it?

I'm asking specifically in this sub, as I assume that in no other sub I will find more Vimium users that would know this struggle.

8 Comments
2024/04/08
07:35 UTC

2

When compiling vim, what option is used for syntax highlight?

Dumb question, want to compile vim-tiny, but coding in high level languages without colors is really disorienting, need syntax highlight, which of the configure options do i need?

3 Comments
2024/04/07
22:57 UTC

64

Do people seriously use Vim and it's cousins for writing more traditional papers and/or documentation? How good is Vim as a universal "front-end" to replace traditional "Office" apps?

TL;DR
Can I use Vim and plain text files to output digital documentation similar to those made in Google's and Microsoft's office suites? I imagine this would be feasible for everything except diagramming software and video editing software. I know some programs allow you to insert images in-line and they show up something like [image-file] in the editor/text and don't actually render and push everything around.

For the past couple of months I've been acutely interested in Vim. This stems from my work environment and the state of computing as a whole these days. This has led me to binging some of Primeagen's content, a few other Linux/Programming people/communities. I understand it's a meme- using vim for everything- but... I can kinda see why/how?

I've gotten acquainted with the normal mode commands/movements and how to "jump" extremely efficiently. I understand the reasoning and nuances behind capital letters and why they do what they do, or the relationships between things like a/i, w/W, f/t. I also see how valuable using c can be along with the aforementioned normal mode commands and how Vim understands the concepts of not only word/symbol boundaries but even sentences, paragraphs, functions, indentation, etc.

I absolutely hate word processors, Office apps/suites, and the like. I can get by with shortcuts for some functions and features, but for those that don't have shortcuts I absolutely lose it having to move my mouse to do the thing over and over again. What's worse is the visual overstimulation of the cluttered "ribbons" and menus and all. What tops it off is how overused these apps are for what are essentially just bullet pointed flat files. The slide decks with a title on page 1 and bullet points on the rest drive me mad.

I've seen workflows in which someone had Vim open and they were editing a file in real time with the same file open in another window but it was being "rendered". It seemed like they were able to create an output of what looked to be a research paper, word processor frills and all. I think this was a Luke Smith video? Anyway, I was wondering how possible this all was as a whole. Can I output proper Word documents, PDFs, powerpoints, spreadsheets, all of that- with a flat file constructed in Vim? Are these extensions of Vim/NeoVim or separate utilities altogether?

88 Comments
2024/04/07
19:53 UTC

18

Fuzzy search-like with no plugins.

Today I discovered this feature that I want to share. Add `set path+=**` in your `.vimrc` and then run `:find (whatever you want, feel free to use wildchar *)` for example `:find myf*.py` and then hit `<tab>`. Enjoy.

4 Comments
2024/04/07
17:53 UTC

12

Default omni completion

Hello!

I like experimenting with vim's features and one of those is omni completion. This type of completion can be fed by plugins but vim also comes shipped with some included omni completion functions. Those are documented in compl-omni-filetypes, the according scripts are found in $VIMRUNTIME/autoload/.

One of the included scripts is for C which I tried the most. But I was never really satisfied with it. It requires the usage of ctags which is fine as I also need this for using tags to navigate.

But the completion of the fields in structs which would be its most handy feature in C just never seems to work in a satisfying way. Sometimes it just fails entirely and when it does not, it always adds a . after the completed fields even though the completed field is not even a structure. Same applies for [ characters that are completed at times that I do not want them.

Also, the popup that should show some information about the completed object is not really helpful but rather confusing. It shows what kind of object this is, but only with one letter, so you have to guess what that letter means. It always show if it is static using 1 and 0 which I do not find an elegant solution then it prints something like

struct    __anon0d38083b0108

which comes directly from the tags file and contains no information at all that I find useful.

There are also other omni completion functions which I briefly had contact with. It seems like the HTML completion is for HTML 4, which is out of use for more than 10 years now...

The documentation of the JavaScript completion (ft-javascript-omni) states the following:

At the moment (beginning of 2006) there are two main browsers - MS Internet Explorer and Mozilla Firefox. These two applications are covering over 90% of market.

I will let that one speak for itself.

So to sum up I do not find this feature of vim particularly helpful. Especially when we look to the language server based completion options that other editors have built in, but can also be brought to vim with some tinkering.

Do you have a similar or different experience with omni completion?

2 Comments
2024/04/06
20:06 UTC

3

Replace mode issues

Hi guys I am new on vim but I have issue that when I open vim automatically open on replace mode even when I try to enter configuration it enter again to replace mode if someone have a sulotion to this

4 Comments
2024/04/06
18:40 UTC

15

Editing stuff inside of brackets

print ( myFunction ( myVariable ))

How can I edit the "myVariable" part of this line of code if my cursor is at the start of the line? Is there a command similar to "cib" for parentheses, or is using "f(" to navigate to the bracket before using "cib" the only option?

25 Comments
2024/04/06
17:52 UTC

0

Can I move a value to the vim register via CLI ?

Hello everyone

Can I move a value to the register via CLI ?

Something like this

https://stackoverflow.com/questions/11600492/copying-a-line-into-vim-register-from-terminal-command-line

but without the vim opening.

> vim value1 Register_a file.txt

> vim value2 Register_b file.txt

> vim value3 Register_c file.txt

Is that possible?

11 Comments
2024/04/06
06:20 UTC

3

VIM syntax highlighting stopped working after upgrade to Ubuntu 22

EDIT: This has been solved (I am not sure how though :shrugs:)

Hello,

My VIM syntax highlighting seems to be not working anymore. I upgraded to Ubuntu 22.04 from 20.04 a few days ago. Today is the first time since then that I opened vim, so I am unsure if they are connected.

Here is my vim rc:

$cat .vim/vimrc
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set smartindent

set number

if &compatible
set nocompatible
endif
set runtimepath+=~/.vim/dein/repos/github.com/Shougo/dein.vim

if dein#load_state(expand('~/.vim/dein'))
call dein#begin(expand('~/.vim/dein'))

call dein#add(expand('~/.vim/dein/repos/github.com/Shougo/dein.vim'))
call dein#add('Shougo/deoplete.nvim')
if !has('nvim')
call dein#add('roxma/nvim-yarp')
call dein#add('roxma/vim-hug-neovim-rpc')
endif

call dein#add('vim-airline/vim-airline')
call dein#add('tpope/vim-fugitive')

call dein#end()
call dein#save_state()
endif
set noeb vb t_vb=
set viminfo+=n~/.vim/viminfo
syntax enable

augroup AutoSaveFolds
autocmd!
autocmd BufWinLeave * mkview
autocmd BufWinEnter * silent loadview
augroup END

set hlsearch
set sts=4
syntax on

The other things seem to be working just fine. But nothing is highlighted. Even `:syntax enable` and `:syntax on` are not working from within a running vim instance. I tried uninstalling and reinstalling vim, did not help. Any other ideas?

Getting this fixed would be hugely helpful and I have no idea how to debug something like this. Any suggestions would be very much appreciated.

7 Comments
2024/04/06
03:17 UTC

3

Vim9Script Types Help

I'm trying to add types to a language list in my vimrc file, the variable looks like this:

var languages = {
  'c': ['c', 'h'],
  'shell': ['sh'],
  'python': ['py'],
  'json': ['json'],
  'typescript': ['tsx', 'jsx', 'js', 'ts'],
}

I've tried adding types like this:

var languages: dict<string, list<string>> {...}

Which should work I think but I'm getting this error:

E488: Trailing characters: , list<string>> = {

I can't figure out which characters are trailing and AI has no idea either.

Solution

Thanks to u/ghost_vici for this response, I was being a moron and defining a type for the key in the dictionary which makes no sense because the key name would always be a string so therefore only the value type is required:

var languages: dict<list<string>> {...}
10 Comments
2024/04/05
22:44 UTC

2

Apply listchars to concealed texts?

I am writing LaTeX with vimtex conceal feature, and need to distinguish between the regular space U+0020 versus the non breaking space U+00A0. My listchars setting is space:·,nbsp:␣,leadmultispace:»\ ,trail:·. Below is a minimal example,

\documentclass[12pt]{article}
\begin{document}
Space U+0020
Non Breaking Space U+00A0
LaTeX Space\ U+0020
LaTeX Non Breaking Space~U+00A0
\end{document}

Here is how it looks without conceal, i.e., conceallevel = 0,

https://preview.redd.it/c8nkhlkpeosc1.png?width=534&format=png&auto=webp&s=25512cf66f3a9f391cab1561d1af8795a73d33b6

Here is with conceallevel = 2,

https://preview.redd.it/bnwth9fueosc1.png?width=534&format=png&auto=webp&s=5445dc4d39d849e7fc41a431c2811874e4322ebb

The raw space and nbsp on line 5 and 6 are properly displayed as · and , but the concealed ones on line 7 and 8 are not.

Checked vimtex/syntax/core.vim , currently there is no distinction between the conceal of space and nbsp, both cchar is the regular space U+0020. It seems unfortunately listchars does not apply to cchar, and my question is that is it possible to do so? Of course I could directly modify vimtex/syntax/core.vim to , but that requires changes in the plugin and also the highlighting group will be different, so more hacking is needed.

3 Comments
2024/04/05
15:14 UTC

8

Recommended streams/videos for shadowing someone using Vim? (Best practices)

Does anyone has a good recommendation for video material, where I can watch someone using Vim in his/her development cycle? I.e. working with git, refactoring code, writing new tests etc?

I have a very basic nvim setup now which I feel comfortable enough to get started + learned the basic hotkeys for navigation and editing.

However, I want to avoid transferring bad habits from my experience using gui editors and I’m curious how other devs use nvim the way it is meant to be.

Best Gerrit

7 Comments
2024/04/05
05:51 UTC

1

help about ps2pdf?

Hi! I read in :h ha(rd copy) Bram told us that we can pass from vim to pdf file using ps2pdf

I ddg about ps2pdf and found this page https://wiki.archlinux.org/title/PDF,_PS_and_DjVu in [ES] https://wiki.archlinux.org/title/PDF,_PS_and_DjVu_(Español) and there they told us about a program gosthscript...

learnig at https://www.linux.com/training-tutorials/creating-pdf-files-ps2pdf/ I see that I have installed ps2pdf, and the command for do the file.pdf ask me about my file.ps

What or how can I get files.ps? could I save as .ps? Vim does it for us: with the command :ha > output.ps so now we have us file.ps

for coincide font of Vim with font of ps2pdf (or gs that it is its father) in Vim we need to set tw=80 and text fits to output.pdf for A4 with margin of 2 cm both sides left and right.

then with ps2pdf we convert our file.ps to file.pdf

finished!

I learnt that using enscript (dowloaded by sudo apt install enscript, little program (yes I am nerardentall, today is app) I tryed to use enscript text_of_vim text_converted.ps and... worked! important: enscript doesnt have utf-8 so it works for lang EN, not for ES, but Bram with Vim fixed it: :ha > output.ps for check if your linux have ps2pdf: command whereis ps2pdf it is part of the app ghostscript. both have manual on terminal to learn their flags options.

Thank you and regards!

8 Comments
2024/04/04
21:53 UTC

2

incsearch without cursor/screen jumping

Is it possible to have the active feedback of highlighting your search term with insearch without it causing your screen to jump around all over the place? This is pretty disorientating when doing a c/text to change up till a searched term on that line. Also when do in a find and replace on a selected block of text :'<,'>s it jumps all over the place making it hard to see what you are changing.

2 Comments
2024/04/04
18:21 UTC

1,121

My wife was unimpressed by Vim - please advise

Last evening I made a small demo to my wife. Nothing fancy, just jumping around the page, moving lines around, deleting several words at a time, the kind of things that blew my mind when I first saw Vim.

Alas, my wife couldn't care less, and she even told me so. I've been married for 10 years, but I'm starting to have some doubts. So I'm appealing to this fine community in this moment of crisis. Where can I go from here? What path should I take?

300 Comments
2024/04/04
18:12 UTC

7

Learn correct typing first then Vim?

So in short, my method of typing is somewhat unique. I do not have my fingers on the home row and although I happily touch type I do so mainly using the first two fingers on my hands and very rarely use the little piggy on the end (he just wee's all the way to Enter or caps).

I (finally) decided to take a look at learning Vi/vim, and wondered do you need to learn to use a keyboard properly first in order to really see the benefits of using Vim ? From the very basics which I've tried so far I find it really awkward to use. I also wonder if people have issues with keyboard layouts, I use UK for example.

thx.

19 Comments
2024/04/04
09:58 UTC

0

New to Vim. Help !!

Yesterday, I started using neo vim it is been a great pain in the ass to set it up i am using ubuntu and it is keep installing previous version of neovim and while installing the plugins get crashed more often

I dont know want to do now I redownloaded it almost like 4 times it is still not clear to me

I want to code in it as a mern Developer

So is there any suggestion , Tutorial or Guide which i can take help from for installing setting up it to suit a mern developer

I would greatly appreciate the help

23 Comments
2024/04/04
06:45 UTC

3

Can't understand how vim is fixing my error

So I have a script that does a bunch of things, one of the things it does is repo init and repo sync.

But during repo sync I get a error like this

manifestUrl = self.manifestUrl.rstrip('/')

AttributeError: 'NoneType' object has no attribute 'rstrip'

Its unable to read the manifestUrl for some reason

The manifest url is in this file

.repo/manifests.git/config

Now I can run any repo command and I get the same error 'NoneType' object has no attribute 'rstrip'

If I open the file .repo/manifests.git/config in vim and exit with wq

The error goes away.

I compared both files before fix and after fix and they are exactly same in terms of permissions and also did beyond compare on them.

Something happens when I save the file in vim with wq that fixes my error, it doesn't work when I exit with q!.

I am stumped now
Any leads will be appreciated

8 Comments
2024/04/04
05:20 UTC

19

What is a “leader” key?

I’ve been using vim for a long time and still don’t know what this means. At this point I’m almost too afraid to ask.

14 Comments
2024/04/04
04:53 UTC

3

semantic highlighting vs lsp for C++

I'm a previous vscode user and C++ developer and find that I have more trouble navigating code without vscode's more comprehensive highlighting. I tried comparing a couple files side by side and I think it boils down to more expressive highlighting differentiating almost every language construct - types, type definitions, aliases, etc

I did some research and what I want seems pretty similar to this: https://gist.github.com/swarn/fb37d9eefe1bc616c2a7e476c0bc0316#controlling-when-highlights-are-applied

But, I am staunchly against using neovim because I have friends who struggle with portability issues and frankly don't see the point in learning lua. I tried vim polyglot, which didn't really get me there.

Furthermore, I found this: https://github.com/jeaye/color_coded - which states that it has been archived in favor of lsp based syntax highlighting. I can't seem to find lsp based syntax highlighting for vim.

Some workarounds that I found:

- https://github.com/jackguo380/vim-lsp-cxx-highlight?tab=readme-ov-file - only works for c/cpp / similar languages

- https://github.com/jaxbot/semantic-highlight.vim - which seems to get me there, going to try it out after posting this

I'm wondering what I might be missing and best practices that I'm not aware ofhttps://github.com/jeaye/color_coded - which states that it has been archived in favor of lsp based syntax highlighting. I can't seem to find lsp based syntax highlighting for vim.

Some workarounds that I found:

- https://github.com/jackguo380/vim-lsp-cxx-highlight?tab=readme-ov-file - only works for c/cpp / similar languages

- https://github.com/jaxbot/semantic-highlight.vim - which seems to get me there, going to try it out after posting this

I'm wondering what I might be missing and best practices that I'm not aware of. An ideal solution would be generic to vim/nvim, and also agnostic to language (not just C++).

4 Comments
2024/04/04
04:02 UTC

Back To Top