Skip to content
plbowers edited this page May 29, 2017 · 3 revisions

For a detailed view of commands available, your best bet is to do a little code-reading in lib/ex.coffee

Without that, here's a quick list of what's available as of 2017-05-29 (version 0.15.0):

:quit :q :quitall :qall :tabedit :tabe :tabnew tabclose: (args) => @quit(args) tabc: => @tabclose() tabnext: -> tabn: => @tabnext() tabprevious: -> tabp: => @tabprevious() tabonly: -> tabo: => @tabonly() edit: ({ range, args, editor }) -> e: (args) => @edit(args) enew: -> write: ({ range, args, editor, saveas }) -> wall: -> w: (args) => wq: (args) => wa: => wqall: => wqa: => xall: => xa: => saveas: (args) => xit: (args) => @wq(args) x: (args) => @xit(args) split: ({ range, args }) -> sp: (args) => @split(args)

substitute: ({ range, args, editor, vimState }) -> args_ = args.trimLeft() delim = args_[0] if /[a-z1-9\"|]/i.test(delim) throw new CommandError( "Regular expressions can't be delimited by alphanumeric characters, '\', '"' or '|'") args_ = args_[1..] escapeChars = {t: '\t', n: '\n', r: '\r'} parsed = ['', '', ''] parsing = 0 escaped = false while (char = args_[0])? args_ = args_[1..] if char is delim if not escaped parsing++ if parsing > 2 throw new CommandError('Trailing characters') else parsed[parsing] = parsed[parsing][...-1] else if char is '\' and not escaped parsed[parsing] += char escaped = true else if parsing == 1 and escaped and escapeChars[char]? parsed[parsing] += escapeChars[char] escaped = false else escaped = false parsed[parsing] += char

[pattern, substition, flags] = parsed
if pattern is ''
  if vimState.getSearchHistoryItem?
    # vim-mode
    pattern = vimState.getSearchHistoryItem()
  else if vimState.searchHistory?
    # vim-mode-plus
    pattern = vimState.searchHistory.get('prev')

  if not pattern?
    atom.beep()
    throw new CommandError('No previous regular expression')
else
  if vimState.pushSearchHistory?
    # vim-mode
    vimState.pushSearchHistory(pattern)
  else if vimState.searchHistory?
    # vim-mode-plus
    vimState.searchHistory.save(pattern)

try
  flagsObj = {}
  flags.split('').forEach((flag) -> flagsObj[flag] = true)
  patternRE = getSearchTerm(pattern, flagsObj)
catch e
  if e.message.indexOf('Invalid flags supplied to RegExp constructor') is 0
    throw new CommandError("Invalid flags: #{e.message[45..]}")
  else if e.message.indexOf('Invalid regular expression: ') is 0
    throw new CommandError("Invalid RegEx: #{e.message[27..]}")
  else
    throw e

editor.transact ->
  for line in [range[0]..range[1]]
    editor.scanInBufferRange(
      patternRE,
      [[line, 0], [line + 1, 0]],
      ({match, replace}) ->
        replace(replaceGroups(match[..], substition))
    )

s: (args) => @substitute(args)

vsplit: ({ range, args }) -> args = args.trim() filePaths = args.split(' ') filePaths = undefined if filePaths.length is 1 and filePaths[0] is '' pane = atom.workspace.getActivePane() if atom.config.get('ex-mode.splitright') if filePaths? and filePaths.length > 0 newPane = pane.splitRight() for file in filePaths do -> atom.workspace.openURIInPane file, newPane else pane.splitRight(copyActiveItem: true) else if filePaths? and filePaths.length > 0 newPane = pane.splitLeft() for file in filePaths do -> atom.workspace.openURIInPane file, newPane else pane.splitLeft(copyActiveItem: true)

vsp: (args) => @vsplit(args)

delete: ({ range }) -> range = range[0], 0], [range[1] + 1, 0 editor = atom.workspace.getActiveTextEditor()

text = editor.getTextInBufferRange(range)
atom.clipboard.write(text)

editor.buffer.setTextInRange(range, '')

yank: ({ range }) -> range = range[0], 0], [range[1] + 1, 0 txt = atom.workspace.getActiveTextEditor().getTextInBufferRange(range) atom.clipboard.write(txt);

set: ({ range, args }) -> args = args.trim() if args == "" throw new CommandError("No option specified") options = args.split(' ') for option in options do -> if option.includes("=") nameValPair = option.split("=") if (nameValPair.length != 2) throw new CommandError("Wrong option format. [name]=[value] format is expected") optionName = nameValPair[0] optionValue = nameValPair[1] optionProcessor = VimOption.singleton()[optionName] if not optionProcessor? throw new CommandError("No such option: #{optionName}") optionProcessor(optionValue) else optionProcessor = VimOption.singleton()[option] if not optionProcessor? throw new CommandError("No such option: #{option}") optionProcessor()

module.exports = Ex

Clone this wiki locally