Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

Friday, November 09, 2012

A poor man's Notational Velocity on Linux

I use Notational Velocity on my Mac all the time. It holds all my notes, lists and any other snippet of text. I love the interface and simplicity, and most of all I love the simple use of text files in Dropbox as a store. This way I can access my notes anywhere, without needing NV to be installed. I also love the global key binding feature so that I can quickly raise it with Cmd+Shift+N.

At work (more on this soon) I started using a Thinkpad x230 running Archlinux. But I sorely missed NV. I experimented with nvpy, but it didn't cut it for me at all. The tkinter UI looks bad in a Qt/GTK desktop, notes are saved in JSON by default, and the text file option is a sort of hack which stores the title in the first line, messing up the notes in NV. So rather than write my own version, I got an almost as nice, and definitely more powerful NV equivalent in Linux.

I am going to assume you use a standard desktop environment like KDE or that your window manager is EWMH compatible. You'll need:

  • To know how to define custom global shortcuts to run a command. For KDE this is System Settings -> Shortcuts and Gestures -> Edit -> New -> Global Shortcut -> Command/URL
  • gvim
  • wmctrl (available in Arch community repo).

Create a new shortcut which should launch the following command string

gvim --remote-silent +':lcd %:p:h | :au FocusLost * :wa' \
'/home/nikhil/Dropbox/Notational Data' && wmctrl -a 'GVIM'

You should edit the path to point to your Dropbox/NV directory. Now whenever you press the global shortcut combination you should see gvim with a list of all files (notes). Press Enter on a file to open it.

We use remote-silent to make sure that gvim uses an existing window if it is already open. The :lcd %:p:h option sets vim's current working directory to the NV directory. This will be useful later. We use the autocommand FocusLost to save the file whenever the gvim window loses focus (simulating NV's autosave feature). Finally wmctrl raises the window to the top by matching the string to the title. If you use gvim on a regular basis (I use terminal vim) and have other windows open, you'll have to tweak this.

So this setup is completely like NV, except for one divergence. Whereas NV searchs the note title and content together, our system will treat it as two flows. To search note titles/file names use / when in the main view. As part of my standard vim plugin set I have ctrlp and ack.vim* which will serve us well here. To always have access to note titles use ctrlp. I map it to sf so that I get quick fuzzy find. Similarly to search note contents I map sd to trigger ack.vim. This is where setting vim's current directory is important. Both plugins will use it as the base search directory.

This NV approximation is fast and works almost as well as the original, although without a slick interface. But nice fonts and a good vim colour scheme come pretty close.


* You'll need ack installed to use ack.vim. ack does not include text files by default. Put --text in ~/.ackrc to do so.

Monday, January 09, 2012

Toggling Proxy settings quickly with Pentadactyl and Firefox

If you use the excellent Pentadactyl plugin for Firefox to get vim super-powers to the browser, here is a quick and painless way to toggle between a direct connection to the internet or using the default proxy settings. Add this to your ~/.pentadactylrc
command proxy -nargs=1 :set! network.proxy.type=<args>
nmap up :proxy 1<CR>
nmap np :proxy 0<CR>
Now pressing up (Use Proxy) will enable Manual Proxy Settings while pressing np (No Proxy) will use Direct Connection. network.proxy.type can take other values which might be suited to your setup. You can change the key bindings too.

Sunday, September 04, 2011

Toolset

Inspired by The Setup and Pratul’s post, here is how I ‘get my work done’.

Hardware

I currently use a four-core i7 15" Macbook Pro with 8GB of RAM and a 500GB HDD. I love it. For backups I have a Western Digital 160GB hard drive. I use cheap Skullcandy earphones when I need them (I usually prefer speakers).

Operating System

I used to be on Arch Linux until I got the MBP. Now I use OS X Snow Leopard. I still run Arch + KDE on a VirtualBox instance to occasionally hack on KDE. With 8GB of RAM, both keep running snappy :)

Running OSX might come as a surprise considering my FOSS roots. But my software stack is such that it makes no difference what UNIX I use really.

Software

Considering I use the computer all day, the number of applications I actually run is tiny.

I use Firefox for browsing. I hide all chrome except the tab bar, and use the excellent Pentadactyl extension to get vim key bindings and other keyboard driven goodness to Firefox.

For viewing PDFs, I use Preview. The rare photo management is done with iPhoto. Music needs are satisfied with Clementine (my iTunes resides in the Trash), while VLC handles video.

I do use the excellent Notational Velocity for note taking and idea jotting and the like. It fast, it stays out of the way and is easy to sync if I have to.

iCal, synced with Google Calendar, is used for todos and submission reminders.

And that is all the GUI apps I usually run. Which is why it doesn’t matter what UNIX I use, since most of my work is in the shell.

Office suite you say? I find Google Docs suffices, to the point that if somebody sends me MS formats, I upload them to Google Docs. The Gmail web interface is also unbeatable so mail stays there.

Accessories include Dropbox, Temperature Monitor Lite, gfxCardStatus to manually control which graphics card is in use, ShiftIt to position windows, afloat to allow ‘Always on Top’ like KWin, Growl for notifications and Tunnelblick for VPN management.

Now we come to the terminal. My terminal emulator is iTerm. I have only one window running maximized, with tmux acting as my ‘window manager’ for shells. It has a slightly customized statusbar, with the solarized colour scheme. The shell is zsh with a custom zshrc based on stuff I pick up around the Internet, with the zsh-git prompt.

This exact same terminal configuration is also available in the Linux VM (including vim configuration) so that I don’t need to switch my behaviour for the different OSes.

For IRC I use irssi although I use it as a total newbie.

And the rest of my day is spent in vim. I do all my long writing in vim — code, articles, blog posts, configuration files — everything. I use the molokai theme rather than solarized for the editor.

Vim plugins

First Tim Pope’s pathogen is indispensible to easily manage other plugins.

a.vim is a convenient little script to toggle between headers and sources.

ack.vim allows the invocation of ack from vim and presents the results in the Quickfix buffer. I map the keystroke ‘sd’ to ack.vim.

fugitive is useful for Git integration with vim, but I don’t use it that much yet except to do blames.

fuzzyfinder is another indispensible script for me. I map ‘sf’ to fuzzyfinder so I can quickly invoke that.

Other plugins I use include nerdcommenter and vim-surround.

My Dream Setup

I would love a standing desk in my hostel room with an external monitor connected to my laptop, the way I worked at Mozilla. I am considering buying a Netgear Ultra 2 NAS to have redundant storage and sharing. Otherwise the MBP works great and is sufficient for now.

Posted via email from nikhil's posterous

Thursday, September 09, 2010

tmux and vim configuration

I’ve now been on tmux for quite a few months since migrating from screen.

aterm + tmux + zsh + vim makes a super command-line combination.

But there can be certain issues with the key bindings with vim. Since moving to tmux I’ve avoided using vim tabs since I couldn’t figure out the right key bindings to switch them using C-PgUp and C-PgDn when in tmux. But today with a little help on #tmux and kerneltrap I finally got things working. So here are my .tmux and .vimrc files for posterity.

# start a new session on tmux att if no existing session is running new  # screen prefix key set -g prefix C-a  # large history set-option -g history-limit 100000  # swap on C-a C-a bind-key C-a last-window bind-key k confirm-before kill-window bind-key r source-file ~/.tmux.conf bind-key v split-window -h #similar to vim's vsplit bind-key h split-window  set-option -g default-terminal "screen-256color"  # status bar customisation set-option -g status-bg default set-option -g status-fg green  # highlight status bar on activity set -g visual-activity on  # change foreground-background for the current window setw -g window-status-current-attr reverse setw -g monitor-activity on  # for vim setw -g xterm-keys on  # load average, battery, and date + time set -g status-right "#[fg=magenta] #(cat /proc/loadavg|awk '{print

$1 \“ \” $2 \“ \” $3}‘) #(acpi|awk ’{print $4;}‘) #[fg=cyan]%d-%m

[fg=green]%H:%M"

# put the programs to start by default here # one $SHELL is always started at 0  # todo/bugtracker http://yokadi.github.com/ neww -n yokadi -t 10 yokadi  # focus on first window select-window -t 0  set status-left-attr reverse

.vimrc

syntax enable filetype on filetype indent on filetype plugin on  " Fast editing of the .vimrc map e :e! ~/.vim_runtime/vimrc  " When vimrc is edited, reload it autocmd! bufwritepost .vimrc source ~/.vimrc  " indent related set backspace=indent,eol,start set smarttab set expandtab set sw=4 set tabstop=4 set softtabstop=4  " other view settings, some redundant set t_Co=256 set number set autoindent set smartindent set showcmd set showmatch set ruler set tw=0 set hlsearch set incsearch set magic  " I don't like swap files set noswapfile :highlight Pmenu ctermbg=238 ctermfg=white gui=bold  " for tmux set mouse=a set ttymouse=xterm  " following taken from http://items.sjbach.com/319/configuring-vim-right set hidden runtime macros/matchit.vim set wildmenu set wildmode=list:longest set title set visualbell  "mappings " fast saves " fast quit " and tag/tree toggling :nmap  :w :nmap  :wall :map  :qall :map  :TlistToggle :map  :NERDTreeToggle :map  :FuzzyFinderFile  :let NERDTreeQuitOnOpen = 1  " ignore case when searching :set ignorecase " but if any character is typed uppercase, respect the case :set smartcase  :set wildignore=*.o,*.pyc set completeopt=menuone,menu,longest,preview  :set scrolloff=8  :set wm=4  " use ack instead of grep for vimgrep :set grepprg=ack  " abbreviations " useful iab xauthor Nikhil Marathe <nsm.nikhil@gmail.com> iab xdate =strftime("%d/%m/%y %H:%M:%S")  let g:GetLatestVimScripts_allowautoinstall=1  " Tell vim to remember certain things when we exit "  '10 : marks will be remembered for up to 10 previously edited files "  "100 : will save up to 100 lines for each register "  :20 : up to 20 lines of command-line history will be remembered "  % : saves and restores the buffer list "  n... : where to save the viminfo files set viminfo='10,\"100,:20,%,n~/.viminfo  " when we reload, tell vim to restore the cursor to the saved position augroup JumpCursorOnEdit au! autocmd BufReadPost * \ if expand(":p:h") !=? $TEMP | \ if line("'\"") > 1 && line("'\"") <= line("$") | \ let JumpCursorOnEdit_foo = line("'\"") | \ let b:doopenfold = 1 | \ if (foldlevel(JumpCursorOnEdit_foo) >

foldlevel(JumpCursorOnEdit_foo – 1)) |

\ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 | \ let b:doopenfold = 2 | \ endif | \ exe JumpCursorOnEdit_foo | \ endif | \ endif " Need to postpone using "zv" until after reading the modelines. autocmd BufWinEnter * \ if exists("b:doopenfold") | \ exe "normal zv" | \ if(b:doopenfold > 1) | \ exe "+".1 | \ endif | \ unlet b:doopenfold | \ endif augroup END  :runtime! ftplugin/man.vim  vnoremap  * :call VisualSearch('f') vnoremap  # :call VisualSearch('b')  " Smart way to move btw. windows map  j map  k map  h map  l  " Allow Ctrl+PgUp/PgDn in tmux set t_kN=[6;*~ set t_kP=[5;*~  " reduce vi compatibility for more usefult stuff set nocp

Posted via email from nikhil's posterous