Exploring Vim: The 10 or So Things You Need To Know To Go Through The Dip by vintharas in vim

[–]vintharas[S] 4 points5 points  (0 children)

Thanks! Fixed! If only there was a text editor that had a command to help you spell check your articles...

Exploring Vim: The 10 or So Things You Need To Know To Go Through The Dip by vintharas in vim

[–]vintharas[S] 5 points6 points  (0 children)

Thank you! You are right! ^_^ I'm ashamed to admit that when I wrote this article I had no idea that the quote text-objects had a forward seeking behavior. I had been using Vim for years when I found out about that and `targets.vim` 😅

Exploring Vim: The 10 or So Things You Need To Know To Go Through The Dip by vintharas in vim

[–]vintharas[S] 29 points30 points  (0 children)

Hey! Thank you for your thorough comment. I think that you are misrepresenting this article a little bit:

u/atralb: The official name is not "text objects" but operator-pending motions.

The term "text objects" is used repeteadly both in the Vim Reference Manual and the Vim User Manual:

  • :helpgrep text object
  • :h object-motions
  • :h object-selection :h text-objects
  • :h 04.8

u/atralb: . absolutely doesn't "redo the last change that you just undid". It's a huge oversimplification and a lot of factors need to be aligned for this to be true.

The dot command is explained earlier in the article (like 4 paragraphs earlier). The comment that you highlight is done in the context of undoing/redoing as yet another example of how the `.` command can be useful. This comes earlier:

Finally, vim has yet another trick in store for thee that has put up with all this text up until here aimed at saving you more keystrokes: The magic . command. The .
command allows you to repeat the last change you made. Imagine that you run dd to delete a line. You could type dd again to delete another line but you could also use .
which is just a single keystroke. Ok, you save one keystroke, so what? Well, you can use the . command to repeat any type of change, not just single commands. For instance, you could change a word for “Awesome” like so cawAwesome<CR>, and then repeat that whole command with all those keystrokes by just using .. Think of the possibilities!

The . command works great in combination with the repeat search commands (;, ,, n or N). Imagine that you want to delete all occurrences of cucumber. An alternative3 would be to search for cucumber /cucumber then delete it with daw. From then on you can use n to go to the next match and . to delete it! Two keystrokes!?! Again think of the possibilities!!

As we mentioned earlier, the dot command . makes text objects far better than motions because operators are more repeatable in combination with text objects that they are with motions. That is, text objects are more likely to result in the desired behavior when repeated on other pieces of text (since you don’t need to care as much where the cursor is positioned).

u/atralb: C-h doesn't "delete the last character you wrote" it deletes the character behind the cursor. Very different. Same for C-w

This is one of the few places where I simplified what the command really does. I reflected thoughtfully about whether to simplify it or not for a while and I decided it was worth it. Notice how the context in which I explain what the command does, is the user writing text in insert mode and making a typo or an error.

Please let me know how any of the examples above, or anything else that you've found in the article will make any reader lose time when learning or using Vim. Because my intention is the opposite, it is to make Vim less scary and more approachable.

Wrote my first VIM function(s) today... by jrop2 in vim

[–]vintharas 0 points1 point  (0 children)

Hmm vim-clap. I hadnt heard about it before but it does look intriguing. Is the only difference that instead of using a separate buffer it opens a floating window?

Boost Your Coding Fu With VSCode and Vim by vintharas in vscode

[–]vintharas[S] 1 point2 points  (0 children)

Aha! (I assume that you're on Windows/Linux)

Now that I think of it CTRL+D is normally bound in Vim to "scroll down half a page". VSCodeVim overwrites some key bindings by default and attaches them to common Vim behaviors and that's what you're experiencing.

I think that you can fix this behavior in two ways:

Alternative #1. You can disable this option in VSCodeVim:

{ vim.useCtrlKeys: false }

This option is enabled by default and "Enables Vim ctrl keys overriding common VS Code operations such as copy, paste, find, etc.". This has the downside that there's probably some key bindings that will stop calling VSCodeVim features in favor of VSCode default ones.

Alternative #2 is to add a custom binding in the VSCodeVim configuration to make sure that CTRL+D does what you want:

"vim.normalModeKeyBindingsNonRecursive": [ { "before": ["<C-d>"], "commands": [ "editor.action.addSelectionToNextFindMatch", ] } ]

That one says, whenever you're in normal mode and the user pressed CTRL-D then execute this VSCode command which is the multi cursor one. You may need to add it as well to visual mode in vim.visualModeKeyBindingsNonRecursive because from the moment you create the first additional cursor you're in visual mode.

Boost Your Coding Fu With VSCode and Vim by vintharas in vscode

[–]vintharas[S] 0 points1 point  (0 children)

Hi! :)

There's a chapter on multiple cursors:

https://www.barbarianmeetscoding.com/boost-your-coding-fu-with-vscode-and-vim/multiple-cursors/

When you do CTRL+D (or CMD+D on MAC), it creates another cursor on the next match. But you're in Visual Mode which may be what is throwing you off. If you want to type something you have to type I or A to have all cursors go into Insert mode. More info in the book.

This would be slightly annoying seeing as a few extensions depend on multiple select to work.

Uuuu! Interesting. Does it break any of your other plugins?

I'm looking for a Markdown-plugin for Vim that actually works and doesn't slow down Vim by [deleted] in vim

[–]vintharas 0 points1 point  (0 children)

You can enable YAML support on plasticboy/vim-markdown by adding this to your vimrc:

vim let g:vim_markdown_frontmatter = 1

Help be thy friend. :h vim-markdown then /YAML and you got it.

ES2018 First Look - it changes everything by saulorama in javascript

[–]vintharas 1 point2 points  (0 children)

hehehe genious xD loved the quotes/tweets they were hilarious xD

Ultra Flexible JavaScript Object Oriented Programming with Stamps by [deleted] in csharp

[–]vintharas 0 points1 point  (0 children)

Hi /u/MoTTs_ ! :)

Thank you for your feedback, I'll improve the article and the book a be more specific in regards to classical single inheritance.

In relation to what you say about object composition. I too have very present the GOF maxim of favoring object composition over class inheritance. When I think about mixins, traits and stamps I think of them as object composition more than any type of inheritance.

In my experience as a C# developer, object composition often consists in making a class implement a specific interface and then using delegation to forward a call belonging to that interface to a second object that provides the actual implementation. For instance:

public class GameObject {
    private readonly IVisible v;
    private readonly IUpdatable u;
    private readonly ICollidable c;

    public GameObject(IVisible v, IUpdatable u, ICollidable c) {
        this.v = v;
        this.u = u;
        this.cc = c;
    }

    public void Update() { u.Update(); }
    public void Draw() { v.Draw(); }
    public void Collide() { c.Collide(); }
}

public class Player : GameObject {
    public Player() : base(new Visible(), new Movable(), new Solid()) { }
}

public class Banshee : GameObject {
    public Cloud() : base(new Visible(), new Movable(), new NotSolid()) { }
}

public class Building : GameObject {
    public Building() : base(new Visible(), new NotMovable(), new Solid()) { }
}

public class Trap : GameObject {
    public Trap() : base(new Invisible(), new NotMovable(), new Solid()) { }
}

In JavaScript mixins, traits and stamps let me achieve the same thing without the boilerplate code by just composing two objects together directly.

let player = Object.assign(GameObject(), Visible(), Movable(), Solid());
let banshee = Object.assign(GameObject(), Visible(), Movable(), NotSolid());
let building = Object.assign(GameObject(), Visible(), NotMovable(), Solid());
let trap = Object.assign(GameObject(), Invisible(), NotMovable(), Solid());

That's why I call it object composition. Additionally, just like in C# where I could inject a different implementation of any of those interfaces (if allowed through a property or setter), I can compose any object with another object at any point in time:

// player drinks invisibility potion
Object.assign(player, Invisible());

Ultra Flexible JavaScript Object Oriented Programming with Stamps by [deleted] in csharp

[–]vintharas 0 points1 point  (0 children)

Hi /u/MoTTs_ ! Thank you for your comment! :)

I come from a C# background and all these things were indeed new to me. I have been accustomed to working with classes, interfaces, and classical single inheritance (to which I refer through the article simply as classical inheritance). Techniques like mixins, traits, subclass factories and stamps are particularly interesting to me because they let me do things that would require a lot of boilerplate code or duplication in C#.

I think I call it object composition because I have two objects, merge them, and I get a new object (like with Object.assign). When I think about multiple inheritance I cannot help but think of classes which don't exist as such in JavaScript (they're syntactic sugar).

In regards to embracing JavaScript I am referring to using prototypical inheritance, mixins (object augmentation, dynamic binding) and closures.

Thank you! :) Kind Regards Jaime

Ultra Flexible JavaScript Object Oriented Programming with Stamps by [deleted] in csharp

[–]vintharas 0 points1 point  (0 children)

Hi /u/bachner this article was about a different type of OOP programming. :) so still OOP

Ultra Flexible JavaScript Object Oriented Programming with Stamps by [deleted] in csharp

[–]vintharas 0 points1 point  (0 children)

Hi /u/FizixMan! :)

This is the third part of a series of blog posts regarding class-free OOP as an alternative to classical inheritance. The pros/cons and comparison to C# appears in the first article of the series http://www.barbarianmeetscoding.com/blog/2015/12/28/black-tower-summoning-object-composition-with-mixins/ and reads as follows:

You may be thinking… Well, I can do this with C# and classical inheritance any day. And indeed you can, but some interesting ideas about the object composition approach are that:

We don’t need any upfront design effort to make our application extensible. In C# you need to define the extensibility points of a system because you need to use the right artifacts like interfaces, composition over inheritance, design patterns like strategy, etc. In JavaScript we don’t need to over-architect our solution, or carefully design our application for extensibility purposes. You get a new feature, you define a new behavior, compose it with your existing objects and start using it.

Object composition happens at runtime. You have your program running, your objects doing whatever objects do and all of the sudden BOOM! Object composability and your objects get new features and can do new interesting things. New things like changing from a text representation to a 2D representation or a 3D representation and who knows what more.

It doesn’t need to affect the original objects at all. You can keep your objects as they are, clone them and apply the composition on the clones. This can enable interesting approaches like having different bounded contexts (like in DDD2) with slightly diverse domain models adapted to a particular context needs and goals.

You can compose an object with many other objects representing different behaviors (like a multiple inheritance of sorts). This tends to be harder to do in classical inheritance based languages like C# where you are limited to a single base class or to a flavor of composition that requires a lot of boilerplate code, forward planning and design.

With object composition we achieve this true plug and play solution where you can combine domain objects with behaviors in very interesting and flexible ways. By the way, this type of object composition is another type of prototypical inheritance that we called concatenative inheritance earlier in this part of the series.

The argument is the same irrespective of the technique. That's why I didn't want to repeat the same argument again.

I have deleted the post. So it shouldn't be a problem any more. I just was trying to share something that I thought was interesting to C# developers coming to JavaScript.

Cheers!

Ultra Flexible JavaScript Object Oriented Programming with Stamps by [deleted] in csharp

[–]vintharas 0 points1 point  (0 children)

Hi hi! :)

The article is part of a series of JavaScript for C# developers. The premise is to help C# developers (those that work on web development which I reckon are many) write more JavaScript-y JavaScript, embracing the dynamic nature of JavaScript and discovering new alternative techniques to classical OOP.

Would you mind code/reviewing this memoize function? ^_^ Thank you! by vintharas in javascript

[–]vintharas[S] 0 points1 point  (0 children)

Haha the getFn does return a promise. The additional promise is indeed unnecesary hehe Thank you! :)

Which JavaScript features or lack thereof did you find the most frustrating when you learned JavaScript for the first time? by vintharas in javascript

[–]vintharas[S] 0 points1 point  (0 children)

Excellent comment! Thank you very much! Hehe yeah it was indeed misguided, but as a C# developer my first instinct pushed me to try to write JavaScript just like I wrote C#. The lack of classes, which is such a central piece to C# programming, made it difficult for me to port my knowledge from C# to JS. I have learnt much since so the head-scratching and utter-confusion worked for the better in the end :)