cabinSource code for personal website |
git clone git://git.dimitrijedobrota.com/cabin.git |
Log | Files | Refs | README | LICENSE |
VimShowcase1.md (6356B)
0 @date: 2021-08-20
1 @title: Vim Showcase #1 - Text Object
2 @language: en
3 @categories: linux, vim
5 # Vim Showcase #1 - Text Object
7 Welcome to the new series called **"Vim Showcase"**
9 In this series, as the title suggests, I am going to showcase vim and all of
10 its wonderful features as well as plugins>
12 Even though I am starting this series off by showcasing plugins, I will try to
13 cover the vanilla vim as much as possible.
15 I restrain myself from using too much plugins as I find vim really usable out
16 of the box (with some tweaking of course), but sometimes it takes just a
17 handful of small, lightweight plugins to enhance the vim experience and boost
18 the writing speed by simplifying repetitive and tedious tasks.
21 ## Introduction
23 With vim being the editor with a primary focus on editing text, it's fair to
24 say that it is filled to the brim with features that support that.
26 Today I am going to present to you a few plugins that complement existing
27 features as well as bust your productivity while writing.
29 For the rest of the article I will assume that you know how to install vim plugins.
31 If you are new to the world of vim plugins make sure to check out my previous
32 article on how to install plugins with plugin manager. It can be found [HERE](https://dimitrijedobrota.com/articles/VimPugins.html)
35 ## Textobj User by kana
37 This plugin is the base that all of the other plugins that I am about to showcase today are based on.
39 This plugin is, in essence, a framework that allows it's users to easily define
40 new text objects by helping you avoid common pitfalls as well as hiding all of
41 the tedious implementation details, allowing you to focus on the task at hand.
43 You can install it by putting the following line in your `vimrc`:
45 Plugin 'kana/vim-textobj-user'
47 Instruction on how to use this plugin can be found on [Github](https://github.com/kana/vim-textobj-user),
49 Before do so, it's a good idea to get a feel for what kind of functionality it
50 is used for by reading ahead or full checking out the full list of other
51 plugins that depend on this one [here](https://github.com/kana/vim-textobj-user/wiki).
54 # Textobj Brace and Textobj Quotes
56 If you want to quickly change all of the parameters of a function, array
57 initialization or anything else that revolves around quotes or braces, vim has
58 you covered.
60 Text object 'Inside' or `i` is very powerful utility. It works with:
62 - Brackets: `(`, `[` and `{`
63 - Quotes: `'`, `"` and ```
64 - Tag: `t`
66 It allow you to use any motion and the contents of the brackets or quotes. You can delete, change, yank and more.
68 After a while, it gets tedious to always have to specify the exactly what you want to change. That's where these two plugins step in, and go one step further. The plugins provide the following set of binding:
70 - Brace:
71 - `ij`: operate on the content between the closest pair of braces
72 - `aj`: operate on the content between the closest pair of braces, including the braces
73 - Quotes:
74 - `iq`: operate on the content between the closest pair of quotes
75 - `aq`: operate on the content between the closest pair of quotes, including the quotes
77 Where these two plugins shine, apart from being able to target the surrounding itself, is that you don't even need to be inside the area to do the change.
79 It's easier to understand by looking at examples (the cursor is shown with `|`):
81 1. Before: `foo '1, |2, 3' bar`; after pressing `diq`: `foo '|' bar`
82 2. Before: `foo| '1, 2, 3' bar`; after pressing `diq`: `foo '|' bar`
83 3. Before: `foo '1, 2, 3' |bar`; after pressing `daq`: `foo | bar`
85 These plugins can be installed with:
87 Plugin 'Julian/vim-textobj-brace'
88 Plugin 'beloglazov/vim-textobj-quotes'
91 # Textobj Variable Segment
93 Renaming is an unavoidable part of any project, whether it be a CSS attribute
94 or a variable name, you often have to deal with `snake case` and `title case`
95 text, which can be a pain to do in vim. This plugin is here to solve that
96 problem.
98 It provides two bindings `iv` and `av` and their usage is illustrated in the example:
100 - Before: `foo_ba|r_baz`; after pressing `civ`: `foo_|_baz`
101 - Before: `QU|UX_SPAM`; after pressing `civ`: `|_SPAM`
102 - Before: `eggsAn|dCheese`; after pressing `civ`: `eggs|Cheese`
103 - Before: `_privat|e_thing`; after pressing `civ`: `_|_thing`
105 - Before: `foo_ba|r_baz`; after pressing `dav`: `foo_baz`
106 - Before: `QU|UX_SPAM`; after pressing `dav`: `SPAM`
107 - Before: `eggsAn|dCheese`; after pressing `dav`: `eggsCheese`
108 - Before: `_privat|e_thing`; after pressing `dav`: `_thing`
111 This plugin is installed with:
113 Plugin 'Julian/vim-textobj-variable-segment'
116 # Textobj Parameter
118 When dealing with functions, changing names and types of the parameters is inevitable. To make that process more easy consider using this plugin.
120 Following the logic of the previous ones, this one allows you to change each of the parameter one by one. Look at the example:
122 `i,` to inner parameter object
124 ```
125 function(param_a, param_b, param_c)
126 |<--->| |<--->| |<--->|
127 ```
129 `a,` to a parameter object including whitespaces and comma
131 ```
132 function(param_a, param_b, param_c)
133 |<----->|
134 function(param_a, param_b, param_c)
135 |<----->|
136 function(param_a, param_b, param_c)
137 |<----->|
138 ```
140 In addition, 'i2,' is similar to `a,` except trailing whitespace characters (especially for first parameter)
142 ```
143 function(param_a, param_b, param_c)
144 |<---->|
145 ```
147 This plugin can be installed with:
149 Plugin 'sgur/vim-textobj-parameter'
152 ## Conclusion
154 Plugins showcased today are the great introductory plugins, as their are both
155 lightweight and provide only a handful of biding to remember while still
156 packing a good punch.
158 As you can see, all of these plugins share the same philosophy. They provide a
159 simple textobject to be used with any existing motion such as `d`, `c` or `y`.
161 After you feel comfortable with using these plugins I encourage you to check
162 out [this](https://github.com/kana/vim-textobj-user/wiki) link for even more plugins that provide similar functionality
164 If you feel particularly brave, you can try writing your own using Textobject
165 User API detailed
166 [here](https://github.com/kana/vim-textobj-user/blob/master/doc/textobj-user.txt)