How do you write code in parentheses or quotation marks?
I just started getting acquainted with Vim and don't understand how to write code framed on both sides by something.
I am used to writing so that if a part of the code occurs, for example, in angle brackets, then first I write the opening bracket, then immediately the closing bracket, after pressing the left arrow key I moved to the position inside the brackets, after writing the code inside, I press the right arrow key and write the code further.
In Vim, as I understand it, it is not customary to use arrows and hjkl is used instead in normal mode.
Can you tell me how to write code in Vim correctly? Switching to normal mode and back to insertion mode just to move one position to the left inside the brackets seems inefficient. Do I need to retrain and write code character by character without going back a position, or is there some more convenient method of working with code in Vim?
https://redd.it/18vtto4
@r_vim
Best plugin for file explorer?
Any recommendations on file explorer plugins to look like an IDE?
https://redd.it/18vqvyr
@r_vim
Search cmap list
Hi,
I have saveral mappings for command mode.:cm,
will list all command mode mappings starting with ,
. Is there a option to search the output?
I tried something like:cm, | /pattern
but didn't work.
https://redd.it/18rz4z9
@r_vim
How do I get back the default functionality of a key/key combination I had already mapped to something else?
Back when I was new to vim, I wanted to have a "select all" feature like I used to have in my browser. And obviously, the de facto default key combination for that was <C-a>
. So, I mapped <C-a>
to do just that:
nnoremap <C-a> gg0vG$
<C-a>
i.e. incrementing numbers. Is there a way to have that back while retaining my mapping for <C-a>
?I use vim from the PyCharm terminal
Do you have any tips for me?
https://redd.it/18rhmwb
@r_vim
How to replace all matching blocks of text?
Good day,
For the sake of this question, I have a file that contains this:
--|-F-@-|-
-A-0-S--|-
------@@-@
--!S-@F--|
--F-@-----
---S------
----------
How would I replace all occurrences of
F-@
-S-
with
BBB
BBB
Such that the final text file looks like:
--|-BBB-|-
-A-0BBB-|-
------@@-@
--!S-@F--|
--BBB-----
--BBB-----
----------
Thank you!
https://redd.it/18rnpf2
@r_vim
Weekly tips/tricks #3
Welcome back everyone! This week, I wanted to cover more about windows (both moving your cursor between them and moving the windows themselves around). After that, I have a bit of a mini section related to quickly adjusting visual selections.
---
# Moving Cursor between Windows
### These mappings make it trivial to move cardinally between/jump around windows.
#### These all accept a count and don't wrap around the screen.
- ctrl-w j
moves cursor one window down (it focuses the window below the current)
- ctrl-w k
moves cursor one window up
- ctrl-w h
moves cursor one window left
- ctrl-w l
moves cursor one window right
#### For these, window order is determined by splits; splits are worked through left-to-right/top-to-bottom (based on split type) recursively. Basically, these mappings prioritize windows within the most nested/inner split until hitting the last/first (depending on direction), then they continue to the next/previous split.
- ctrl-w w
without count moves cursor to next window
- ctrl-w w
with count moves cursor to the count
th window
- ctrl-w W
moves cursor to previous window (prioritizing windows within the same split until hitting the last one)
#### These are more situational.
- ctrl-w t
moves to first (top-left-most) window
- ctrl-w b
moves to last (bottom-right-most) window
- ctrl-w p
goes to previous window (jumps back and forth between the two most recent windows)
For more information, you can look into :h window-move-cursor
.
I find that mapping ctrl-h/j/k/l
(or alt-h/j/k/l
) to ctrl-w h/j/k/l
is quite useful/natural as you start to use these mappings more often. Also note that a good chunk of window mappings (not just for this section) have an alternate mapping of ctrl-w ctrl-KEY
to allow for keeping ctrl
held (which prevents having to alternate between holding and releasing ctrl
when repeating these mappings).
---
# Moving Windows Themselves Around
### These mappings help with reordering the windows visually. Unfortunately, they are not as granular as one might like.
#### Note that the first four have the last key capitalized; this means that you have to hold shift while hitting them (otherwise you would be using the lowercase variants from the previous section).
- ctrl-w J
moves current window all the way down (to the bottom)
- ctrl-w K
moves current window all the way up (to the top)
- ctrl-w H
moves current window all the way left
- ctrl-w L
moves current window all the way right
- ctrl-w r
rotates all windows within the current (innermost) split forwards (left-to-right/top-to-bottom depending on split type; must be done in an innermost split, as vim does not support moving a nested split as a single entity this way)
- ctrl-w R
rotates all windows within the current (innermost) split backwards (right-to-left/bottom-to-top depending on split type)
- ctrl-w x
without count exchanges current window with next window in current (innermost) split (or with the previous window if this is the last one)
- ctrl-w x
with count exchanges current window with count
th window of current (innermost) split (can't swap with a window that contains a split)
For more information, you can look into :h window-moving
.
Similar to the previous section, mapping ctrl-H/J/K/L
aka ctrl-shift-h/j/k/l
(or alt-H/J/K/L
) to ctrl-w H/J/K/L
can be useful if you see yourself needing to move windows relatively often.
---
# Quickly Adjusting Visual Selection
### Back when I first found out about these mappings, I was surprised by how much easier they made modifying/reusing visual selections. It's one of those QOL things which isn't strictly needed but takes out the tedium of a surprising number of tasks.
- v_o
(visual mode) o
moves cursor diagonally to other end of selection without changing it (swaps/reverses start and end points of selection); this is useful for if you want to quickly add/remove some words/lines at the other end of your selection
- v_O
(visual block mode
Adding plugins manually
Is there a way install plugins manually. My workplace vim setup is in a vanilla state. I could install the plugins since the servers are connected directly and does not have internet access. I'm hesitant to bring this up to the IT guys. Any ideas ? Thanks
https://redd.it/18pmaac
@r_vim
Vim-UTest: Vimscript unit testing plugin with mocking support
Hello fellow Vimmers,
I have recently released yet another unit-testing plugin for Vimscript. It's called Vim-UTest, where the "U" stands for "unit", or "you", or sometimes even "unicorn". Check it out on GitHub: https://github.com/cdelledonne/vim-utest
There are many great Vimscript testing projects out there: vim-testify, vim-UT, vader.vim, vroom, vim-vspec, vim-themis (and probably more). However, there is one fundamental feature that I was missing from all these: support for mocking. Without the ability to mock the dependencies of a certain unit, one can only test such a unit by crafting some elaborate system-level tests, which is the main reason why I never got around to writing tests for my other Vim plugin.
Vim-UTest has a simple interface (who doesn't claim this for their own plugins) and produces readable test report messages. Other than that, it has a bunch of other useful features:
Support for test fixtures with optional set-up and tear-down
Can be run from within Vim/Neovim as well as from the command line
Autocompletion for unit test names (when used from within Vim/Neovim)
Quickfix list population with test errors (when used from within Vim/Neovim)
Vim-UTest is ready to smack your buggy Vimscript plugins — only virtually of course, violence is by no means a feature of Vim-UTest. If you give it a try, let me know!
https://redd.it/18p8prl
@r_vim
Language server plugin for vim 7.4
I'm currently limited to 7.4, but I'm hoping to set up a language server. All the plugins I can find seem to require 8. Are there any options I'm missing?
https://redd.it/18oypgf
@r_vim
GVIM: resize font/window using keyboard mapping or mousewheel scrolling
​
https://i.redd.it/p688wznrgp2c1.gif
I was looking at the answers for this question on StackExchange and started modifying one the answers for Linux to make it work better and work with Windows. It was a lot more difficult than I was expecting, so I thought I might as well make it a plugin when I finally got it working well.
It changes the font size (and therefore window size too) in gvim, using Ctrl+/- or mousewheel.
Works on Linux and Windows.
https://github.com/eggbean/resize-font.gvim
https://redd.it/184cbbq
@r_vim
How do I create a new window (split) displaying the current buffer?
I ask because I accidentally did this and have no idea what I did to do it. Basically, if I'm looking at foo.txt, how can I quickly create a vertical or horizontal split that will also show foo.txt? Thanks in advance!
https://redd.it/183rq5l
@r_vim
Came across an interesting online Vim config generator
https://vimconfig.com/
However, the comments syntax is wrong (# instead of ")
https://redd.it/18v7v0g
@r_vim
Is it possible to show contextual help?
I am writing a program with many custom classes, each with several arguments. I sometimes forget the arguments. Then, I need to find the definition to figure out how to call it.
Is it possible to show a contextual help from the definition of a class?
For example, on some file, I got class SomeClass(*some-args)
On another place if I write SomeClass, I see some-args. Perhaps, it also shows me where the class is defined.
Sorry if it’s a bad question. Thank you for your time.
https://redd.it/18vrzga
@r_vim
Vim for Python
# Vim for Python
I'm new to Vim and have just gone through bunch of resources and created a setup for Python. Have a look:
Vim Screenshot
Overall works fine and has all major functionalities as required by me. I have also prepared a small documentation of all plugins, here have a look: https://github.com/saxena-codes/vim/blob/main/README.md
Also, referencing `.vimrc` file here: https://github.com/saxena-codes/vim/blob/main/.vimrc
Please let me know any more plugins you are aware and any suggestions to the setup are welcome.
Thanks in advance :-)
https://redd.it/18s4ow0
@r_vim
Replace a character
I am trying to copy and single character and then paste it in place of and other in a different line.
The characters are Unicode symbols (nerd fonts)
For the copy I do : yl
For replace and paste : — I am stuck —
r would get me in insert
d would then copy the character in the buffer …
What is the best way to do that ?
Thanks
https://redd.it/18r436c
@r_vim
installing Coq manually (linux)
I have to install packages in a linux system where a plugin manager won't work due to network restrictions. OTOH, I can download a zip of a plugin. I (hooray for me :-) was able to install NERDTree easily just by unzipping it into ~/.vim/pack/vendor/start.
Coq is not as easy, as it seems to depend on some lua packages, and I am clueless about lua. When I start up vim, I get an error messages saying "module 'coq' not found", and shows where it's looking. I've tried various things, and setting LUA_PATH removes some error messages, but then it still can't find lua.so.
I want to avoid an infinite regression of digging around, and I'd appreciate any advice!
https://redd.it/18ra4sz
@r_vim
About all other text inputs
Hello! Need advice on how to work with other software after diving in VIM. Constantly trying to use vim-movements and other commands. How you deal with that?
https://redd.it/18rv5ad
@r_vim
Some not-so-useful tips I recently learned
While reading quickref.txt I came across some interesting things, some more useful that others:
​
* Have you ever wondered how to make *cryptographically secure encodings*? I've got the answer: open vim, select your text and type `g?`. Your text is now encrypted by rot13! Want to decrypt it? Type `g?` again!
* This one is probably known, but I didn't: you can use `!` to send code to an external program and then back to vim, after being "filtered". Example: select your text, then type `!base64<CR>` and your text is going to be "filtered" with base64. It can also be used with sort, uniq, etc.
* You can use `:ce` to center some text. There's also `:le` and `:ri` for left and right align.
* This one is just ***✨exquisite✨***! Type `5gs` and vim goes to sleep for 5 seconds and becomes totally irresponsive. We all know the meme "turn your computer off to exit vim", but if you use `1000gs` there's no way to quit vim from within, you'll have to use some external method!
* ***Bonus tip:*** use `inoremap <Esc> <Esc>gs` for some extra fun!
But seriously, why are `g?` and `gs` a thing? They're completely useless
https://redd.it/18qvnm8
@r_vim
Mastering Vim: How to Solve AoV Challenges with Ease
https://youtu.be/YazmNjy-mCA?si=HT8wYsiJLARl1ukJ
https://redd.it/18qfe6z
@r_vim
only) O
moves cursor horizontally to other corner of selection without changing it; this functionality allows you to adjust your block selection in all cardinal directions when coupled with v_o
(note that v_O
behaves identically to v_o
in normal non-block visual modes since there are only two "corners"/ends at any given time)
- gv
(normal mode) reselects the previous selection (using the same visual mode it was last in)
- v_gv
(visual mode) gv
swaps back and forth between the current selection and the previous one (maintaining both of their respective visual modes)
For more information, you can look into :h visual-change
and :h visual-start
.
---
I had originally planned to primarily cover a bunch of miscellaneous mappings this week, but I decided to cover more window-related mappings (since I covered a chunk of them last week but didn't mention any of the ones related to moving the cursor between windows and moving windows themselves around).
Do you all feel that my lists are getting too long? Should I be reducing the number of topics per week and/or trying to be less detailed? Any feedback is welcome!
---
Previous (Week #2)
https://redd.it/18q7u2f
@r_vim
I Have Now Tried Several LSP's and Here are My Thoughts
I probably should have said LSP's/Linters in the title.
For the longest time I was using coc in vim. Probably about 3 years, so I have the most experience with it.
Within the last year I have been struggling with several tedious/annoying issues that are slowing down my productivity. You may never run into any of these issues with coc, and I certainly would recommend it if you are a beginner to vim. I'm not getting into the issue because I would still recommend it.
I have also tried setting up neovim. I spent the better half of 2 weeks trying to figure out the "easy" and "hard" way to get neovim going. Easy being, following some guides and use lspconfig. Hard being, learning how it all works and configuring it yourself. They both were terrible experiences. Lots of wasted time down paths with things that just didn't work. The "easy" path sort of worked, but making any slight change, or not liking one thing was a pain to figure out. I had a conversation with a coworker who goes all in on config and cool plugins, and asked me how come "eslint isn't auto fixing something that is fixable". This wasn't something I typically wanted, but I just couldn't find out how to with neovim. He ended up writing some gross lua code which could run eslint with fix on it on save. The time from when he did `:w` before was like 2 seconds, then it bumped up to 3 with this new code he wrote. I went back to my machine that had the issues with coc that I had had, and prettier was timing out, > 1 seconds. So maybe prettier is just getting pretty bad. A junior that uses vscode had no issues, prettier seemed pretty snappy (without eslint fix).
All that to say, I have always preferred minimal being better. Less code, fewer bugs. So in comes ALE. This was the fastest to set up, worked as a near perfect drop in replacement to coc. All coc functions had an exact replica for ale. I have reduced my vimrc even further, and only have one minor outstanding thing I need to figure out. I am going to continue using ALE, it is running faster than all the others and so easy to configure exactly how I want with far less config than neovim's lsp.
LESS IS MORE. (at least for me).
If you want MORE IS MORE I would recommend vscode
https://redd.it/18q2m9j
@r_vim
The vim way
I searched google for this but I can't find a way to do this in one command. Say I have multiple lines of text and there are specific words I need to copy.
I need to copy all the words that have # (ideally including the #) and paste them in some other part of the file (or on another file)
blah blah #word blah blah #word
#word blah blah #word blah blah
blah blah #word blah blah #word
I tried :'<'>g/#\w\+ (and this highlights the words properly) but I'm stumped as to how to yank just the words into a register. When I try something like norm "Ayy or norm "Ayiw, they either copy the whole like or copy the first character of the line that has the # on it.
Is there a better way to do this? or do I just do a macro that copies the whole line, then deletes everything that doesn't have a # (which sounds more complicated now that I think about it and would require what I want to do in the first place)
https://redd.it/18pcd84
@r_vim
What are nice color schemes for Vim on terminal of Win (= CMD.exe)?
**Hi** The settings of vim on terminal is limited, not all color schemes are showed full. colors of letters, background color too are changed.
I screenshoted my :set for data: https://imgbox.com/C6yaNrFP
I like blue colors. and soft background colors.
I use some but find another is cool...
Murphy, solarized8_high, elflord ... ¿more?
Thank you and Regards!
https://redd.it/18p5dr4
@r_vim
Move to line + Refocus window
Vim newbie here. Is it possible to do something like:
nmap gg ggzz
nmap G Gzz
nmap :<num> " and then it automatically does zz
So as to be able to refocus your screen automatically when jumping by many lines? I tried the above approach but with no success.
Thanks
https://redd.it/184bkj3
@r_vim
Vimscript - find line matching regex and then color word matching other regex
I'm looking for a way to write some configuration in my vimscript file to find lines matching certain regex and then colour the specific word in those lines matching another regex.
For example, when I'm writing, grab everything after it, before the colon, C++ code, I want to find all lines with a case
keyword, grab everything after it, before the colon, and then color it in blue.
https://redd.it/18482kc
@r_vim
How easy is it to setup Neovim and Nvchad on windows?
I have researched quite a bit and found neovim to be quite good. I haven't used it but I use VIM. I saw nvchad was pretty good too.
My question- Is it easy to setup nvim and nvchad in windows? What could be the way if anyone of you could elaborate?
https://redd.it/183m9wn
@r_vim