recentpopularlog in

kme : vim   462

« earlier  
editor - Disabling swap files creation in vim - Stack Overflow
Set the following variables in .vimrc or /etc/vimrc to make vim put swap, backup and undo files in a special location instead of the working directory of the file being edited:

<code class="language-viml">set backupdir=~/.vim/backup//
set directory=~/.vim/swap//
set undodir=~/.vim/undo//</code>

Using double trailing slashes in the path tells vim to enable a feature where it avoids name collisions. For example, if you edit a file in one location and another file in another location and both files have the same name, you don't want a name collision to occur in ~/.vim/swap/. If you specify ~/.vim/swap// with two trailing slashes vim will create swap files using the whole path of the files being edited to avoid collisions (slashes in the file's path will be replaced by percent symbol %).

For example, if you edit /path/one/foobar.txt and /path/two/foobar.txt, then you will see two swap files in ~/.vim/swap/ that are named %path%one%foobar.txt and %path%two%foobar.txt, respectively.
vim  swapfile  backupfile  settings  configfile  dammitbrain 
25 days ago by kme
Use Vim Inside A Unix Pipe Like Sed Or AWK
<code class="language-bash">
# source: https://news.ycombinator.com/item?id=11431129
function vimify() {
(vim - -esbnN -c $@ -c 'w!/dev/fd/3|q!' >/dev/null) 3>&1
}</code>
vim  pipe  textprocessing  solution 
5 weeks ago by kme
Use Vim Inside a Unix Pipe Like Sed or AWK | Hacker News
http://blog.robertelder.org/use-vim-inside-a-unix-pipe-like-sed-or-awk/
Good point.This argument that domestication lowers intelligence (among other powerful abilities) and that we are unquestionably domesticating ourselves is pretty damn solid. The only argument against it seems to be "... but my ego!".

Obviously there is some interplay with the fact that we develop new mental models and thinking tools to augment intelligence.

Also immersion as children in highly abstract ways of thinking further augments/multiplies raw intelligence (most convincing explanation to the Flynn effect imo).

I've lost the link, but there was an excellent article I read related to the amazing Otzi discovery (https://en.wikipedia.org/wiki/%C3%96tzi) describing how adults of that era (modern humans, primitive societies) would likely have been terrifying to us now in just how much they outclassed us in raw strength, intelligence and stamina. We would be relying a lot on the benefits of childhood nutrition and education to feel superior. This isn't completely convincing, there are a lot of factors in play, but those levels of brutal competition and danger would have a profound effect, especially epigenetically.
vim  texteditors  anthropology  history  forthecomments 
5 weeks ago by kme
brammool/libvterm: Mirror of http://bazaar.leonerd.org.uk/c/libvterm/
<code>To merge in changes from Github, do this:
- Commit any pending changes.
- Setup the merge tool:
git config merge.tool vimdiff
git config merge.conflictstyle diff3
git config mergetool.prompt false
- Run the merge tool:
git mergetool
This will open a four-way diff between:
LOCAL - your current version
BASE - version as it was at your last sync
REMOTE - version at head on Github
MERGED - best-effort merge of LOCAL and REMOTE
Now find places where automatic merge didn't work, they are marked with
<<<<<<<<, ======= and >>>>>>>
Fix those places in MERGED, remove the markers, and save the file :wqall.</code>
vim  devel  git  vimdiff  merging  merge  mergetool  tipsandtricks 
8 weeks ago by kme
ciaranm/securemodelines: A secure alternative to Vim modelines
This works fine, and it recognizes 'filetype', which is all I really need.
vim  security  plugin  modeline  solution 
8 weeks ago by kme
Move through wrapped lines | Vim Tips Wiki | FANDOM powered by Wikia
I ended up using a combination of this tip and the one from https://vim.fandom.com/wiki/Move_cursor_by_display_lines_when_wrapping
My current settings are:
<code class="language-vim">map <silent> <Up> gk
imap <silent> <Up> <C-o>gk
map <silent> <Down> gj
imap <silent> <Down> <C-o>gj
map <silent> <home> g<home>
imap <silent> <home> <C-o>g<home>
map <silent> <End> g<End>
imap <silent> <End> <C-o>g<End>

setlocal linebreak
setlocal nolist
setlocal display+=lastline</code>
vim  configfile  wrapping  scrolling  cursormotion  annoyance  sortof  solution 
july 2019 by kme
Move cursor by display lines when wrapping | Vim Tips Wiki | FANDOM powered by Wikia
I ended up using a combination of this tip and the one from https://vim.fandom.com/wiki/Move_through_wrapped_lines.
You can add the following to get the `standard keys' to work:
<code class="language-viml">
noremap <silent> k gk
noremap <silent> j gj
noremap <silent> 0 g0
noremap <silent> $ g$</code>

If you copy the code from the tip into your vimrc file, make sure that you delete trailing spaces from each line, AND that you put the new code near the bottom of the vimrc file. If the code is near the top of vimrc, something coming after it might redefine those keys.

Unfortunately, this tip breaks the movement commands in conjunction with other commands. For example, d<Down> will no longer delete two lines but delete from the cursor to the position in the next line.

But you can still use j to move down by a physical line, and dj will do what you want.
You can avoid this by mapping the keys in the operator-pending mode as well:
<code class="language-viml">
onoremap <silent> j gj
onoremap <silent> k gk</code>
vim  keybinding  configfile  scrolling  cursormotion  annoyance  sortof  solution 
july 2019 by kme
Writing Vim Plugins / Steve Losh
Except when it isn't, and then you need to 'call pathogen#helptags()'. Dunno why.
Creating a help document is as easy as creating a doc/yourplugin.txt file in your project. It will be indexed automatically by pathogen#helptags() so your users will have the docs at their fingertips.
vim  plugin  extension  howto 
june 2019 by kme
Search for visually selected text | Vim Tips Wiki | FANDOM powered by Wikia
Create file (for example) ~/.vim/plugin/vsearch.vim (Unix) or $HOME/vimfiles/plugin/vsearch.vim (Windows) with contents:

<code class="language-viml">" Search for selected text.
" http://vim.wikia.com/wiki/VimTip171
let s:save_cpo = &cpo | set cpo&vim
if !exists('g:VeryLiteral')
let g:VeryLiteral = 0
endif
function! s:VSetSearch(cmd)
let old_reg = getreg('"')
let old_regtype = getregtype('"')
normal! gvy
if @@ =~? '^[0-9a-z,_]*$' || @@ =~? '^[0-9a-z ,_]*$' && g:VeryLiteral
let @/ = @@
else
let pat = escape(@@, a:cmd.'\')
if g:VeryLiteral
let pat = substitute(pat, '\n', '\\n', 'g')
else
let pat = substitute(pat, '^\_s\+', '\\s\\+', '')
let pat = substitute(pat, '\_s\+$', '\\s\\*', '')
let pat = substitute(pat, '\_s\+', '\\_s\\+', 'g')
endif
let @/ = '\V'.pat
endif
normal! gV
call setreg('"', old_reg, old_regtype)
endfunction
vnoremap <silent> * :<C-U>call <SID>VSetSearch('/')<CR>/<C-R>/<CR>
vnoremap <silent> # :<C-U>call <SID>VSetSearch('?')<CR>?<C-R>/<CR>
vmap <kMultiply> *
nmap <silent> <Plug>VLToggle :let g:VeryLiteral = !g:VeryLiteral
\\| echo "VeryLiteral " . (g:VeryLiteral ? "On" : "Off")<CR>
if !hasmapto("<Plug>VLToggle")
nmap <unique> <Leader>vl <Plug>VLToggle
endif
let &cpo = s:save_cpo | unlet s:save_cpo</code>
vim  searching  searchandreplace  tipsandtricks  essential  movein  vimscript 
june 2019 by kme
pipe - Piping buffer to external command in Vim - Stack Overflow
You can use :w !cmd to write the current buffer to the stdin of an external command. From :help :w_c:
vim  buffers  pipes  externalcommands  textfilter  textprocessing  dammitbrain  solution 
april 2019 by kme
Vim digraphs cheatsheet | https://devhints.io/
The one-page guide to Vim digraphs: usage, examples, links, snippets, and more.
vim  specialcharacters  digraphs  cheatsheet  quickreference 
march 2019 by kme
Mapping keys in Vim - Tutorial (Part 1) | Vim Tips Wiki | FANDOM powered by Wikia | https://vim.fandom.com/
So put these lines in ~/.vim/after/ftplugin/mediawiki.vim in order for 'j' and 'k' to just "do what I mean" in MediaWiki / Markdown source files.
The following commands map the 'j' key to execute 'gj' and the 'k' key to execute 'gk'. These are useful for moving between long wrapped lines.

<code class="language-viml">:nnoremap k gk
:nnoremap j gj</code>
vim  keymap  remapping  configfile  essential  movein 
march 2019 by kme
Cscope Home Page | http://cscope.sourceforge.net/
Try: 'ag -l --cpp | cscope -i- -b -q' (build cross-ref, inverted index)
devel  c  cplusplus  codesearch  crossreference  commandline  vim  asanide  solution 
february 2019 by kme
vim - How to fix duplicate cscope ? is it a better way? - Stack Overflow | https://stackoverflow.com/
Solution: put 'set cscopenoverbose' right before the 'if filereadable("cscope.out")' statement.
vim  cscope  errormessage  annoyance  solution 
february 2019 by kme
keyboard shortcuts - How to put current line at top/center/bottom of screen in vim? - Unix & Linux Stack Exchange | https://unix.stackexchange.com/
zt puts current line to top of screen
z. or zz puts current line to center of screen
zb puts current line to bottom of screen

More info about scrolling at http://vimdoc.sourceforge.net/htmldoc/scroll.html or in vim type :help scroll-cursor
vim  tipsandtricks  scrolling  cursormotion  solution  dammitbrain 
february 2019 by kme
Vim documentation: eval | http://vimdoc.sourceforge.net/
Expand the value of an environment variable into the current buffer:

<code>Ctrl-R, =, expand($LANG)</code>
vim  syntax  function  registers  reference  environmentvariables  solution 
february 2019 by kme
Vim: enter Unicode characters with 8-digit hex code - Stack Overflow | https://stackoverflow.com/
Things I know:

The command ga on the character 𝓭 gives me hex:0001d4ed.
I can copy it on the clipboard and paste it via "+p.
I know how to enter Unicode values that have a 4 digit hex code:
<C-v>u for example <C-v>u03b1 gives the α character.
vim  unicode  specialcharacters  textediting  solution 
january 2019 by kme
replace - In Vim is there a way to delete without putting text in the register? - Stack Overflow | https://stackoverflow.com/
To delete something without saving it in a register, you can use the "black hole register":
<code class="language-vim">"_d</code>

Of course you could also use any of the other registers that don't hold anything you are interested in.
vim  security  history  solution  registers  copypaste  fuckina 
october 2018 by kme
Alternative way to clear search · Issue #131 · tpope/vim-sensible
I like mapping to <CR> because I can still use <Ctrl>+L for vim-tmux-navigator, but I prefer Tim's way of clearing the search, because you can still use n/N to pick up where you left off, after clearing the highlighting.

<code class="language-vim">
set incsearch
" Use <C-L> to clear the highlighting of :set hlsearch.
if maparg('<C-L>', 'n') ==# ''
nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
endif
</code>
I don't know where I found this but I did quite some research on the topic and it turns out the best way is to do:

<code class="language-vim">
nnoremap <CR> :let @/ = "" <bar> echo "search string cleared whatever" <CR>
</code>

This being if you want the mapping to be on Enter, which I find really useful

I can't back this up with anything except that it works and doesn't break anything else, but I thought it would be useful.
searching  vim  configfile  tipsandtricks  movein  solution 
december 2017 by kme
Suggestion: set synmaxcol to sane levels · Issue #142 · tpope/vim-sensible
Hey, just wanted to suggest setting synmaxcol to a sensible level, it's 3000 by default!, and this makes no sense.

I learned of it while talking on #vim how editing an HTML with minified CSS line completely slowed everything down. As it's not sane to have human content reach this limit, I think bringing this value down to 300 or something is better than having it at 3000.
vim  tipsandtricks  configfile  syntaxhighlighting 
december 2017 by kme
vim - Why some people use 'if has("gui_running")' in a .gvimrc? - Stack Overflow
Note that the 'fuoptions' config setting in the example is Mac OS X only.

Usually what I want is just something like this:

<code class="language-vim">
if has("gui_running")
if has("x11")
set lines=52 guioptions-=T
endif
endif
</code>
vim  configfile  dammitbrain  reference  solution 
november 2017 by kme
Vim documentation: cmdline | http://vimdoc.sourceforge.net/
To use these with 'echo' you need to expand() them (use a single-quoted string). A useful example is ":echo expand('%:p:h:t')".

To use these in insert mode, do something like CTRL-R, =expand('%:p:h:t').
vim  textprocessing  buffers  variables  syntax  tipsandtricks  dammitbrain  reference 
november 2017 by kme
Easier buffer switching | Vim Tips Wiki | FANDOM powered by Wikia | http://vim.wikia.com/
<code class="language-vim">" Mappings to access buffers (don't use "\p" because a
" delay before pressing "p" would accidentally paste).
" \l : list buffers
" \b \f \g : go back/forward/last-used
" \1 \2 \3 : go to buffer 1/2/3 etc
nnoremap <Leader>l :ls<CR>
nnoremap <Leader>b :bp<CR>
nnoremap <Leader>f :bn<CR>
nnoremap <Leader>g :e#<CR>
nnoremap <Leader>1 :1b<CR>
nnoremap <Leader>2 :2b<CR>
nnoremap <Leader>3 :3b<CR>
nnoremap <Leader>4 :4b<CR>
nnoremap <Leader>5 :5b<CR>
nnoremap <Leader>6 :6b<CR>
nnoremap <Leader>7 :7b<CR>
nnoremap <Leader>8 :8b<CR>
nnoremap <Leader>9 :9b<CR>
nnoremap <Leader>0 :10b<CR>
" It's useful to show the buffer number in the status line.
set laststatus=2 statusline=%02n:%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P</code>
vim  buffers  tipsandtricks  configfile 
november 2017 by kme
how to insert filename without the path in vim - Stack Overflow | https://stackoverflow.com/
You can use
<C-r>=expand("%:t")<CR>
See :help filename-modifiers.
Edit
<C-r> is used in insert mode to insert the content of a register. "% is the register that contains the name of the current file.
"= is the expression register, it contains the result of the expression that comes after =:
<C-r>=2+27+6<CR> --> 35
<C-r>=expand("%:t")<CR> --> file.txt
vim  tipsandtricks  buffers  match  variables  evaluation  textediting  solution 
november 2017 by kme
How does the vim "write with sudo" trick work? - Stack Overflow | https://stackoverflow.com/
Many of you have probably seen the command that allows you to write on a file that needs root permission, even when you forgot to open vim with sudo:

:w !sudo tee %

The thing is that I don't get what is exactly happening here.
vim  tipsandtricks  sudo  sysadmin  textediting 
november 2017 by kme
Get the name of the current file | Vim Tips Wiki | FANDOM powered by Wikia | http://vim.wikia.com/
<code class="language-vim">" given: /abc/def/my.txt
:echo expand('%:p:h:t') " ==> def
" First get the full path with :p (/abc/def/my.txt),
" then get the head of that with :h (/abc/def),
" then get the tail of that with :t (def)</code>
vim  dammitbrain  filemanagement  variables  syntax  fuckina  solution 
november 2017 by kme
VIM Quick Reference Card | http://tnerual.eriogerg.free.fr/
This one has a concise summary of search/replace, which is what I needed.
vim  quickref  cheatsheat  reference  solution  fuckina 
november 2017 by kme
Visual selection | Vim Tips Wiki | FANDOM powered by Wikia | http://vim.wikia.com/
Did you just do something on a visual range, and to your horror the visual block vanished?

Just type gv to reselect the last block.
vim  textselection  tipsandtricks  solution 
november 2017 by kme
Syntax Highlighting for Template Toolkit (.tt files) in VIM - Stack Overflow | https://stackoverflow.com/
Probably need https://github.com/vim-perl/vim-perl

<code class="language-vim">
" ~/.vim/ftdetect/tt.vim
autocmd BufNewFile,BufRead *.tt setf tt2
autocmd BufNewFile,BufRead *.html.tt serf tt2html
</code>
vim  perl  webdevel  templatetoolkit  syntax  filetype  configfile  solution 
october 2017 by kme
GitHub - vim-scripts/csv.vim: A Filetype plugin for csv files. | https://github.com/
Check out :ArrangeColumn and :UnArrangeColumn. These allow you to use vertical selections to prepend/append to individual columns. Pretty handy!

vim.org link: http://www.vim.org/scripts/script.php?script_id=2830

<code class="language-vim">
" create this as ~/.vim/filetype.vim
if exists("did_load_csvfiletype")
finish
endif
let did_load_csvfiletype=1

augroup filetypedetect
au! BufRead,BufNewFile *.csv,*.dat,*.tab,*.bed setfiletype csv
augroup END
</code>
Syntax error when opening a CSV file

If you see this error:

<code>CSV Syntax:Invalid column pattern, using default pattern \%([^,]*,\|$\)</code>

This happens usually, when the syntax script is read before the filetype plugin, so the plugin did not have a chance to setup the column delimiter correctly.

The easy way to fix it, is to make sure the :syntax on (:syn-on) statement comes after the :filetype plugin (:filetype-plugin-on) statement in your .vimrc

Alternatively, you can simply call InitCSV and ignore the error.
Autocommand on opening/closing files

Alternatively, you can restrict this setting to files below a certain size. For example, if you only want to enable this feature for files smaller than 1 MB, put this into your .vimrc

let g:csv_autocmd_arrange = 1
let g:csv_autocmd_arrange_size = 1024*1024
vim  script  csv  syntaxhighlighting  programming  plugin  delimitedtext  textprocessing  errormessage  essential  movein  solution 
october 2017 by kme
« earlier      
per page:    204080120160

Copy this bookmark:





to read