r_vim – Telegram
r_vim
71 subscribers
1.24K photos
60 videos
1 file
19.5K links
Download Telegram
Vim color scheme customization

I've been trying to make my own tweaks to the already existing slate color scheme in vim, as I already tried tweaking some things on top of it like adding a status bar and setting specified colors for it, same for a row guide, which led me to want to modify the syntax highlighting too, the first being that I wanted to change function declarations to a yellowish color, and changing variable declarations to purple, ie (function, func, in yellow) and (int, float, short, long, const, var, ect... in purple), I ended up making groups for those words and then using the highlight function in my vimrc yet the changes only got applied for the vimrc itself. any pointers on what I should try to have those changes applied onto any other file I work on, and is there a way that's easier that listing every declaration in languages that I use/would use?



https://redd.it/1qg9wmr
@r_vim
This media is not supported in your browser
VIEW IN TELEGRAM
PR for new option related to scrolloff: interested in testers

https://redd.it/1qfjf3i
@r_vim
I'm lost on :syntax region

I have a file where almost every line is of the form

TAG name?default=value name?default=value ...

And of course the "?default" is optional.

I'm looking to give tags, names, defaults, and values different colors.

I spent a bunch of time staring at the VIM explanation of how :syntax works, including ":syntax region" which seems to be what I want, but the actual denoscription of how it works is so overburdened with describing how to make it work for strings nested inside multi-line comments in block-structured languages that I'm having an awful time figuring out wtf I'm supposed to type. Even when I just set keywords (which seems to work) and comments with match (which seems to work), adding more lines seems to override everything else, even when I put "online" on everything.

Is there an easier explanation out there than https://vimhelp.org/syntax.txt.html to look at? Like, a simple example of how to make it work instead of "here's how we parse embedded regular expressions inside string inside comments" or something equally complex?

TIA!

https://redd.it/1qkh1a4
@r_vim
Function return causing line jump

I wrote a simple function that checks the current line and either does nothing or performs some visual selection based on conditionals. When running the function from the command line using :execute All three of the conditionals result in the cursor jumping to the first line if they are true. I've discovered that this has to do with the return value equaling 0 which somehow corresponds with line 0. I've written a few simple vimnoscript functions before, and haven't run into this problem.

I've tried running vim --clean and loading the function to make sure it wasn't my config. I'm lost.

Here is the function:

function! SelectLineIfComment() abort
let l:ln = getline('.')
if match(l:ln, '^\s$') != -1
return
endif

if match(l:ln, '^\s
//') == 0
normal! V
endif

if match(l:ln, '^\s/\') == 0
let l:endln = search('*/', 'nW')
execute 'normal!V' . l:endln . 'G'
endif
endfunction

https://redd.it/1qla3wo
@r_vim
NOOOO WHAT ABOUT THE CHILDREN IN UGANDA
https://redd.it/1qp27to
@r_vim
Vim: unsaved buffer edits remain even when switching buffers

Here's my workflow:

1. `vi foo bar` (two files that exist)
2. Make a change in the `foo` buffer
3. `:bn`—fails with the message "No write since last change (add ! to override)"
4. `:bn!`—switches to the `bar` buffer
5. `:bp`—switches to the `foo` buffer

At this point, I would expect to be seeing foo in its original state, i.e. without the edit I made at step 2. However, I *do* see the edits, so my questions are:

* Why does `:bn` fail if no 'harm' comes of it?
* What is the point of `:set hidden`? I've read that this command will instruct the current buffer to 'keep changes in memory', but that seems to be happening anyway.
* Is there a way to switch buffers and discard changes? I don't really need to do this, I'm just wondering if it's possible.



https://redd.it/1qobeg2
@r_vim
:move/:copy between buffers?

I’ve started working more frequently using vim with :split or :vsplit, and find myself wanting
to grab sections of text from one window(/buffer) and chuck them into a different buffer. If I were working in the
same file, I’d do a good old-fashioned visual-select-and-:'<,'>copy, but it :help :copy (and
:help {address}) didn’t give me any help as far as specifying a destination address in another buffer.

One solution to this would be to write up some vimnoscript, but I figured that it was worth checking
whether someone else knew some esoteric thing that would help out here.

https://redd.it/1qn0dlj
@r_vim
Quick Q: How do you re-type when you typo?

When I'm writing in vim insert-mode, and I notice I have written a typo in either the current word or one before, I find I tend to just hammer the backspace key. Sometimes I escape, 'b' then 'cw'. I'm curious to know what method you use to fix typos on the fly.

https://redd.it/1qrarsl
@r_vim
BufExplorer yields "Press ENTER or type command to continue"

BufExplorer is a plugin that lets users easily navigate between files that they have opened. When invoked, it shows these files in a split window, along with state metadata and the folder path. You can quickly go to the folder using Vim's gf command. I've grown highly dependent on BufExplorer, using it synergistically with tabs and windows within Vim. The files can be shown in various sort orders (by name, most recently used, and other criteria I don't recall). You can trim the list by deleting line times, which correspond to files that have been opened (it doesn't delete the file, just it's appearance in BufExplorer).

While indispensable, I do get tripped up by a wrinkle. I've seen the message in the subject line above for years if not decades. Not always, but once it starts, it never goes away. For someone use to finger muscle memory, it's not just friction-- it's a pothole.

Using ":set verbose=9", I found the problem to be:

E303: Unable to open swap file for "BufExplorer", recovery impossible

It turns out that my current working directory (":pwd") no longer exists. The solution was as simple as switching to a known existing directory, e.g., ":cd \~/tmp".

I find it easy to lose track of my working directory and get into this situation if:

I use Vim for days on end so that I'm relying on BufExplorer to switch between files
I rely heavily on a command line to pipe the full path of target file into the system clipboard and get Vim to switch to it using ":e <Ctrl+R>*"
I routinely use the Vim "gf" command in the path field of BufExplorer to a folder, making my "cwd" somewhat irrelevant
A commentor said it was odd for a buffer list to use a swap file. While I'm not certain, it is possibly a side-effect of sourcing a mksession file to resume a Vim session in a new instance of Vim at a later date. I'm not sure how that impacts the invocation :BufExplorer -- it's just a guess at a contributing factor.

https://redd.it/1qscvuh
@r_vim
Search and replace the two-character [ string

I use vim to edit LaTeX files among other things and I have run across a string pattern that I cannot figure out how to find with a sed-like substitution command. Suppose I want to replace the string "\\[" with "foo". Nothing I have tried in vim is capable of identifying the "\\[" sequence. Here are the things I have tried:

:%s/\\\\\[/foo/g
:%s/\\[/foo/g
:%s/"\\\["/foo/g
:%s/'\\['/foo/g

I thought the first one should work, but then I just started trying other stuff. In each case I get this error: "E486: Pattern not found: \\\\[/foo/g

Oddly enough, I *can* forward search to find the next occurrence of that sequence in the usual way: /\\\\[

Can someone please set me straight?

https://redd.it/1qu5rh9
@r_vim
Formatting of status line

Vim novice here. I understand that this is code for configuring the status line. Don't remember where I got it. I sense I may want to use it. I am not competent to read how it configures it. Help appreciated.

" Format the statusline

set statusline=CWD:\\ %{CurDir()}%h\\ \\

set statusline+=\\ \\ File:\\ %{HasPaste()}%t%m%r%y%w[%{&fenc}\]\\ \\ Line:\\ %l/%L:%c\\ \\ Value:\\ 0x%B\\ \\ %<%p%%

set statusline+=[wc:%{WordCount()}\]

Thanks.

https://redd.it/1qwu463
@r_vim
How to horizontally scroll large popups?

Say that I have a huge table displayed in a popup.

Although I can add some keys in the popup filter function to scroll up and down, with entries like:

 \# Move up   
if \["\\<C-n>", "\\<Down>", "j", "\\<ScrollWheelDown>"\]
win\_execute(id, "normal! \\<c-e>")
\# Move up
elseif \["\\<C-p>", "\\<Up>", "k", "\\<ScrollWheelUp>"\]
win\_execute(id, "normal! \\<c-y>")


I tried with:

  elseif key == "l"
win_execute(id, "normal! zl")
elseif key == "h"
win_execute(id, "normal! zh")


but it does not work.

Does anyone knows if it is possible? Because if not, then I could open an feature request on the issue tracker of vim.

https://redd.it/1qxlibf
@r_vim