My Vim setup
[updated: 02.03.14; 11.4.10; 23.2.10; 17.1.10; 29.8.09; 31.8.09]
vimrc
(UNIX/Mac: ~/.vimrc; Windows: $VIM/_vimrc)
" vim:fo-=a set nocompatible "== pathogen call pathogen#runtime_append_all_bundles() filetype plugin indent on set autowriteall " auto save the file on things like :next set switchbuf=usetab,newtab " Make shift-insert work like in Xterm mapmap! if version >= 500 " highlight strings inside C comments let c_comment_strings=1 " Switch on syntax highlighting if it wasn't on yet. if !exists("syntax_on") syntax on endif " Switch on search pattern highlighting. set hlsearch endif set shiftwidth=4 set softtabstop=4 set expandtab set linebreak " dont linebreak inside words set mousehide " hide the mouse when typing text set splitbelow "== search related set ignorecase smartcase set incsearch function! NoHLSearch(pat) call search(a:pat) set nohls set hls endfunction " command -nargs=1 S :call NoHLSearch( ) " F5 - toggle highlight search map :set hls! set hls? " unicode - for hars pasted from web-pages, PDFs etc (see usr_45.txt) set encoding=utf-8 " ** actualyl these sould be defined in vimrc and called in there to set " the default that is set when vim is run. function! NormalWritingModeLinesAndLinespace() set lines=36 set linespace=4 endfunction function! DraftingWritingModeLinesAndLinespace() set lines=21 set linespace=13 endfunction "== syntax/display set columns=75 " set lines=38 " now setting it to less as i've increased linespace " set lines=32 " set linespace=5 call NormalWritingModeLinesAndLinespace() set ch=2 " Make command line two lines high set laststatus=2 " so last remaining window always has a statusline " make closed folds less visually prominent highlight Folded guifg=LightBlue function! MyFoldText() let leadingSpaces = " " return leadingSpaces . "\\" . (v:foldend - v:foldstart) endfunction set foldtext=MyFoldText() " note that the following has a backslash followed by one space set fillchars=fold:\ highlight statusline guibg=LightGray guifg=DarkGray gui=none set statusline= set statusline+=%{getline(search(\"^[:#]\",\ \"bnW\"))} " show curr heading set statusline+=%= " show rest right justified. set statusline+=\ \ %c\,\ %l\ (%L) " col, line (tot lines) highlight CursorLine guibg=#D9D9D9 "colorscheme morning "set background=light " dark " for solarized if has("gui_macvim") colorscheme solarized else colorscheme morning endif set backup " turn on backup set backupdir=/Temp/vimFileBackups " dir for tilde files set dir=/Temp/vimSwapFiles " dir for swap files " mustn't have trailing slash. otherwise subsequent additions wont work set path+=~/Notes set path+=~/PhD set autoindent set browsedir=current " open file browser in current dir set selectmode=key "== snipmate options let g:snips_author = "James Cole" "== taglist options let g:Tlist_Auto_Open=1 set updatetime=100 let Tlist_WinWidth = 40 let tlist_text_settings = 'text;h:headings' nnoremap :TlistToggle " To not display the Vim fold column in the taglist window let g:Tlist_Enable_Fold_Column = 0 " only show contents of the current file in current tab let g:Tlist_Show_One_File = 1 " weird, my computer crashed and after restarting it would no longer " generate the tags. it'd say " Taglist: Failed to generate tags for /my/path/to/file " ctags: illegal option -- -^@usage: ctags [-BFadtuwvx] [-f tagsfile] file ... " Taglist FAQ says this is coz its not using the exuberant ctags file. " if i type ctags in shell it gets exuberant one... " but anyway i recently installed oh-my-zsh, which might be somehow the " problem. setting the following var fixes the prob " This seems to be about this problem (though I didn't it all): " http://vim.1045645.n5.nabble.com/MacVim-and-PATH-td3388705.html let Tlist_Ctags_Cmd = '/usr/local/bin/ctags' " assume it gets a valid filename and path function! GetMarkdownHtmlFilename() let b:htmlFileNameForMarkdownDoc = expand('%:t:r') . ".html" let dialogPrompt = "Name and location for HTML file" let b:htmlFileNameForMarkdownDoc = \ inputdialog( dialogPrompt, expand('%:p:h') . "/" . b:htmlFileNameForMarkdownDoc) let menuTypeAndLoc = "amenu 900.107 " let menuItemName = "&Personal.A&uto\\-generate\\ HTML\\ on\\ save" let menuCall = ": silent call GetMarkdownHtmlFilename() " let menuDef = menuTypeAndLoc . menuItemName . menuCall execute(menuDef) endfunction " let markdownUtilName = "multimarkdown" let markdownUtilName = "peg-markdown" function! SaveFile() w TlistUpdate if exists("b:htmlFileNameForMarkdownDoc") execute("!" . g:markdownUtilName . " % > " . b:htmlFileNameForMarkdownDoc) endif endfunction nnoremap :silent call SaveFile() inoremap :silent call SaveFile() vnoremap : silent call SaveFile() gv "== tabbar options let g:tagbar_expand = 1 let g:tagbar_updateonsave_maxlines = 7000 "== scrolling imap set sidescroll=1 " smooth horizontal scrolling - 1 char at a time set scrolloff=1 "== cut and paste " set clipboard+=unnamed " copy yanks and deletions to system clipboard " send all yanked text to the system clipboard nnoremap y "+y " a 'cut' operator that can be used with text-objects, where cut text " is placed on the system clipboard. nmap \u "+d " F4 - show list of headings in document map :g/^:/ " F6 - change all the non-displayed chars to plain-text equivs " (note how have to escape pipes between commands, and " double escape pipes within replace commands) map :%s//--/ge \| %s/ /.../ge \| %s/\\|/"/ge \| %s/\\|/'/ge " F7 - to condense selected lines " very quick a dirty way to do it, should put all the words in a datastructure " and handle words and their variants ending with s better map :s/\ /\&/ge \| '<,'>s/\ /tt/ge \| '<,'>s/\ /b\/ween/ge \| '<,'>s/\ /w\//ge \| '<,'>s/\ /info/ge \| '<,'>s/\ /compu/ge \| '<,'>s/\ /r/ge \| '<,'>s/\
gvimrc
(UNIX/Mac: ~/.gvimrc; Windows: $VIM/_gvimrc)
" vim:fo-=a if has("win16") || has("win32") || has("win64")|| has("win95") " get normal ALT-SPACE behavior map:simalt ~ set gfn=Lucida_Sans_Typewriter:h18:cANSI elseif has("gui_macvim") set gfn=Menlo:h15 endif set cursorline " highlight line cursor is on set guioptions-=T " no toolbar " must be set in vimrc rather than vimrc - they're values are reset when " gvim starts set vb t_vb= function! SubsituteTildeForHomeDir(path) " " want the trailing slash to avoid case of a file in " parent of homedir starting with homedir's name " e.g. if homedir is /users/James " if there was a file called /users/JamesNotex.txt " let homeDir = expand("~") . "/" let newPath = substitute(a:path, "^" . homeDir, "~/", "") return newPath endfunction " sets window title that shows, in this order, these details: " - for unnamed files " - '[No Name]' " - a '+' if buffer has been modified " - current working directory " - vim server instance name " - for named files " - filename " - a '+' if buffer has been modified " - path " - if we're currently auto-generating HTML for this markup, " indicate name+path of that file " - vim server instance name " in any paths, a tilde is substituted for the home directory " function! JamesTitleString() " get list of nums of the buffers assoc'd w/ each window in curr tab page. let l:bufnrlist = tabpagebuflist() let fileNameAndPath = bufname(l:bufnrlist[tabpagewinnr(tabpagenr()) - 1]) " show only the filename (get rid of all the path details) let fileName = substitute(fileNameAndPath, ".*/", "", "") " 'escape' ampersands, so they 1) aren't hidden " & 2) make character following them underlined let fileName = substitute(fileName, "&", "&&", "g") if fileNameAndPath == "" let title = "[No Name]" else let title = fileName endif " Add '+' if the current buffer in the tab page is modified if getbufvar(l:bufnrlist[tabpagewinnr(tabpagenr()) - 1], "&modified") let title = title . ' +' endif if fileNameAndPath == "" let title = title . " (CWD: " . SubsituteTildeForHomeDir(getcwd()) . ")" endif if fileNameAndPath != "" let title = title . " (" let title = title . SubsituteTildeForHomeDir(expand("%:h")) let title = title . ")" endif " if we're currently auto-generating HTML for this markup, indicate name+path of that file if exists("b:htmlFileNameForMarkdownDoc") let title = title . " [->" . b:htmlFileNameForMarkdownDoc . "]" endif let title = title . " - " . v:servername return title endfunction set title set titlestring=%{JamesTitleString()} " max size of titlestring set titlelen=100 function! JamesTabLabel() let label = '' let bufnrlist = tabpagebuflist(v:lnum) " Add '+' if one of the buffers in the tab page is modified for bufnr in bufnrlist if getbufvar(bufnr, "&modified") let label = '+' break endif endfor " Append the number of windows in the tab page if more than one " let wincount = tabpagewinnr(v:lnum, '$') " if wincount > 1 " let label .= wincount " endif " if label != '' " let label .= ' ' " endif " ^ commented out because it includes taglist window in count " an enhancement would be to filter it out let fileName = bufname(bufnrlist[tabpagewinnr(v:lnum) - 1]) " show only the filename (get rid of all the path details) let fileName = substitute(fileName, ".*/", "", "") " 'escape' ampersands, so they 1) aren't hidden " & 2) make character following them underlined let fileName = substitute(fileName, "&", "&&", "g") " don't show '.txt' extensions let fileName = substitute(fileName, "\\.txt$", "", "") let label = label . fileName return label endfunction set guitablabel=%{JamesTabLabel()} function! OpenMyFiles() " note that for filepaths, must use forwards-slashes let notesDir = "~/Notes" let phdWorkingDir = "~/PhD/working" let dropBoxDir = "~/Dropbox" let fileList = [ \ notesDir . "/2014-plan.txt", \ notesDir . "/2014-days.txt", \ dropBoxDir . "/Apps/PlainText\\ 2/plan.txt", \ notesDir . "/vim.txt", \ notesDir . "/biograph.txt", \ notesDir . "/food&drinks.txt", \ notesDir . "/artsRelated.txt", \ phdWorkingDir . "/phdNotesInclSources.txt", \ notesDir . "/projectsToWorkOn.txt", \ notesDir . "/doAndGet-ideas.txt", \ notesDir . "/media-ideas.txt", \ notesDir . "/presents-ideas.txt" \ ] " \ notesDir . "/compu.txt", " \ notesDir . "/aiya,univData.txt", " \ notesDir . "/thinking&Knowl.txt", " \ notesDir . "/writing.txt", " \ notesDir . "/postQueue.txt", " \ notesDir . "/otherIdeas.txt", " \ notesDir . "/I-F&Games.txt", for fileName in fileList exec "e " . fileName exec "tabe" endfor exec "tabc" exec "tabdo :TlistToggle" " now, put the focus on the days file exec "normal! 2gt" set columns=135 endfunction " dev notes: " originally I didnt have the command there to join the lines, and it " didnt work properly. the reason was that you can't call exec like that " when there are a range of lines specified on the command line, as there " will be because there is a selection - and that sucks. the only " reasonable option would be if i could just put the 's' command there " without putting it as an arg to the exec...which i tried but it didnt " seem to work. if you use the substitute function, it only works on a " per-line basis, which'd be a pain. " could ask vim-use if there's a better way to do this. function! ConvertStringToFileName() normal! gv normal! J exec "s#\\<\\l#\\uge" normal! gv exec "s/ //ge" exec "s/:/-/ge" endfunction " kinda silly way to impl this - I dont know how to define it as a string " and just insert that string. dont know how to encode the linebreaks. but " it works. function! InsertNotesFileFields() let oldFo = &fo set fo-=a normal! O normal! otitle= normal! oauthor= normal! otype= normal! oyear= normal! otopics= normal! oread= normal! o normal! o normal! o---------- normal! o let &fo = oldFo endfunction " requires the input text to be visual selection function! CleanTranslinkResult() let stringsToRemove = "Take Bus\\|\\t\\|(.\\{-})\\|daily timetable\\|trip timetable\\|Departing\\|Arriving\\|Zones travelled in:.*$\\|Fares for this journey.*$\\|Fare included in the next trip.*$" normal! gv exec "'<,'>s/" . stringsToRemove . "//ge" endfunction function! WrapAllLines() let oldTw = &tw let &tw = 9000 normal! gg normal! gqG let &tw = oldTw endfunction function! CloseTlistAndSetColumns() TlistClose set columns=76 endfunction function! GetLevel(theLine) if a:theLine =~ "^:" return 0 else return 1 endif endfunction function! FoldOnColonHeadings() setlocal foldmethod=expr " Make all the text within each section a fold " note that you dont call that func you just spec the func name setlocal setlocal foldexpr=GetLevel(getline(v:lnum)) " set columns=77 " setlocal foldcolumn=2 normal! zR endfunction "== menus function! OpenMyFiles_MenuItem() call OpenMyFiles() amenu disable &Personal.&Open\ Standard\ Files endfunction amenu 900.100 &Personal.&Open\ Standard\ Files : silent call OpenMyFiles_MenuItem() amenu 900.105 &Personal.C&lose\ Tlist\ and\ Set\ Columns : silent call CloseTlistAndSetColumns() amenu 900.107 &Personal.A&uto\-generate\ HTML\ on\ save : silent call GetMarkdownHtmlFilename() amenu 900.109 &Personal.Toggle\ GitGutter : GitGutterToggle amenu 900.110 &Personal.&Format\ XML : silent call FormatXml() amenu 900.120 &Personal.&Convert\ String\ To\ File\ Name : silent call ConvertStringToFileName() amenu 900.140 &Personal.Clean\ &Translink\ Result :silent call CleanTranslinkResult() amenu 900.150 &Personal.&Insert\ Notes\ File\ Fields :silent call InsertNotesFileFields() amenu 900.160 &Personal.&Wrap\ All\ Lines :silent call WrapAllLines() " eventually i want to put ticks next to the selected ones ✓ amenu 900.170 &Personal.W&riting\ Mode.&Normal :silent call NormalWritingModeLinesAndLinespace() amenu 900.180 &Personal.W&riting\ Mode.&Drafting :silent call DraftingWritingModeLinesAndLinespace() colorscheme solarized set background=light " for solarized " its set to dark in vimrc, as light is unreadable in terminal " make the highlighting of search terms less prominent " this is a lighter shade of brown " highlight Search guifg=#cbac4c highlight Search guifg=#dac47f
Autocommand for setting filetype of .txt files
(UNIX/MAC: ~/.vim/bundle/myadditions/ftdetect/txt.vim; Windows: $VIM/vimfiles/bundle/myadditions/ftdetect/txt.vim)
au BufNewFile,BufRead *.txt setf txt
$HOME/ctags.cnf (unix/mac: $HOME/.ctags. ctags website).
--langdef=txt --langmap=txt:.txt --txt-kinds=+h --regex-txt=/^(:.*)$/\1/h,headings/
($HOME is an environment variable ctags uses; that's where it looks for the configuration file - I've set mine to same dir as $VIM)
$VIM/vimfiles/syntax/txt.vim
syntax match lvl1Heading /^:[^:].*$/ syntax match lvl2Heading /^::[^:].*$/ syntax match lvl3Heading /^:::[^:].*$/ syntax match lvl4Heading /^::::[^:].*$/ syntax match lvl5Heading /^:::::.*$/ highlight lvl1Heading guifg=#0000FF highlight lvl2Heading guifg=#0075FF highlight lvl3Heading guifg=#0095FF highlight lvl4Heading guifg=#60B9FF highlight lvl5Heading guifg=#90DCFF syntax match crossedOutLine /^\s*\.x.*$/ highlight crossedOutLine guifg=#AAAAAA
Add-on scripts
- matchit
- three related ones by Tim Pope
- snipMate - TextMate-style snippets for Vim
- though i haven't used this one much yet
- taglist
- for this i've installed ctags, and put it in my PATH environment variable (in my case in c:\programs\ctags58)
- to get it to work properly with tabs (the 'tabs' for selecting different files, not the 'tabs' for indenting) apply the following patch
--- plugin/taglist.vim 2008-08-13 19:04:48 +0000 +++ plugin/taglist.vim 2008-08-27 19:24:49 +0000 @@ -4097,6 +4097,12 @@ " window. Used after entering a tab. If this is not done, then the folds " are not properly created for taglist windows displayed in multiple tabs. function! s:Tlist_Refresh_Folds() + + " Not needed when one file is displayed. + if g:Tlist_Show_One_File + return + endif + let winnum = bufwinnr(g:TagList_title) if winnum == -1 return
- renamer - rename multiple files by editing a text document
- Allows you to use the familiar editing techniques like regexs and using visual-block mode to rename multiple files, and also not have to deal with the escaping you have to do with a shell
- I came across this in a discussion thread about the editor-agnostic massren util, which allows you to do a similar thing. I ended up using renamer as I couldn't get massren running properly on my system.
How I've dealt with Vim's temp files
Details here.
No comments:
Post a Comment