11 ms·
I use (Vim IMproved - not vi) vim all the time. I find it interesting to see what features other people tend to use in vim, there seems to be some minor differe
by bArray 8y ago
I use (Vim IMproved - not vi) vim all the time. I find it interesting to see what features other people tend to use in vim, there seems to be some minor differences in their workflows, but it's not clear who "wins" the productivity battle.
I only use a very small number of it's features:
* `:tabe` Create a new tab
* `:e .` Start browsing files in that tab
* `:w` Write the file
* `:q` Quit the file (`:q!`, seriously, please do quit the file)
* CTRIL+SHIFT+UP/DOWN To switch tab (doesn't reliably work on every machine)
* `/WORD` To search for something
* `:NUM` To go to a specific line
* `i` To insert
* SHIFT+V to select lines
* `d` To delete lines
* `x` To extract lines
* `y` To "yank" (copy) lines
* `p` To paste lines
>Here are a few things I wish I could do better:
I don't have a great memory, so memorizing more than what I use every day is a little too much. One thing that I'm working on remembering is the ability to replace strings (although I don't really like regex).
>Would I learn Vim again?
I'm yet to experience anything compelling enough to stray me away. The advanced features are there if I ever need them, but for the most part I am free to have a lightweight editor.
- johnboyer 8y ago>Vim IMproved Oh, so you are using an improved version of Vi IMproved? ;)
- imiric 8y agoEmacs + evil-mode, presumably. :)
- tom_mellior 8y agoI need to use Emacs rather than vim for some things (Proof General, mostly), and I was surprised how well evil-mode works. It's only undo that I don't get. From vim I'm used to be able to undo as many editing steps as I want. In evil-mode, I find that if I type "u" too many times, it runs out of undos to do and starts undoing the undos (i.e., it starts redoing things I want to go away). Also, search uses different word separators from vim: In vim "foo_bar" is a single word that will be skipped by pressing "w". But in evil-mode the "_" is a word separator, so the above is three words. That breaks my flow every time. Some of this might not be due to vanilla evil but due to the fact that I'm using it through Spacemacs. This is my two cents. If by any chance anyone would know off the top of their head how to fix these, I'd be greatful.
- triska 8y agoFor linear undo and undo branches, undo-tree.el is required: https://www.emacswiki.org/emacs/UndoTree https://www.emacswiki.org/emacs/UndoTree Regarding "_", you can set up Emacs to treat _ as word constituent by modifying the syntax table. For example: (modify-syntax-entry ?_ "w") For more information, please see: https://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-Table-Functions.html https://www.gnu.org/software/emacs/manual/html_node/elisp/Sy...
- tom_mellior 8y agoAwesome, thanks! I'll try these.
- JdeBP 8y agoNot necessarily. It could be NeoVIM. (-:
- bArray 8y agoAha yeah, it's a recursive improvement on itself, like the GNU acronym!
- ibotty 8y agoThat's neovim, right?
- mercer 8y agoor Spacemacs
- joslin01 8y agoI'm guessing you mean "dd" and "yy" to delete/yank lines. "x" deletes a single character, what you mean extract a line? If you learn "w", which just means advance by a word, you can combine them with your existing knowledge for much better use. So "dw" becomes delete a word, or "d3w" means delete next 3 words. "v" is also useful in conjunction with "w" / "b".
- caseymarquis 8y ago'[d|c]iw', to delete/change the word your inside of is another small improvement.
- _frog 8y agoI'm also a big fan of `ci[(|'|"]` to change all the text between a pair of delimiters. I can type `ci"` while my cursor's at the start of the line, and it'll jump to the first set of double quotes, remove the text that's currently between them, and enter edit mode.
- the_white_oak 8y agoYou can also use `cib` to change text between braces and `ciB` to change text between curly braces.
- LyndsySimon 8y agoIsn't this part of vim-surround? http://github.com/tpope/vim-surround http://github.com/tpope/vim-surround
- mercer 8y agoI'm fairly sure that works out of the box. I get annoyed when another editor's VIM mode doesn't properly emulate it.
- bArray 8y agoI would either: * SHIFT+V to highlight a line, `d` to delete * `:d` to delete the current line Not experimented with `dd` (or `yy`).
- ElevenFiftyNine 8y agoThat's a solid set and will take you far. I did eventually start peppering in a few pattern matching command things that don't require much regex. * `:g` Global command, executes an Ex command on every line that matches via the pattern `:[range]g/pattern/cmd` One common use I have for using `:g` is to delete all lines that match or do not match a pattern, like when I've removed an attribute from some data structure and I want to quickly fix all my mock objects to remove the attribute: `:g/pattern/d` To delete patterns that do not match, useful for debugging: `:g!/pattern/d` * `:norm` this thing motivated me to use more of the movement commands like `A`, `o`, `D`, `f`, `cw`, and `ci`. Used `:[range]norm cmd`, it acts like each key in the command is run on every line in range. I usually use it with a selection, for example to add a comma to the end of every line in range with `A`, or insert at the end of line: `:norm A,` Or to delete everything after the first period in a range using `f` to move to character, `l` to move after that character, and `D` to delete everything after cursor: `:norm f.lD` The best part about learning these two is that they can be used together. If you want to insert `fmt.Println(err)` after every line (using `o`), but only on the lines matching `err != nil`: `:g/err != nil/norm ofmt.Println(err)` Or two write `time.Now(),` only on lines which have `"created_at":` and only after the colon: `:g/created_at/norm f:lDA time.now(),` And if you've got hashes with string keys and string values i.e. `"key": "value"`, you can upper case the string values matching `"pattern"` with: `g/pattern/norm 3f"lvi"~` On lines it matches it finds the third double quote with `3f"` then moves a character over with `l`, visual selects inside the double quote with `vi"` and uppercases the selection with `~`. One regex trick that I end up using with `:g` pattern matching is `^\s*`. When you put it before any pattern then the pattern matches only if it has some amount of whitespace preceding it, and that whitespace extends from the beginning of the line to the start of the pattern. It is good for targeting code indented with whitespace. Final thought, when you're typing your commands in norm and you've entered insert mode, you can issue the escape command with <Ctrl-v><Esc> which when done right should look like `^[` but will not actually be those characters. http://vim.wikia.com/wiki/Power_of_g http://vim.wikia.com/wiki/Power_of_g
- iovrthoughtthis 8y agoThanks for this. Been using vim for 3-4 years and I've never seen the norm command. This is next months habbit I guess!
- dingaling 8y agoMost of those are plain vi ( and ed ) commands. All of my machines have the vim-tiny package to stay as close to stock vi as possible. I open and close the editor dozens of times a day to make simple changes and I don't tolerate any lag. I can see that vim would be great for long-form programming but plain old vi was just fine for most admin tasks.
- bArray 8y agoOkay, so I've come across `vim.tiny` a few times now, what's the difference? Plain `vi` I can't seem to work out, the shortcuts I usually use all seem to be different?
- Abitingal 8y agoVim can be compiled as different versions, the bigger the version the more features it will have. I know that its described in Vims manual but I can't find it right now. Tiny versions don't include some useful features like visual mode and tabs. My guess is that vim.tiny is made to be a drop-in replacement for the old vi.
- majewsky 8y agovim-tiny differs from regular vim in how much stuff is compiled into it. Regular vim is actually quite hefty since it includes e.g. scripting bindings to Python, Perl, Lua, etc.; or support for X11 (which is useful even in a terminal for working with the X clipboard), and so on. If you have both vim and vim-tiny installed, you can use the command ":version" to compare which features have been compiled in.
- Zardoz84 8y agoUse Plug to load the plugins that you only need for a specific file. For example, this only load this plugins if I'm working wiht LESS/SCSS/CSS or Vue files : Plug 'groenewege/vim-less', { 'for': ['less']} Plug 'cakebaker/scss-syntax.vim', { 'for': ['scss'] } Plug 'othree/csscomplete.vim', { 'for': ['less', 'scss', 'css', 'vue'] }
- 8y ago
- JepZ 8y agoRegarding the replace thing: If you are used to sed it should be easy, as it is pretty much the same. I keep using this pattern over and over again: :%s/search/replace/gc The '%' is some sort of reference to the file you are currently editing and therefore you are doing a replace on the whole file. You can see the difference in combination with some visual selection. When you select some text and press ':' it opens as ":'<,'>" :% # replace in the whole file :'<,'> # replace in the current selection The 'gc' flags at the end are: g=global to replace multiple times per line c=confirm to let vim ask you about every replacement Sometimes its just easier to let vim ask you a few times than to spend 5 minutes to figure out the 100% correct regex.
- bArray 8y agoThank you for explaining this! I will have to practice, replace is something I don't do very often enough to remember but do it often enough that it annoys me each time.