Vim After 11 Years
statico.github.com
statico.github.com
I used to have , remapped to <leader> but switched back when I realised what I was missing out on. I'd advise anybody else to reconsider if they've made the same mistake I did.
Is there a use for `;` I'm missing out on? `;` just seems to be for stuff like "`fp` -- Oh wait, I didn't see all the p's between my cursor and the p I wanted. ; ; ; ;."
Now I use easymotion.vim which obviates that scenario.
For example if I have a longer line I would like I could do something like f,a<cr><esc>k,.k,.k,.k,.k,.k,.
"Apps, extensions, and user scripts cannot be added from this website"
nmap <CR> :write<CR>
cabbrev w nope
Re-map enter to save the file. If you try to do a :w it will yell at you until you take out the cabbrev so you can retrain your muscle memory. Took me about a day to retrain.
let g:EasyMotion_leader_key = ';'
nmap s ;w
nmap S ;b
Remap s and S to be easymotion forward and backward. I never use s, since it's largely a redundant command, and didn't like having to do a two key command for easymotion. (You can set the leader key to whatever here, the nmap's are the important part.)
noremap <C-H> <C-W>h
noremap <C-L> <C-W>l
noremap <C-J> <C-W>j
noremap <C-K> <C-W>k
Move between panes with motion keys with control held down.
Also the YouCompleteMe plugin got some HN airtime but it really needs to get more. It's amazing.
http://valloric.github.com/YouCompleteMe/
And as others have mentioned using vim inside of tmux is very nice. It's especially helpful to remap the entire tmux keymap to be vim-like.
Also, does anyone have any suggestions for what to re-map Space to? I am amazed Enter and Space in command mode both do relatively useless things. Remapping space to page down is OK but I use ctrl-f/b which is just as fast imho.
noremap <Space> @q
This lets me set a macro by first wacking qq, then q to finish, and then replay it by wacking space. I find myself using quick throw-away macros that only have a use for maybe 10 seconds far more often with this setup. (Plus wailing on the spacebar to get work done can be really satisfying ;) " space toggles the fold state under the cursor.
nnoremap <silent><space> :exe 'normal! za'.(foldlevel('.')?'':'l')<cr>
" <leader>space expands with zO
map <leader><space> zO nnoremap <Space> za
vnoremap <Space> za
also, for folding in general I'd recommend using set foldmethod=marker
which has the benefit of making folds more 'transparent' in your code, and also persistent across vim sessionsI used to use space as my "clear all searches and clear the echo-line" command, but decided space is too big and easymotion is too good to not pair them. I now use <leader><leader> to do the all-clear command.
EDIT: disregard me, it was a stupid configuration error (both plugins mapped the same key for completion, and foreplay won)
[0] http://ivanvillareal.com/osx/setup-iterm2-to-behave-like-gua...
iTerm2 can intelligently communicate with tmux in order to present splits and windows are handled by iTerm2, rather than within the single terminal window.
- scrolling with a mouse wheel
- selecting/resizing a split window
- jumping to a specific place in the code
- making a selection
- scrolling with a mouse wheel
:h scroll.txt
- selecting/resizing a split window :h window-resize
:h window-move-cursor
- jumping to a specific place in the code /foo<CR>
or the myriad of cool things in :h motion.txt
- making a selection v{motion}Surely we don't need to get into this sort of thing here.
If you don't know how to do it without the mouse, then it's more efficient to do it with the mouse. If you don't remember how to do it without the mouse, then it's more efficient to do it with the mouse. If you just like using the mouse better, then ….
Anyway, and perhaps more importantly, it doesn't hurt any of us if anyone else values ease of use (even if it's illusory or temporary!) over efficiency.
di{ is obviously both quicker and more precise than reaching to the mouse, pointing at the beginning of the code block, extending the selection until the end of the code block and hitting backspace.
One may think these keybindings are awkward or hard to remember (I did, at first, they are not) but they are both faster, more efficient and more deterministic by nature. But I may be a control freak. :-)
You can of course make nicer mappings, but even then it isn't as nice.
10<C-w>
But I tend to keep windows at equal width anyway.I also resize often, particularly when using vimdiff, because I often use smaller screens (either because I am watching other things in tmux panes at the same time, or because I am working on my eeepc).
"narrower window
map - <C-W><
"wider window
map + <C-W>>
"shorter window
map _ <C-W>-
"taller window
map = <C-W>+No. All this can be made with an extra cognitive overload provided by the use of keyboard shortcuts that makes you think you're doing something useful and/or faster than with the mouse.
Especially if you don't need to have your hand at the keyboard at all times (i.e you're just browsing code and not writing), scrolling with the mouse is way faster.
By the way, you totally missed the "me" in
> Keyboard shortcuts give me precision and efficiency, not speed, and that cognitive overload you talk about is a small price to pay.
which quite clearly means that this is a subjective matter.
Thanks for helping policing the internet: we clearly don't need to debate about anything.
Vim is just one of the many things you can run in a terminal, and just one of the many things you can do with a terminal.
And I know that I never use mouse in one or the other. I don't use it for scrolling, I don't use it for pointing and clicking, I don't use for selecting stuff…
REPL? no use for the mouse. htop? no use for the mouse. git/svn/hg? no use for the mouse.
I never select or copy anything from the terminal: pbcopy on the Mac OS X and xclip on Linux are what I use to get stuff from the shell into the system clipboard.
I don't think that's what you ask, but in Vim, visual selection is done by hitting v (character-wise), V (line-wise) and Ctrl-v (block-wise) followed by a motion or a text-object: va{, vit and so on.
Good mouse support in a terminal is also nice for elinks, which several of my vim shortcuts trigger (company wide code/wiki searches, or similar).
People that take keyboard only to the extreme strike me as adhering to the letter of the law rather than the intent. Whichever works faster for a person is better.
# See http://www.reddit.com/r/commandline/comments/kbeoe/you_can_make_readline_and_bash_much_more_user/
"\eOd": backward-word
"\e[5D": backward-word # for OS X
"\eOc": forward-word
"\e[5C": forward-word # for OS X
"\C-f": reverse-search-history
"\C-F": reverse-search-history # for OS X
#Control-F: reverse-search-history
#Control-j: menu-complete
#Control-k: menu-complete-backward
set bell-style none
set completion-ignore-case on
set completion-prefix-display-length 2
set show-all-if-ambiguous on
set show-all-if-unmodified on- easier to change the default darkblue to be readable on black - can configure double-click on filename behaviour (cmd+alt click in Terminal) - can have auto-copy-to-clipboard on selection
In short, it's more like terminal applications on other OSes I'm familiar with.
if !isdirectory(expand(root, 1).'/vundle')
exec '!git clone '.src.' '.shellescape(root, 1).'/vundle'
endifMy approach also works even if git doesn't exist (by skipping vundler).
I need this since sometimes I work on systems that don't have every bell-and-whistle I could want.
https://github.com/docwhat/homedir-vim/blob/master/vimrc/.vi...
Just kidding, tmux for life.
With tmux I'd need to create a new pane, navigate to the same directory, and reinitialize any environment stuff like virtualenv.
Use both! :)
http://www.vim.org/scripts/script.php?script_id=2937
> The biggest hole, however, is the lack of refactoring and smart completion.
This one doesn't need gVim, with rgb() and rgba() support https://github.com/ap/vim-css-color
I still use tmux or screen to do other things which aren't convenient or elegant to do within vim, but splitting windows and creating tabs can be done just fine within vim itself (or, in my case, within gvim, which I prefer due to the increased color gamut and keybinding abilities over terminal vim).
# ~/bin/ss-ctrl
#!/bin/sh
env_name=ctrl
long_name=skillspy
short_name=ss
cd ~/src/${long_name}/site && \
tmux new-session -d -s ${short_name}-${env_name} && \
tmux rename-window -t ${short_name}-${env_name}:1 git && \
tmux new-window -t ${short_name}-${env_name}:2 -n log 'RAILS_ENV=development rails s -p 3009; bash -i' && \
tmux new-window -t ${short_name}-${env_name}:3 -n db 'ssdb; bash -i ' && \
tmux new-window -t ${short_name}-${env_name}:4 -n misc && \
tmux new-window -t ${short_name}-${env_name}:5 -n redis 'cd ~/src/redis-2.6.0-rc8/src && ./redis-server && date && bash -i' && \
tmux new-window -t ${short_name}-${env_name}:6 -n sidekiq 'RAILS_ENV=development bundle exec sidekiq | tee log/sidekiq.log; date; bash -i' && \
tmux select-window -t ${short_name}-${env_name}:1 && \
tmux -2 attach-session -t ${short_name}-${env_name}
# ~/bin/ss-code
#!/bin/sh
env_name=code
long_name=skillspy
short_name=ss
cd ~/src/${long_name}/site/app/models && \
tmux new-session -d -s ${short_name}-${env_name} && \
tmux rename-window -t ${short_name}-${env_name}:1 models
cd ~/src/${long_name}/site/app/controllers && \
tmux new-window -t ${short_name}-${env_name}:2 -n controllers
cd ~/src/${long_name}/site/app/views && \
tmux new-window -t ${short_name}-${env_name}:3 -n views
cd ~/src/${long_name}/site/app/assets/stylesheets && \
tmux new-window -t ${short_name}-${env_name}:4 -n css
cd ~/src/${long_name}/site/app/assets/javascripts && \
tmux new-window -t ${short_name}-${env_name}:5 -n js
cd ~/src/${long_name}/site/app/workers && \
tmux new-window -t ${short_name}-${env_name}:6 -n workers
tmux select-window -t ${short_name}-${env_name}:1 && \
tmux -2 attach-session -t ${short_name}-${env_name}I use two tmux windows, one of each of my screens. One is code and the other runs `make && ./test blah blah` whenever I hit F5 in vim. To get vimux to use windows (as opposed to just panes) there's a fork under pull requests (disclaimer: I wrote it).
If you haven't tried multiple panes with multiple font sizes — e.g., smaller font for logs/compiling/long-running, bigger for editing — then that's a world I don't want to live in. (j/k ;)
In the end, though, I went back to Command-T.
let g:ctrlp_user_command = {
\ 'types': {
\ 1: ['.git/', 'cd %s && git ls-files'],
\ 2: ['.hg/', 'hg --cwd %s locate -I .'],
\ },
\ 'fallback': 'find %s -type f'
\ }let g:ctrlp_user_command = 'ag --nogroup --nobreak --noheading --nocolor -g "" %s '
I find CtrlP breaks down with large projects such as the Linux kernel. While it's fast to find the initial list of files (2 seconds or so) it's extremely slow to actually search through said list, about .5-sec per keystroke.
[0] I'm not a maintainer, I just happen to be using its wonderful instrumentation hooks in a research project.
[1] It's about half a second on my laptop, which has an SSD. This time is dramatically larger if you have a rotary drive, more like 10-20 seconds IIRC.
let g:ctrlp_clear_cache_on_exit=0
Is there any reason to do this instead of !sh within Vim to drop into a shell?
The other issue I have in general with the ! form is that some applications mess up osx vim. For example, try dropping into a node session (!node) and then quitting.
bind '"\C-z":"fg\n"'
bind -x '"\C-z":"fg"'
echo 'Control-z: "fg\n"' >> ~/.inputrc
If I replace "z" with "a", it works.C-z works otherwise, e.g. C-v C-z prints ^Z in shell, and C-z suspends programs (e.g. vim). Is it a bash thing or a terminal thing (I'm using iTerm2)?
set bind-tty-special-chars Off
in your .inputrc, before you do the bind on C-z.The readline man page is a little misleading:
bind-tty-special-chars (On)
If set to On, readline attempts to bind the control characters treated
specially by the kernel's terminal driver to their readline equivalents.
Disabling it doesn't actually stop readline from binding those control characters. It just enables you to override those default readline binds. If the variable is set to On (the default), that's not possible.Also, another thing I have noticed, is that I cannot catch the SIGTSTP (Control-Z) signal with the `trap` command. I can catch other standard signals, e.g. SIGINT (Control-C), but not SIGTSTP (along with SIGSTOP and SIGKILL, obviously).
Ctrl+z suspends Vim so that you are back to where you were when you started Vim.
:sh starts a new shell in Vim's current directory.
Both options have their use.
I recommended ^Z/fg/bg because it's the fastest, easiest way to get to a good, functional shell if you're not using a multiplexer (tmux/iTerm2). If you map ^Z in your shell to "fg\n" then switching is lightning fast.
All apps I have used since learning Vim has some kind of Vim bindings - Visual Studio, Eclipse, PyCharm and ST2. I also rely on browser vim plugins (vimium, vimperator).
It seems Vim mode is becoming ubiquitous in my apps.
I'm editing some project with 10000 C++ files.
There is some C++ file I currently don't have open, say "palette.cpp" which is in a subdirectory "project/graphics/algorithms/color/".
Now I want to open palette.cpp without ever having to type, not even with tab autocompletion, that path.
IntelliJ (which I do use for C++ ;)) can do this easily: just press CTRL+R, then palette.cpp, ENTER, and there you are in that file.
Another thing: Some IDE's and editors have this feature where if you change lines, it marks it with some color on the left, as well as colors in the scrollbar, to immediately see which parts of the file were changed compared to git and/or the last time you opened it. Can Vim do this?
Thanks!
^o and ^i get used a lot in conjunction with 'gf', and are also pretty handy in general.
Not sure if this helps but FuzzyFinder: http://www.vim.org/scripts/script.php?script_id=1984
:e **/palette.cpp<CR>
2. You can try http://www.vim.org/scripts/script.php?script_id=3052 but I'm positive there are other implementations.This is the feature that I miss the most in Vim, after working 5+ years in IDEs like Visual Studio. There are some Vim plugins addressing this (at least a year or so ago, when I searched), but nothing as elegant and seamless as in IDEs.
If I may ask, how do you use it? The C/C++ plugin was unusable, last time I tried it.
But I just made a manual set of syntax highlighting rules for C++, and that's good enough for me.
The git integration and other IntelliJ features make up for the missing C++ navigation and refactoring features for me.
I do everything related to compiling, debugging, and stuff (as well as all git committing and stuff, the IntelliJ git integration is about showing changed lines) from a terminal.
This does that: https://github.com/airblade/vim-gitgutter
I don't recall where I saw this, but someone advised disabling syntax coloring in your editor to remove a crutch (and, secondarily, to visually simplify your environment). I've tried this with Vim and it's surprisingly nice [0]. You have to read the code more closely, and think more carefully about what's on screen, and this has the effect of focussing me more. Simplifying my environment, making it more sparse, but always having the power of Vim available, makes for a really potent, semi-distraction-free environment.
[0] Well, mostly. I leave it on in order to have three colors used: a good contrast color for code, a second contrast color for strings, and a third, very low-contrast color for comments and line numbers so that, if I want to see those things, I can look for/at them, but if I don't, they're easy to ignore. Likewise, visually distinguishing between strings and code continues to be really useful.
You can turn off colors. That's your customization because you like it. Good. Other people want other customizations.
In short, according to the OP, if you want that level whiz-bang, you should switch from Eclipse (and presumably Coda or Sublime Text 2) to Vim.
Perhaps you might enjoy using ed...
From: patl@athena.mit.edu (Patrick J. LoPresti)
Sender: news@athena.mit.edu (News system)
Subject: The True Path (long)
Date: 11 Jul 91 03:17:31 GMT
Newsgroups: alt.religion.emacs,alt.slack
When I log into my Xenix system with my 110 baud teletype, both vi
*and* Emacs are just too damn slow. They print useless messages like,
'C-h for help' and '"foo" File is read only'. So I use the editor
that doesn't waste my VALUABLE time.
Ed, man! !man ed
ED(1) UNIX Programmer's Manual ED(1)
NAME
ed - text editor
SYNOPSIS
ed [ - ] [ -x ] [ name ]
DESCRIPTION
Ed is the standard text editor.
---
Computer Scientists love ed, not just because it comes first
alphabetically, but because it's the standard. Everyone else loves ed
because it's ED!
"Ed is the standard text editor."
And ed doesn't waste space on my Timex Sinclair. Just look:
-rwxr-xr-x 1 root 24 Oct 29 1929 /bin/ed
-rwxr-xr-t 4 root 1310720 Jan 1 1970 /usr/ucb/vi
-rwxr-xr-x 1 root 5.89824e37 Oct 22 1990 /usr/bin/emacs
Of course, on the system *I* administrate, vi is symlinked to ed.
Emacs has been replaced by a shell script which 1) Generates a syslog
message at level LOG_EMERG; 2) reduces the user's disk quota by 100K;
and 3) RUNS ED!!!!!!
"Ed is the standard text editor."
Let's look at a typical novice's session with the mighty ed:
golem> ed
?
help
?
?
?
quit
?
exit
?
bye
?
hello?
?
eat flaming death
?
^C
?
^C
?
^D
?
---
Note the consistent user interface and error reportage. Ed is
generous enough to flag errors, yet prudent enough not to overwhelm
the novice with verbosity.
"Ed is the standard text editor."
Ed, the greatest WYGIWYG editor of all.
ED IS THE TRUE PATH TO NIRVANA! ED HAS BEEN THE CHOICE OF EDUCATED
AND IGNORANT ALIKE FOR CENTURIES! ED WILL NOT CORRUPT YOUR PRECIOUS
BODILY FLUIDS!! ED IS THE STANDARD TEXT EDITOR! ED MAKES THE SUN
SHINE AND THE BIRDS SING AND THE GRASS GREEN!!
When I use an editor, I don't want eight extra KILOBYTES of worthless
help screens and cursor positioning code! I just want an EDitor!!
Not a "viitor". Not a "emacsitor". Those aren't even WORDS!!!! ED!
ED! ED IS THE STANDARD!!!
TEXT EDITOR.
When IBM, in its ever-present omnipotence, needed to base their
"edlin" on a UNIX standard, did they mimic vi? No. Emacs? Surely
you jest. They chose the most karmic editor of all. The standard.
Ed is for those who can *remember* what they are working on. If you
are an idiot, you should use Emacs. If you are an Emacs, you should
not be vi. If you use ED, you are on THE PATH TO REDEMPTION. THE
SO-CALLED "VISUAL" EDITORS HAVE BEEN PLACED HERE BY ED TO TEMPT THE
FAITHLESS. DO NOT GIVE IN!!! THE MIGHTY ED HAS SPOKEN!!!
?I don't want to have to think more carefully about things that don't matter like syntax. Highlighting gives you visual clues so you can get meaning from code more quickly and get on with it, instead of having to read everything carefully.
Plus: pretty colors.
I am still not very good at opening multiple buffers, I just close vim and open the other file.
But that is about it. I felt I have doing it wrong. But I can get work done and it is easier everytime I install a new server.
Would save me from buying Sublime
It's 'real' intellisense for Vim/C#. It's fairly new and rough around the edges, but works great once you get it going.
Because then I found out about ctrlp.vim and :E, two things that makes NERDTree completely useless to me.
Maybe someone here could help me out.
Environment:
- Lubuntu 12.10 64,
- LXterminal as well as UXTerm,
- GVim/Vim 7.3.547,
- both passive and active ftp,
- a local ftp server and http://secureftp-test.com/ to test it.
When I try to access a remote ftp directory, I can only open the directory that I typed in a path to. As soon as I navigate through the listed directories and hit enter on any, the screen splits into two horizontal panes and the top pane reads "File not found".
I tried this from Windows 7 Gvim/Vim (don't have the version handy but it was 7.3+) and it worked as expected.
From what I gather it just doesn't seem to look for the right directory after I hit enter in the list I think. Maybe it skips an extra forward slash somewhere or something?
I understand we're not really on the netrw/vim mailing list but any response would be appreciated!
let g:netrw_liststyle = 4Also, there doesn't seem to be a way to tell netrw to create a vertical split rather than a horizontal split, which is inconvenient on modern wide screen monitors.
P
opens the file in the most recent non netrw window. v
opens the file in a vertical split and :Vex
opens netw in a vertical split.https://github.com/mihaifm/vimpanel https://github.com/mihaifm/bufstop
https://github.com/alanhamlett/Alan-vimrc
Some features in my vimrc file:
* Code folding for bracket or indention based languages
* Edit multiple files in tabs using minibufexpl plugin
* Using the Solarized color scheme
* Using Vundle for plugin management (apt-get for Vim plugins)
* Common swp, backup, & view directories (No more ~ files left around)
* Useful defaults (spaces instead of tabs, remove trailing newlines, etc.)
Uh, I use xterm...
It's obsolete, I know, but it's still the fastest.
set undofile " This creates a undo file that persists your undo history when the file gets closed
imap >> <ESC> " Double right arrow to escape from insertion mode. This is faster and more comfortable (at least for me) than to reach for tab key for some people
set clipboard=unnamed " This is bridges between your Vim yanks and your system clipboard
Some people use jj to go to the normal mode. Personally I remapped Caps Lock to Escape in my whole system, so I can go to normal mode easily.
You can yank to the system clipboard by providing appropriate register to yank into. You do that by pressing "* before the yank command (e.g. "*yy to yank the current line).
https://github.com/docwhat/homedir-vim/blob/master/vimrc/.vi...
The important bits are vim's built-in omnicomplete and neocachecompl
Omnicomplete by itself isn't bad. I haven't seen any excellent documentation explaining how it all works, but even without my .vimrc I use C-X-f a lot to complete filenames.
Ciao!
1 class Hello
~
~
~
~
~
--INSERT--
Like that? Of course; heck, even xterm does that fine. If you were referring to something else, I'm not too sure...EDIT:
Never mind, now I know what you're talking about. No, I don't think you can get those in terminal vim, but I'm pretty sure there is a plugin for it.
" Make Y behave like other capitals
nnoremap Y y$
" Reselect visual block after indent/outdent
vnoremap < <gv
vnoremap > >gv
There are a number of vim-setups that are popular. janus (https://github.com/carlhuda/janus), spf13 (https://github.com/spf13/spf13-vim) are pretty popular ones.
>>Last time I tried I couldn't bind F-keys for some reason F keys bind fine for me, using OS X Terminal, and gnome-shell in linux. Are you using an esoteric term?
>> I couldn't get syntastic's error marking column to stay on instead of shifting my text back and forth all the time That is using the SignColumn part of vim. As far as I know, vim doesn't allow you to force the existance of SignColumn. You can open up a bug report at their Google Code repo if you think its worthwhile
>> I couldn't get auto-complete mapped to tab properly Depending on your language, YouCompleteMe (https://github.com/Valloric/YouCompleteMe) is amazing, but if you don't do C based stuff NeoComplCache is great too (http://www.vim.org/scripts/script.php?script_id=2620)
>> the extra functionality of vim ends up being counter-productive when none of it works right To be fair, thats true of any tool.
Try this:
augroup syn_gutter
au BufWinEnter * sign define mysign
au BufWinEnter * exe "sign place 1337 line=1 name=mysign buffer=" . bufnr('%')
augroup END
Bonus fancy character bling:
let g:syntastic_error_symbol='✗'
let g:syntastic_warning_symbol='⚠'