[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
VIM Tips & Tricks
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 174
Thread images: 6
File: vim.png (90 KB, 1022x1024) Image search: [Google]
vim.png
90 KB, 1022x1024
Realized I've pretty much settled on what I know as it's 'adequate', but know there's a boatload more that would be good to know.

What are some not 100% basic VIM commands, scripts or what have you, that you use?
>>
remapped j and k to gk and gj
makes working with .tex less of a pain in the ass
>>
>sudo apt-get install emacs
>>
>>53324732
Why is vim so much more popular on /g/ than emacs anyway? I thought it'd be more of an even split
>>
>>53324643
/search-pattern
>n to go to next match

:%s/pattern/replacement
>>
>>53324643
also, install vim-tetris
and hit \te
>>
>>53324885
adding to this
>:%s/pattern/replacement/g

g for global, ie. not just first match but all matches

>:s/pattern/replacement/g
only replace in current line
>>
if you're in trouble press ESC then type :q!
>>
>>53324834
because emacs is dumb as fuck

vim does one thing and does it well
>>
Press . to repeat last action.
gg goto top of the file, G goto bottom of the file.
>>
Pretty basic but I took way too long until I started using these

>{
>}
moves between blocks in normal mode
>%
move to matching brace
>caB
remove everything in block including brackets and enter insert mode
>ciB
same as above but dont remove brackets

>>53324982
vim is worth using for . alone I swear down
>>
keep it going. somebodies gotta know something better than search and replace
>>
>>53324643
vimcasts.org
>>
maybe someone can help me with this.
I get really sick of scrolling across long lines with the cursor. What am i doing wrong?
I just hold shift and arrow keys
>>
>>53324834
I tried learning emacs, I really tried, but even the movement keybinds are so obscure that it's easier to just use the arrow keys.
>>
>increment number by 1
ctrl a
>decreate number by 1
ctrl x

it's situational enough but can be nice
>>
>>53325058
Use evil mode then
>>
>>53324643
Disable arrow keys and learn proper motions.

Learn mnemonics to remember motions.
For example, to change everything inside quotes it's ci"

Before you move the cursor, spend a second thinking of the quickest way to get where you want to go. Is it w or b for words, W or B for WORDs, f for forward search, ) or } or ] to move sentences/blocks, or just plain / search.

Learn auto complete. Start with ctrl-n and ctrl-p then learn the ctrl-x repeats.

Avoid using any plugins and customizations until you git gud. Personally if my vimrc gets bigger than one screen I trim it down.
>>
>>53325086
>Avoid using any plugins and customizations until you git gud
eh I disagree with this
>>
>>53325047
Try 5w
"Move 5 words forward"
You can change the 5 to any number
The opposite movement is b for back
You're probably better to forward search for a character with f. For example fg moves to the next occurrence of the letter g. Move to the next g with ; and search letters backward with F
>>
>used vim for 6 months
>zero clue what the fuck registers are and how to navigate undo tree
been on my "should look this up sometimes" list for a while, copying to clipboard is avery obscure looking command to me lel
>>
>>53325106
OK, well, many plugins and customizations. Don't copy some dudes 10kb vimrc from github cos you're just learning to use the editor the exact way he does. Unless you both do the exact same thing on the same files, you'll be fighting to learn the editor AND fighting to learn someone else's workflow. Keep it fairly vanilla for a while.
>>
>>53325119
http://vimcasts.org/categories/registers/
Watch from #51 onwards
>>
>>53325128
That I do agree with, just add things you know you actually need one at a time (often a quick google away)
>>
>>53325138
neat thanks, find reading anything in the official documentation a bit of a pain
>>
If you are coding, Ctrl-n and Ctrl-p are language aware, and will read ctags

For example, touch hello.c, vim hello.c, now do #include <stdio.h> and int main. Now type pri then Ctrl-n and vim will give you a list of functions to complete, including printf

This can also be made to work with the spelling dictionary, I think just :set spell then type half of any word and Ctrl-n to get a list of autocompletes. You might have to change :set complete from k to kspell
>>
>>53325128
https://www.reddit.com/r/linux/comments/48i2xx/tired_of_default_vim_i_made_an_great_vimrc_that/
>>
:sh opens a terminal

I only use it for editing .tex files as I want the .pdf on the other half of the screen
>>
>>53325155
> just add things you know you actually need one at a time (often a quick google away)
This is a great tip. Learn things one at a time, in increments.

Vim is almost like learning a new spoken language, you can't just get instantly fluent overnight, you need to learn little bits and iterate over them before moving onto the next thing. Eventually you build proficiency.

It took me 6 months of adding a new thing every week until I got what I'd consider "good" at vim.

This is minimum proficiency any vim user should aim for: http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/
>>
Why are vim's default color scheme so gag inducing? Like come on
>>
>>53325187
What a fucking mess. I'd say this is the worst possible way to learn the editor because it adds in a whole bunch of key mappings and changes default behaviors. So you learn how to drive vim like this, then you use ANY system besides your own and you'll hate it because everything is different. Sometimes you just need to change one quick thing, sometimes you can't easily get your vimrc onto a box.

I'd suggest starting with no arrow keys, pathogen, vim-lightline, tabwidths to your preference, and nothing else. Learn to use vim, then gradually make it your own over time. Don't start out by learning some random bloke's idea of what vim should be.

>>53325242
http://ethanschoonover.com/solarized
>>
>>53325311
Yeah I use a base-16 one, just find it odd how they have so many colorschemes by default but they are all so shit
>>
>>53325311
Posted it as a joke desu, he configured vim to a point where you wonder why he is using vim in the first place
>>
>>53325378
I totally agree. Pretty much the only remotely usable default scheme is zenburn.

>>53325413
Oh, ha, I'm dumb :) People are weird, I saw one effort to turn vim into one of those macfag editors like TextMate or Sublime. I didn't get it either.
>>
Possible to emulate how IntelliJ handles ..auto brackets? ie in IDEA pressing "{ Enter" gives (# is cursor)

private void funct(){
#
}


but in vim with delimate I get
private void funct(){
#}

indentation is off and I'd like the bracket to be one line lower
>>
>>53325444
You can tell he spent quite a bit of time with it too, eh if it works for him I guess why not
>>
Not vim per se but if you are a vim user get Vimium (chrome extension)

seriously do it now
>>
>>53325488
There is also VimFx, Vimperator, and Pentadactyl for Firefox
>>
>>53325488
>i3wm
>vim
>vimium
>zathura
>ranger
can honestly not imagine ever going to any other setup, love the across the board consistency
>>
dude lol

the 1 and only way to use vim is to remap every single command yourself, as you imagine what they are, and what you need, that way... you don't have to 'learn'. you 'decide' and 'imagine' a text editor of your dreams...

roooooooooooooookie!
>>
>>53324643
to open new file side by side type
:vsp secondfilename

while one firsfile is opened
>>
>>53325061
holy shit
>>
>>53324913
With our without the exclamation mark?
>>
>>53325618
>:q
will say "you havent saved the file yet" if you havent and its in any way edited
>:q!
exits anyway
>>
>:tabedit file
>gt, gT to go to left/right tab
>>
>>53325460
Try this maybe?
inoremap {<CR> {<CR>}<C-o>O

And as a general tip from this mapping: i_CTRL+O executes one command in normal mode, then goes immediately back into insert mode. Useful for course correcting, e.g. moving one line down in insert mode is <C-o>j.
>>
>>53326256
that should work, thanks
>>
>>53324909
adding to this

>:s/..../g
Works also in visual, and will automatically operate on the visual selection.

>>53325047
Just use f<letter> and then use ; to repeat, usually faster than going by-word for me

>>53325460
Use jiangmiao/auto-pairs, does exactly what you're looking for

>>53325981
:tabe
>>
You know how you might want to delete everything between two brackets or parenthesis in a function? Go to where the bracket begins and in escape mode click ci{ to delete everything between two brackets. I was fucking stoked when I found this out, saves you a lot of time from just holding down the delete key
>>
>>53326885
Or you could just use a mouse like a normal person
>>
>>53326802
>o
looking that up too thanks
>>53326802
lel I actually :tabe <tab>, guess the tab isnt neccessary
>>
>>53324885
shift + n to go to the previous match
>>
Some of my lesser-known ones (I guess I don't know a lot of other vim users)

>*
jumps to next occurrence of word under cursor

>:%s//<new word>/g
Replaces last search register, combined with * that means all occurrences of highlighted word (just try it) and you don't have to type the actual thing

>:%s/man\zsbear\zepig/dog
Replaces 'manbearpig' with 'mandogpig': zs and ze delimit the start and end of the captured pattern.
Really comfy to replace all occurrences 'function foo(int)' by function foo(float)'
>>
>>53325061
> Holy shit, thank you
>>
>>53326899
having the mouse enabled...
>>
Always use :x instead of :wq because that only changes the file modified time if there were actual modifications to the file. Also ergonomics.
>>
swap esc and capslock to make things much easier.

use vim-surround plugin.
>>
>>53327078
actually, map capslock to control
>>
>>53327013
>*
this is invaluable, the reverse (jumping backwards)
>#

and here is fucking magic if you don't know it

>gd
go to definition of word under cursor, works for variables, functions, whatever
>>
>>53327038
Go back to the 1970s, fag.
>>
>>53327038
i use the nipple every now and then in vim, why not
>>
You can jump to your previous change via g; and forward from there via g,

I have these mapped to <left> and <right>
g;            Go to [count] older position in change list.
If [count] is larger than the number of older change
positions go to the oldest change.
If there is no older change an error message is given.
(not a motion command)
{not in Vi}
{not available without the |+jumplist| feature}

*g,* *E663*
g, Go to [count] newer cursor position in change list.
Just like |g;| but in the opposite direction.
(not a motion command)
{not in Vi}
{not available without the |+jumplist| feature}
>>
>>53324643
i would love a less manual way of doing this


# poop
# poop
# poop
# poop



Suppose we want to remove the # comment on poop (without using Replace), I would usually do a Control + v and highlight the first char and scrolling all the way to the last. Then I press Shift + i, delete the # and press esc. This removes all of the comments.

Its too retarded because I have to keep scrolling if the block of code is big. Is there a smarter way?
>>
>>53327586
sed
>>
I mainly use gvim. How do I set the size of each tab to a specific number of characters?

I would prefer to not use a plugin if possible. This link gives two solutions:
https://stackoverflow.com/questions/488462/vi-vim-how-to-set-the-tab-label-title-length-to-a-fixed-size-in-chars

I changed my .vimrc based on the first solution given:
if has("gui_running")
set guifont=DejaVu\ Sans\ Mono\ 10
set guioptions-=T "remove toolbar
set guioptions-=r "remove right-hand scroll bar
set guioptions-=l "remove left-hand scroll bar
set guioptions-=R "no scroll bar with split
set guioptions-=L "no scroll bar with split
set guitablabel=%-0.12t%M "12 characters max tab labels
set guioptions=e "from documentation for guitablabel
endif


All of the tabs are the same size until I edit something. Then the edited tabs have different sizes. I saw that the *answer* in the like used a plugin. I hope I don't need to use that, I would like to keep it simple if possible.
>>
>>53327586
im sure there's a cleaner way but i select and jump to end of block with }
>>
>>53324926
>vim does one thing and does it well
this is what vimfags actually believe
>>
>>53327621
also just delete with x or d, no need to enter insert mode
>>
>>53327618
set tabstop=2
set softtabstop=2
set shiftwidth=2
>>
>>53327111
Why not both?
>>
File: vim.png (19 KB, 644x468) Image search: [Google]
vim.png
19 KB, 644x468
>>53327696
If I set those options they will overwrite my current ones I believe.

" Basic
set nocompatible " use vim defaults (No vi stuff)
syntax on " turn on syntax highlighting

" General
filetype plugin indent on " load filetype plugins/indent settings
set autochdir " always switch to the current file directory
set backspace=indent,eol,start " make backspace a more flexible
set backup " make backup files
set backupdir=~/.vim/backup " where to put backup files
set directory=~/.vim/tmp " directory to place swap files in

" Vim UI
set hlsearch " highlight searches
set incsearch " do incremental searching
set number " show line numbers
set ruler " show the current row and column
set scrolloff=3 " keep 3 lines when scrolling
set showcmd " display incomplete commands
set showmode " display current mode
set columns=80 " number of columns used

" Text Formatting/Layout
set expandtab " use spaces, not tabs
set shiftwidth=4 " how many columns to shift text(>>,<<)
set nowrap " don't wrap lines
set tabstop=4 " tab is 4 spaces

" load color scheme
colorscheme blackocean " use a color scheme

if has("gui_running")
set guifont=DejaVu\ Sans\ Mono\ 10
set guioptions-=T "remove toolbar
set guioptions-=r "remove right-hand scroll bar
set guioptions-=l "remove left-hand scroll bar
set guioptions-=R "no scroll bar with split
set guioptions-=L "no scroll bar with split
set guitablabel=%-0.12t%M "12 characters max tab labels
endif


Also looking a little closer at my issue, the max tab size is working when the title of the tab is long enough. What bothers me is when the name of the tab is too short. Then I get different sizes. See pic.

I would like all the tabs to be the same size, if possible.
>>
I'm trying to have gvim use a different colorscheme than vim, but this isn't working:
if has('gui_running')
colorscheme base16-ocean
else
colorscheme apprentice
endif

gvim just has the default colors, but I can run
colorscheme base16-ocean
manually and get the desired colorscheme.
What do?
>>
>>53327750
that should work
>>
>>53327746
Oh, you mean tab as in browser-tab. You should use buffers in Vim instead.
>>
>>53327773
But it doesn't. I just tried creating .gvimrc with just
colorscheme base16-ocean
and it worked, but I don't want to have two separate vim configs to keep track of.
>>
>>53327866
if has('gui_running')
set guifont=Source\ Code\ Pro\ 12
colorscheme base16-ocean
else
colorscheme onedark
endif

thats mine which does work, sure you dont have a type somewhere?
>>
>>53327895
or that your .vimrc is actually loading?
>>
>>53327895
Something weird is going on.
If I put the colorscheme line first, then none of the other lines of this statement execute. If I put it last, it just doesn't work as usual.
Literally what the fuck.
if has("gui_running")
colorscheme base16-ocean
set guifont=Terminus\ 12
set go+=c
set go-=m
set go-=T
set go-=r
endif
>>
>>53327951
if you dont put it at all does the rest execute ok? if so i have no fucking clue what the problem would be
>>
>>53327971
>if you dont put it at all does the rest execute ok?
That's what I meant. It somehow just breaks out of the if block and continues reading the rest of the config perfectly.

All this shit just points to one thing: time to wipe the .vim and start from scratch.
>>
>>53328000
right, figured one of the "set blabla" could have been fucking with things but if it works fine with no colorscheme set then.. yep, thats weird
>>
>>53327013
Didn't know that last bit, thanks!
>>
>>53324732
>not pacman

YOU ARE USING THE WRONG DISTRO
>>
>>53328122
>does everything i want it to do
pretty content desu
>>
>>53327586
There are a lot of plugins for easier handling of comments out there. I use Commentary personally. In your example, I could simply do gcu or gcip. If I'm on the top row, gc} and 4gcc would also have the intended effect.
>>
>>53324643
HOW THE FUCK DO YOU EXIT VIM?
>>
>>53328178
<esc>:qa!
should cover all bases.
>>
>>53328178
if this is an issue you wont have any use of vim before you read some tutorials anyway, so start there
>>
>>53325085
i don't get this answer, if you're gonna use evil mode, why not just use vim while you're at it?
>>
>>53328178
like you kill any program
sudo kill $(ps aux | grep vim | egrep -o "[1-9]{4}" 
>>
>>53328230
i just sudo reboot, just in case kill misses something
>>
Ctrl-Z is your friend.
>>
>>53328230
What if the PID is five digits, Anon?
>>
>>53324834
Because Emacs is a bitch to properly learn and there are so many more resources available for vim
>>
>>53328392
always thought it wasnt harder/easier than vim, just different, never did try it though
>>
For those who aren't on an ANSI US layout, and especially those who have extra letter keys and such, remember to map your unused keys to useful things that are otherwise bothersome to get at.

A couple of examples without much thought behind them could be for Germans and Nordics to map öä to {} and å/ü to $.
>>
>>53329461
>mind blown
remapping ^ to å right the fuck now, been using 0w
>>
>>53328392
there is by far more resources for emacs than vim.

vim is a great editor for quick config file edits and system administration. But when it comes to real software development, GNU Emacs 24 is superior in every regard.
>>
>>53329514
>lots of modifiers
nope.jpg
>>
Vim is great, but only if you don't try to use it like Emacs. By that I mean you should use Vim as an editor rather than an IDE. Vim is fine as part of a development environment, but only if you see it as a tool along with your shell and utilities as an IDE. Things like Vim plugins are a disgusting mess. You should avoid using Vim script for anything other than configuration.

If you want an all-in-one IDE with a bunch of fancy plugins, just use Emacs. Spacemacs, which is Emacs with evil-mode and helm and a tonne of other stuff, is awesome and it just werks. There's nothing special to learn if you use Vim, except there's so much nice stuff you can do just by pressing space. And configuration / installing plugins is all done nicely with Emacs LISP instead of some hideous mess of Vim script.

>>53324688
>having massive long lines instead of neatly wrapping to 80 columns with gq
>>
>>53324643
:help!
>don't forget the exclamation mark
>>
>>53329708
>having editor full screen
>>
>>53329780
When did I say anything about having an editor fullscreen?
>>
>>53329825
you didnt, long lines just isnt an issue for me with the window size i use
>>
>>53329850
When writing plain text, it's best practice to keep everything wrapped onto separate lines normally under 80 columns. This makes the text more comfortable to read, and it will avoid winding people up, when you're that one guy who sends emails all in massive long lines, or has big long-lined commit messages. You should actually put hard wraps in your file instead of relying on whatever's displaying it to wrap it like that, since that provides consistency and allows you to indent and quote blocks of text. Also, many Unix tools are designed to work best with lists of lines, rather than big long lines. It also makes it easier to put your text under version control.
>>
>>53329993
I see your point. The only text editing I ever do is editing .tex files though and here hard wrapping is really irrelevant.
>>
>>53330121
TeX is one of the cases where it's best practice to use hard wrapping, and you'll see others tend to do that. Lots of tools, including your editor, are designed to work with blocks of text being multiple lines.

In Vim, you can press gq5j to wrap a bunch of lines below the cursor, or shift+v and select a bunch of lines and gq, and it will wrap them. You can also `:set wrap` (actually I think it's something else) to make it auto wrap when writing long lines.

https://raw.githubusercontent.com/sarabander/sicp-pdf/master/src/sicp.texi
>>
>>53327586
https://github.com/scrooloose/nerdcommenter
>>
>>53330215
>TeX is one of the cases where it's best practice to use hard wrapping
Why do you think this is the case and that my "window width wrap" with gj/gk is insufficient here?
>>
>>53330240
Sure that will work, and if that's easiest for you, do that, but Vim is designed to work with files made of many lines. That's why j and k don't work as you'd expect when you squeeze everything into one line. It also makes visual line and visual block not work very well, and it means you can't indent paragraphs. It also means lines can't be used as a reference for things, since the whole paragraph is one line. It means you can't easily jump up to a line using relative line numbers or just line numbers, and it means output from your compiler won't link nicely to where in the source it's referring. Using things like grep or ag aren't very useful when everything's in one line, and if you're keeping track of your files with git, commits are much more destructive and harder to merge.
>>
>Hit Ctrl-V for visual block mode.
>Press I, type something than ESC.
>that something gets inserted before the selected block in all lines, works similarly with c and A too..
>di) to delete everything in the closest encloseing (), i stands for inside.
>da) to delete everyting in the closes encloseing () including the (), the a stands for all.
>use f, F, t, T and ; to move around fast inside a line by searching for a single character, also works with commands that require a range like d and c.
Also, try remapping capslock to escape it´s a lot more comfortable that way.
>>
>>53330392
Not changing my .tex ways yet but if I do end up working with other text editing or git merging (I know the latter is coming soon) I'll definitely get the wrapping set up right.

Thanks for taking your time to explain.
>>
>>53324643
>100% basic VIM commands
I like the ‘j’ command. Sometimes also the ‘k’ command.

You should try them out sometime, they're p. neat
>>
>>53330215
>or shift+v and select a bunch of lines and gq
Holy shit why has nobody told me about this sooner?

Gone are the days in which I need to manually re-align my text to 80col to satisfy my autism
>>
>>53324643
set foldmethod=syntax
set foldnestmax=1
set foldlevel=0


Use za to fold/unfold something under the cursor. Use zr and zm to fold the entire file.

Hope this helps somebody become more productive!
>>
yy yanks a line
2yy yanks two lines
>>
File: 1440551032314.png (656 KB, 3508x4960) Image search: [Google]
1440551032314.png
656 KB, 3508x4960
>>
File: 1448427662176.png (591 KB, 3508x4960) Image search: [Google]
1448427662176.png
591 KB, 3508x4960
>>
>>53325183
>Ctrl+n
holy shit this just blew my mind.

Also blowing my mind: I can just type gD to go to the definition of something, as long as it's in the same file.

I don't know how to make vim smart enough to scan the entire project, though.

For ctrl+n, do you know if it's somehow possible to display the signature for the function I'm currently ‘inside’? e.g. say I start with mmap(, have the cursor after the ( and want to view the signature.
>>
>>53330634
>gD
That's amazing, thanks
>>
>>53329461
If you're anything like me, you can swap your symbols with your numbers

i.e. without shift I get !@#$%^&*[]-= and with shift I get 1234567890_+

I also have () accessible without modifiers, and {} is that + shift.

Instant coding productivity gain
>>
I just had an idea

https://github.com/hobbestigrou/vimtips-fortune/blob/master/fortunes/vimtips

Install this and include `fortune vimtips` in your .zshrc
>>
>>53330634
Generate ctags (run 'ctags' in the root of the project)
Hit ctrl-[ on anything to go to its definition, even if the def is in another file.
Hit ctrl-o to go back "out" to where you were, and hit ctrl-i to go back "in" to the definition.

I should have mentioned but if you have ctags, the ctrl-n and ctrl-p autocomplete will also read your definitions from the ctags.

You need to have the cursor on the thing to go to its definition. If you're in the brackets of an mmap() then hit ESC to exit insert mode, B (capital b) to go Back to the start of the WORD, then ctrl-n[ to jump to the def of mmap.

If you use C, you might want to look into using GNU Global and the vim-cscope plugin. I work on the kernel in my day job and this is better for working with a large C project.
>>
>>53331412
>Generate ctags (run 'ctags' in the root of the project)
But I don't want to manually run `ctags` every time I change my code. Isn't that a bit stupid? Can't vim be smart enough to scan the files on its own?

Also, ctags in the root of my project just gives me ‘ctags: No files specified’.
>>
>>53331434
Yea, there are plugins to generate tags automatically on save, or you can map :!ctags to a leader shortcut.

Sorry, ctags -R to be recursive.
>>
>replace 0 and $ with H and L
>map tab and shift tab to :bnext and :bprev
>>
>>53331612
>remapping H
but why
>>
>>53331795
and L*
>>
>>53330587
>>53330601
10/10
/thread
thx
>>
>>53324732
>not yum install emacs
>>
>>53331934
>not pacman -S emacs
>>
>>53331934
>>53331995
> not tar xf emacs*; cd emacs*; ./configure; make; sudo make install;
>>
:e.
to open vim's native file browser at your current dir

Works with any path too:
:e path
>>
>>53332121
i almost asked "wait how the fuck else are people opening files"
>>
>>53332137
From an external browser or a dumb sidebar. Surprisingly few seem to be aware of netrw
>>
Curious, do you people use nerdtree or something similar?
>>
>>53332339
I have it installed but I always forget about it. I'm usually jumping around source files with vim-cscope which is quicker, or I use :e and tab completion to open a file I already know exists.
>>
>>53327586
Looks like you need this:
https://github.com/mawww/kakoune
>>
>>53324643
There is a vim wiki. Use it faggot.
>>
>>53324926
>vim does one thing and does it well
>Vimscript
>>
>>53328225
Because the UI of a customizable editor isn't the important part.
>>
>mx
mark position with x
>'x
go to mark x
>>
>>53328178
like any other program.
ctrl+x,ctrl+z.
Or esc,:,q,!,enter
>>
>>53324834
because /g/ is full of casuals
>>
:set relativenumber

single biggest help to me, makes navigating a breeze
>>
>>53333258
>bug in line 124
how do you get around this?
>>
>>53333273
I always do that by typing :124 to go to line 124.
>>
>>53332752
>qx
start recording macro x
>do a bunch of stuff
>q
stop recording macro x

>@x
replay macro x

>100@x
replay macro x 100 times
>>
>>53333302
ah, I thought the relative line numbering would be applied to everything
huh, may even try it out now
>>
>>53333258
set relativenumber number
Makes it a tad nicer.
>>
>>53333326
I found it distracting as fuck and I don't use relative jumps ever either way

YMMV
>>
>>53333344
figured as much, something I can't predict if I'll like or dislike without giving it a go, just haven't bothered to try it yet
>>
>>53325018
ciw for this effect applied to single words

I have CTRL-D mapped to ciw.
>>
>>53333311
I know of this and can't figure out why I never use it
>>
>>53327586
Use macros. For example.
q 1
0
x
q
<number of comments you want to remove> @ 1
>>
>>53333839
Actually forgot a j in there, but you get the idea.
>>
>>53333331
>>53333258

just make a little function or search a plugin to toggle it if you like.
>>
>>53330634
> gD

Fuck this is cool

Also I started using this to make taking notes easier. Goes into insert mode and makes a bullet point on a new line. Mapped to leader b
nmap <leader>b o<C-k>Sb
>>
File: vim.png (46 KB, 1022x2126) Image search: [Google]
vim.png
46 KB, 1022x2126
RICING TO THE LIMIT
>>
>>53334058
Way ahead of you. <Leader>n toggles relativenumber and <Leader>m toggles both in my setup. Leader is bound to comma.

I sure hope no plugin exists for something as simple as that.
>>
>>53325018
>caB
>ciB
Is there an equivalent for parentheses?
>>
>>53324885
Wow. Did you know that you cal also move around with either the arrow keys or h, j, k and l?
>>
>>53335162
b
>>
>>53335162
cab
cib
>>
>>53335162
ci( ci[ etc. all work just fine
>>
>>53335231
>>53335239
>>53335243
Thanks!
>>
>>53334847
vims default fold function is pretty ugly
i wrote one so it aligns it and line count at the end.
>>
gg=G

reindent the whole file. handy sometimes
>>
>>53335717
>i wrote one so it aligns it and line count at the end.
Do you mean the columns at the left? If so, I would appreciate that.
>>
>>53335868
like this.

        set listchars=tab:│\ 
function Myfoldtext()
let l:tab = '│' . repeat(' ', &tabstop-1)
let l:beg = substitute(getline(v:foldstart), '\t', l:tab, 'g')
let l:mid = substitute(l:beg, '.*{', '','') "}
let l:end = substitute(getline(v:foldend), '^\s\+', '', '')
if l:mid == ''
let l:mid = '...'
else
let l:mid = ' '
endif
return printf("%s%s%s [%d Lines] ", l:beg, l:mid, l:end,
\ v:foldend - v:foldstart)
endfunction
set foldtext=Myfoldtext()
highlight Folded ctermfg=red ctermbg=NONE
>>
>>53335939
I don't get those │ tab indicators on my end, anon.
>>
>>53336237
thats what the listchars setting does.
>>
>>53336349
Doesn't seem to be working on my end.

It's not a big deal, I like my fold settings the way they are - with the exception of the fold column at the left getting on my nerves. (I want the fold column to be to the right of the line numbers, not the other way around)
>>
>>53336468
ahh thats what you meant. i misread.
i dont know how to do that, i dont really use it.
Thread replies: 174
Thread images: 6

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.