This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-07
Channels
- # asami (1)
- # aws (2)
- # babashka (5)
- # babashka-sci-dev (162)
- # beginners (68)
- # biff (1)
- # calva (26)
- # circleci (4)
- # clj-kondo (5)
- # cljs-dev (7)
- # clojure (84)
- # clojure-europe (15)
- # clojure-uk (1)
- # clojured (2)
- # clojurescript (19)
- # conjure (1)
- # datomic (5)
- # emacs (2)
- # graalvm (20)
- # honeysql (6)
- # improve-getting-started (2)
- # kaocha (3)
- # lsp (31)
- # off-topic (7)
- # pathom (7)
- # releases (1)
- # shadow-cljs (1)
- # spacemacs (1)
- # vim (30)
g*
or g#
- the same as *
or #
but do not limit search to word boundaries, includes partial matches
Two others I use a lot are q:
and q/
to bring up command and search history, respectively, and search/edit them before running again.
While we're on the topic of *
and #
:
• You can also highlight part of a word in visual mode and then press *
and #
to search for other occurrences of that string in the buffer.
• When you're highlighting all occurrences of a string via *
or #
, you can use :%s
to replace all of the occurrences with something else, by omitting the first part ("what to replace") of the sed expression. For example, place your cursor over foo
, press *
to highlight all instances of foo
, then enter :%s//bar
to replace all foo
instances with bar
.
Wow, g*
and g#
are really nice when I want to search for keywords AND the corresponding symbols in let-bindings, function params, etc., which doesn’t really work with just *
/`#`.
I use marks frequently, but double-tick ''
is great because it returns the cursor to where you were before the last jump. And '.
takes you back to where you last edited something.
If you have a column of some repeating number like:
1
1
1
You can select them in visual mode and hit g<C-a>
to turn them into an ordered list like:
2
3
4
and you can prepend a count like 10g<C-a>
to increment by some number other than 1:
11
21
31
Vim + tmux + christoomey/vim-tmux-navigator + esamattis/slimux => an instant IDE for anything that presents a command prompt. Bash, R, TCL, Python, anything!
Not sure if it's a tip, but want to share anyway and may be someone will be inspired by it and decided to write something like this / copy my code. I have a hotkey (comma + k), that checks the project root dir and launches an appropriate repl (lein, cli, or clojure-dart). It's written on fennel, but it's pretty easy to achieve: https://github.com/Liverm0r/dotfiles/blob/master/.config/nvim/fnl/lang/clojure.fnl Repl runs inside the built in terminal. Vim-iced or Conjure will be able to connect to it automatically.
If you’re not using macros, you’re not living. To start recording, hit q
followed by some letter, which will be the name of the macro. Like qa
.
Then, do your stuff.
Once you’re done recording, hit q
once more.
Now, you can replay your recorded actions with @
followed by the name of your recorded macro, like @a
.
What I normally use it for is doing repetitive linewise changes. It’s hard to come up with good examples, but here’s one.
As a part of an edit, I want to turn
this.x = args[0];
into
this.x = args[0];
this.x = args[1];
this.x = args[2];
this.x = args[3];
this.x = args[4];
this.x = args[5];
Standing on the first column of the first line, I do
qayyp<C-a>q4@a
Breaking it down:
qa
• start recording the macro named a
yyp
• copy the line and paste on the next line
<C-a>
• increase the number by 1
q
• stop recording the macro
4@a
• execute the macro a
4 times.
It’s a silly example. The point is that you can do arbitrarily complex sequences of actions that you can repeat freely.I’m sure I’m not even close to the awesomeness that you can achieve with macros, but I use them whenever I can, so maybe I’ll get there eventually.
Oh yes, so true. Macros in Vim are amazing. can be a bit daunting to compose them in a flexible way, but the reward is worth it.
@U0510902N are there any patterns for constructing macros that you like to use?
Or just any use cases where you tend to apply them?
I feel like I’m holding myself back by sticking to linewise changes or “find next x
and do y
“ish changes
I use macros all the time, for all kinds of stuff, not limited to linewise changes. I definitely recommend using them whenever you find yourself making the same kind of mechanical change in a bunch of different places.
There is a bit of an art to using the right kinds of motions in your macro that will work at every site where you want to apply the macro. For example, avoid using hjkl
to move around, because the number of spaces you'll need to move could vary between the sites. It's often better to use word-wise motions, use f
to jump to a specific character like {
, etc.
I tend to use qq
to start recording because it's easier to type than e.g. qa
. I rarely need to record more than one macro at a time, but in the extremely rare case that I do, then I use other characters, like qa
, qb
, qc
etc.
Use @q
to replay your macro the first time, but then after that, you can use @@
to replay the last macro that you played. That's nice because you can quickly replay the same macro at various sites by pressing the @
key over and over.
If you happen to know how many times you want to apply the macro, then you can do like 4@@
, as mentioned above.
Another hot tip: Whenever possible, make your macros include the steps that it takes to end up on the next instance that you want to call the macro. For example, if I'm writing a macro that I want to apply on every other line, starting at the beginning of the line, then I might end the macro with jj0
to go down two lines and position the cursor at the beginning of the line.
That way, you can really fly -- you can press @@
repeatedly to apply your macro over and over, without needing to reposition the cursor in between.
@U0AQ3HP9U basically, every thing that @U0AHJUHJN said is what I was going to say. Well put!
Thank you, @U0AHJUHJN! 😄
I tend to use f
, /
or just moving to the next line as my "set up for the next invocation" move. And I also tend to use qq
- it was just easier to illustrate qa
😄 But I did not know about @@
! I'll make sure to use that from now on.
Using macros feels a bit like on-the-fly programming for text editing... Write the source for the function, then call it when you need it. So damn cool.
Another macro tip I don't think has been registered here: you can record a macro to a register like q, then do a visual block selection and execute the macro on each line of the selection with :'<,'>norm @q
. Or you can search for a pattern with /
and then apply the recorded macro to each line that matches with :g//norm @q
... or each line that doesn't match with :v//norm @q
.
I feel like I don’t use the :g
or :v
stuff enough
Thank you for the tip!
To delete until some pattern I usually use in normal mode d /foo