|
| is the statement separator, similar to ; in many languages. g invokes everything after it on each line matching the pattern. The thing after it is two statements: a replace operation on that line, and a let to increment the variable. The number increments because only the stuff after g// is run for each match, not the stuff before it. Here is that line translated to a more verbose pseudocode:code:
|
# ? Aug 11, 2013 16:36 |
|
|
# ? May 8, 2024 06:13 |
|
ArcticZombie posted:
See :help sub-replace-expression or :help sub-replace-\=. :s/<p>/\='<p id="'.n.'">'/ is replacing each <p> with the concatenation of the string <p id=", the contents of the vimscript variable n and the string ">. . is the concatenation operator in vimscript (see :help expr-.). The vertical bar is basically just the equivalent of a semicolon in C; it allows multiple expressions on the same line. See :help :bar. I say basically because it has different behavior when following certain commands, :g (a.k.a. :global) being one of them. Also check out :help :g. That command has two arguments (separated by / or whatever). The first is the pattern it matches, the second is the Ex command it runs on those lines. In this case, it matches any line containing <p> and replaces it as explained above. Then follows the nonstandard behavior of the vertical bar used after :g. Instead of just moving on to the next match, it first runs the command after the bar and thus increments n. Only after that command finishes does it move on to the next matching line. And to leave no stone unturned, :let declares an internal vimscript variable. n is still going to be there after the command finishes running, so you can use it afterwards if you'd like. Hope that helps! fidel sarcastro posted:In fact, the whole thing sounds like it's behaving like a C-style for loop but a quick search says Vim doesn't have any support for them? :help for / :for EDIT: For example: :for i in range(10) | echo i | endfor The Laplace Demon fucked around with this message at 16:43 on Aug 11, 2013 |
# ? Aug 11, 2013 16:38 |
|
Thanks fellas. I don't often use vim, in fact I only used it in this instance because of the ability to set a variable and increment it like that which you can't do with just plain regex in other editors.
|
# ? Aug 11, 2013 17:57 |
|
The Laplace Demon posted::help for / :for Whoops, I apparently mistook "doesn't support the exact same syntax" for "doesn't support for loops." Edited my post.
|
# ? Aug 11, 2013 18:08 |
|
Need a recommendation for convenient bindings for quickfix list commands. Mostly open, close, next, previous etc. What do you guys use? Been playing with Ack.vim + AG and would love to make that navigation snappier. Experimenting with the following: code:
DreadCthulhu fucked around with this message at 01:56 on Aug 18, 2013 |
# ? Aug 18, 2013 01:34 |
|
DreadCthulhu posted:Need a recommendation for convenient bindings for quickfix list commands. Mostly open, close, next, previous etc. What do you guys use? I'm a big fan of tim pope's vim-unimpaired: https://github.com/tpope/vim-unimpaired
|
# ? Aug 19, 2013 11:13 |
|
Oh man that's got a LOT of stuff in it, I'll have to do some cherry picking.
|
# ? Aug 20, 2013 21:35 |
|
Just wanted to re-emphasize how amazing that PragProg book for Vim is. If you don't know where to start or where to go, seriously consider checking it out. Just finished reading it after over a year, and I still need to go back and review a lot of its tricks.
|
# ? Aug 29, 2013 00:34 |
|
Something totally awesome I just discovered, not sure how I lived without this: Want to work on two or more repos in one vim? Open a new tab with :tabnew, :lcd %repo_path% and now all the windows spawned in that new tab will inherit the same :pwd and you can CTRL-P your worries away. For bonus points, if you already have a tab with a bunch of open windows whose pwd is all over the place, just :windo lcd %repo_path% and you're golden.
|
# ? Sep 15, 2013 04:59 |
|
anyone using powerline for vim? https://github.com/Lokaltog/powerline
|
# ? Dec 4, 2013 11:28 |
|
smug forum rear end in a top hat posted:anyone using powerline for vim? https://github.com/Lokaltog/powerline I'm using airline, same idea though. They're both really good.
|
# ? Dec 4, 2013 13:57 |
|
fidel sarcastro posted:I'm using airline, same idea though. They're both really good. Yeah I've found airline to be more lightweight and easier to deal with.
|
# ? Dec 4, 2013 13:59 |
|
Thanks guys, airline seems great. I discovered that powerline in vim would sometimes interfere with my ability to do things in git (couldn't get control of git's index.lock) because it was polling for git status and branchname or something. It made interactive rebase incredibly painful, especially when manipulating large ranges of commits. Maybe it's just because I was using an outdated version of powerline, but for now I'll just see how things go with airline.
|
# ? Dec 4, 2013 15:26 |
|
I finally got motivated to sit down and rewrite my vim config. Despite getting over the "turn VIM into an IDE" bug and slimming it down by 1/3rd it's still 125 lines. Sure runs a lot better, though.
|
# ? Dec 4, 2013 19:43 |
|
Yeah Airline is nice. I held off for months but finally patched my fonts and they do look a lot nicer (I use inconsolata). Also have a vim plugin that sets my tmux status bar to match the vim one (But you can change its colour scheme if you want).
|
# ? Dec 5, 2013 20:57 |
|
How would I go about removing leading blank lines from a buffer in vim?
|
# ? Dec 10, 2013 04:37 |
|
A nice little video to show you just how far off a VIM master you really are.
|
# ? Dec 10, 2013 04:53 |
|
FamDav posted:How would I go about removing leading blank lines from a buffer in vim? gg/.<CR>kdgg
|
# ? Dec 10, 2013 06:03 |
|
Ever since I learned about the find character command (f) I use ; a lot. I learned about it in some video that I can't find now, I guess it was by the Practical Vim guy?
|
# ? Dec 10, 2013 10:15 |
|
That drag visual block function at the end is nice!
|
# ? Dec 10, 2013 11:45 |
|
Symbolic Butt posted:Ever since I learned about the find character command (f) I use ; a lot. vimcasts.com
|
# ? Dec 10, 2013 23:27 |
|
I recently found out that you can now set 'relativenumber' and 'number' at the same time, and vim will show an absolute line number for current line and relative line numbers for the rest.
|
# ? Dec 11, 2013 01:06 |
|
Cat Plus Plus posted:I recently found out that you can now set 'relativenumber' and 'number' at the same time, and vim will show an absolute line number for current line and relative line numbers for the rest. And if you use numbers.vim you also get relative numbering in normal mode, and absolute in insert mode as a bonus. Tiger.Bomb posted:gg/.<CR>kdgg Intuitive.
|
# ? Dec 11, 2013 17:38 |
|
fidel sarcastro posted:And if you use numbers.vim you also get relative numbering in normal mode, and absolute in insert mode as a bonus. I get something similar with: code:
|
# ? Dec 12, 2013 14:28 |
|
Tiger.Bomb posted:vimcasts.com Oh it was this one http://vimcasts.org/blog/2010/11/arrrrcamp-presentation-vim---walking-without-crutches/ thanks!
|
# ? Dec 12, 2013 14:35 |
|
Marsol0 posted:I get something similar with: Slick, I'll have to tinker with that. Not that numbers is an overly large plugin but hey, one less thing to install.
|
# ? Dec 12, 2013 15:59 |
|
As someone who is a really dedicated vim user, is there a reason to try eclim? I don't write Java. I'm not sure what IDE features from Eclipse I'm actually missing out on. My primary languages are Go, R, and Python. Is the stuff from Eclipse just more useful for Java/C++?
|
# ? Dec 20, 2013 12:48 |
|
Chin Strap posted:As someone who is a really dedicated vim user, is there a reason to try eclim? I don't write Java. I'm not sure what IDE features from Eclipse I'm actually missing out on. My primary languages are Go, R, and Python. Is the stuff from Eclipse just more useful for Java/C++? Thanks for bringing that up. I'm starting to work in Scala more and it just so happens that the Scala IDE from Typesafe is done with Eclipse so it'd be great if I can connect vim to that.
|
# ? Dec 20, 2013 13:30 |
|
Chin Strap posted:As someone who is a really dedicated vim user, is there a reason to try eclim? I don't write Java. I'm not sure what IDE features from Eclipse I'm actually missing out on. My primary languages are Go, R, and Python. Is the stuff from Eclipse just more useful for Java/C++? You're missing out on fun features like forgetting how to render text properly, randomly occurring internal errors, and "restart" option built-in. Eclipse is not very good. For Python you could take a look at PyCharm, which recently got a free version (it also has Vim emulator, IdeaVim; haven't used it though).
|
# ? Dec 20, 2013 13:33 |
|
Cat Plus Plus posted:You're missing out on fun features like forgetting how to render text properly, randomly occurring internal errors, and "restart" option built-in. Eclipse is not very good. I'm not all that interested in switching away from my highly custom vim without good reason. I see a lot of coworkers liking Eclipse, but they are all Java guys so that must explain it.
|
# ? Dec 20, 2013 13:34 |
|
Chin Strap posted:As someone who is a really dedicated vim user, is there a reason to try eclim? I don't write Java. I'm not sure what IDE features from Eclipse I'm actually missing out on. My primary languages are Go, R, and Python. Is the stuff from Eclipse just more useful for Java/C++? If you do decide to stick with Eclipse, I was using vrapper when I last used Eclipse heavily, and it was pretty good. It had one cool feature that I've not seen in any other vim plugin for an IDE - a toggle button to make it easy to turn off when others are coding in your IDE.
|
# ? Dec 21, 2013 17:12 |
|
What is the quickest way to tranform this:C++ code:
C++ code:
|
# ? Apr 3, 2014 12:48 |
|
Dicky B posted:What is the quickest way to tranform this: code:
|
# ? Apr 3, 2014 13:22 |
|
You might want something like :s/[(,]/\0\r/g in order to break after the opening paren as well as between arguments, and insert all the breaks you want instead of just the first one.
|
# ? Apr 3, 2014 13:48 |
|
Cool, I've ended up with :s/[(,]\s\?/\0\r\t/g which sorts the indentation out as well. Thanks for pointing me in the right direction!
|
# ? Apr 3, 2014 14:30 |
|
I know you can map a command on a search with g like '1,$ g/bad things/d'. Is there a way to map a macro across a regex as well? Edit: forgot range in example :g/<pattern>/normal @q leper khan fucked around with this message at 18:49 on Apr 7, 2014 |
# ? Apr 7, 2014 18:03 |
|
leper khan posted::g/<pattern>/normal @q Could you unpack that? Is q the macro name?
|
# ? Apr 7, 2014 18:53 |
|
Subjunctive posted:Could you unpack that? Is q the macro name? q is the register where the macro is stored. The normal command treats whatever comes after as if it had been typed on the current line in normal mode, so when you do that across a range, it applies the normal mode commands to each line in the range. I use :'<,'>norm (or numbered ranges) for . and & a lot, and it's great for macros, too. It's a pretty awesome command.
|
# ? Apr 7, 2014 18:59 |
|
MacGowans Teeth posted:q is the register where the macro is stored. The normal command treats whatever comes after as if it had been typed on the current line in normal mode, so when you do that across a range, it applies the normal mode commands to each line in the range. I use :'<,'>norm (or numbered ranges) for . and & a lot, and it's great for macros, too. It's a pretty awesome command. code:
You can chain multiple calls if you have an enter key press in a register. I can't work out how to paste one into the command line without having pre-recorded it though. code:
Where ^M is a pasted enter, to record one to register q ( qq<Enter>q ) and paste with control-r q.
|
# ? Apr 11, 2014 15:26 |
|
|
# ? May 8, 2024 06:13 |
|
Destroyenator posted:You can chain multiple calls if you have an enter key press in a register. I can't work out how to paste one into the command line without having pre-recorded it though.
|
# ? Apr 11, 2014 16:07 |